Skip to content

Commit a40c4af

Browse files
Vmarcelo49hajimehoshi
authored andcommitted
debugui: draw DrawOnlyWidget without culling by its layout item (#48)
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. Closes #47
1 parent 9b22e7e commit a40c4af

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

‎draw.go‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (c *Context) draw(screen *ebiten.Image) {
106106
for cmd := range c.commands() {
107107
switch cmd.typ {
108108
case commandRect:
109-
vector.DrawFilledRect(
109+
vector.FillRect(
110110
target,
111111
float32(cmd.rect.rect.Min.X*scale),
112112
float32(cmd.rect.rect.Min.Y*scale),
@@ -205,12 +205,19 @@ func (c *Context) drawIcon(icon icon, rect image.Rectangle, color color.Color) {
205205
// DrawOnlyWidget adds a widget that only draws the given function without user interaction.
206206
func (c *Context) DrawOnlyWidget(f func(screen *ebiten.Image)) {
207207
_ = c.wrapEventHandlerAndError(func() (EventHandler, error) {
208-
_, _ = c.widget(widgetID{}, 0, nil, nil, func(bounds image.Rectangle) {
209-
c.setClip(c.clipRect())
210-
defer c.setClip(unclippedRect)
211-
cmd := c.appendCommand(commandDraw)
212-
cmd.draw.f = f
213-
})
208+
// The layout item is allocated as usual, so that the layout does not depend
209+
// on whether the drawing is visible. The item's bounds must not be used to
210+
// cull the drawing though: f can draw outside them, and the clip rect
211+
// already limits the output to the visible area.
212+
if _, err := c.layoutNext(); err != nil {
213+
return nil, err
214+
}
215+
216+
c.setClip(c.clipRect())
217+
defer c.setClip(unclippedRect)
218+
219+
cmd := c.appendCommand(commandDraw)
220+
cmd.draw.f = f
214221
return nil, nil
215222
})
216223
}

0 commit comments

Comments
 (0)