From 9b34d36fb857f04b62c354333cc324d497a452d7 Mon Sep 17 00:00:00 2001 From: vmarcelo49 Date: Sat, 26 Sep 2026 15:37:23 -0300 Subject: [PATCH] debugui: draw DrawOnlyWidget without culling by its layout item DrawOnlyWidget created a nested widget, and that widget was culled when the bounds of its layout item did not overlap the container body. The callback can draw outside those bounds, so they cannot tell whether the output is visible: in a grid cell the item has the default height at the top of the cell, and the drawing disappeared once that item scrolled out while the cell was still visible. Allocate the layout item as before, so that the layout does not depend on whether the drawing is visible, and add the draw command without the visibility check. The clip rect already limits the output to the visible area. Also replace the deprecated vector.DrawFilledRect with vector.FillRect. Fixes #47 --- draw.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/draw.go b/draw.go index 3c0383f..3032156 100644 --- a/draw.go +++ b/draw.go @@ -106,7 +106,7 @@ func (c *Context) draw(screen *ebiten.Image) { for cmd := range c.commands() { switch cmd.typ { case commandRect: - vector.DrawFilledRect( + vector.FillRect( target, float32(cmd.rect.rect.Min.X*scale), float32(cmd.rect.rect.Min.Y*scale), @@ -205,12 +205,19 @@ func (c *Context) drawIcon(icon icon, rect image.Rectangle, color color.Color) { // DrawOnlyWidget adds a widget that only draws the given function without user interaction. func (c *Context) DrawOnlyWidget(f func(screen *ebiten.Image)) { _ = c.wrapEventHandlerAndError(func() (EventHandler, error) { - _, _ = c.widget(widgetID{}, 0, nil, nil, func(bounds image.Rectangle) { - c.setClip(c.clipRect()) - defer c.setClip(unclippedRect) - cmd := c.appendCommand(commandDraw) - cmd.draw.f = f - }) + // The layout item is allocated as usual, so that the layout does not depend + // on whether the drawing is visible. The item's bounds must not be used to + // cull the drawing though: f can draw outside them, and the clip rect + // already limits the output to the visible area. + if _, err := c.layoutNext(); err != nil { + return nil, err + } + + c.setClip(c.clipRect()) + defer c.setClip(unclippedRect) + + cmd := c.appendCommand(commandDraw) + cmd.draw.f = f return nil, nil }) }