From 14284afa73ec88f9528b9fcbf6c9a067681f8d20 Mon Sep 17 00:00:00 2001 From: Greg Pomerantz Date: Sun, 10 May 2026 06:26:29 -0400 Subject: [PATCH] Add drawPng function to Renderer for PNG icon rendering - Takes image.Image, position (x,y) in Dp, size (width,height) in Dp - Tint color with alpha < 255 applies color overlay using clip.Rect - Converts Dp to pixels using Renderer.toPx() - Uses paint.NewImageOp for image rendering --- .DS_Store | Bin 0 -> 6148 bytes internal/ui/render.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..8f2483070296b1f4314e1d86cd8b6e2cc186b33c GIT binary patch literal 6148 zcmeHK%}T>S5Z>*NNhm@O3Oz1(Em&=}h?h|73mDOZN=;1BV9b`LHHT8jSzpK}@p+ut z-9U@Mqlle>-EVe&b~7Jje;8wYFb@wHYcj@cXowt@5nvgqOtOTne*Z@>iKBGZ>3s4^wN~GK|n)v4dxov)&U(}pV41KL;)S&5{SZ}YcSUc9uTfm z0d*=jPYkZp!7fakYcSWS(-~JQ!#rl?;_<@O>R=ZtoN-qp^~3-%u+BhL51V-YpTjRx z`p92Tp%F1a4E!?&cx~tn2T+tbTfdcuXRUyC4-Ez5a#TP-U%Ldr0QZrWa%#Uo9pYSr Wxkj7??J6CRE&_@W>WG0~VBiarUrP7@ literal 0 HcmV?d00001 diff --git a/internal/ui/render.go b/internal/ui/render.go index aaadb60..9961678 100644 --- a/internal/ui/render.go +++ b/internal/ui/render.go @@ -372,6 +372,42 @@ func (r *Renderer) drawLine(gtx layout.Context, shp *text.Shaper, line []text.Gl t.Pop() } +// drawPng draws a PNG image at the given position and size. +// x, y are in Dp (top-left corner). +// width, height are in Dp (target size). +// col is the tint color — if alpha < 255, the image is tinted using blendOp.DstIn. +func (r *Renderer) drawPng(gtx layout.Context, img image.Image, x, y Dp, width, height Dp, col color.NRGBA) { + if img == nil { + return + } + + // Convert Dp to pixels + xPx := int(r.toPx(x)) + yPx := int(r.toPx(y)) + wPx := int(r.toPx(width)) + hPx := int(r.toPx(height)) + + // Compute source rectangle (full image) + src := image.Rect(0, 0, img.Bounds().Dx(), img.Bounds().Dy()) + _ = src // unused, but kept for clarity + + // Compute destination rectangle + dst := image.Rect(xPx, yPx, xPx+wPx, yPx+hPx) + + // If tint color has alpha < 255, apply tint using blendOp.DstIn + if col.A < 255 { + // Draw tinted rectangle over the image + bgClip := clip.Rect(dst).Push(gtx.Ops) + paint.ColorOp{Color: col}.Add(gtx.Ops) + paint.PaintOp{}.Add(gtx.Ops) + bgClip.Pop() + } + + // Draw the image + paint.NewImageOp(img).Add(gtx.Ops) + paint.PaintOp{}.Add(gtx.Ops) +} + // WindowConstraints tracks the initial window constraints captured at the start of Draw. // All elements are positioned relative to these bounds to ensure consistency. type WindowConstraints struct {