Skip to content

Widget not rendered on window scoll #47

Closed

Description

@t-geindre

While scrolling on a window, widgets may disappear too early.

A simple example with a colored rectangle:

package main

import (
	"image"
	"image/color"

	"github.com/ebitengine/debugui"
	"github.com/hajimehoshi/ebiten/v2"
	"github.com/hajimehoshi/ebiten/v2/vector"
)

type Game struct {
	ui debugui.DebugUI
}

func (g *Game) Update() error {
	_, err := g.ui.Update(func(ctx *debugui.Context) error {
		ctx.Window("test", image.Rect(0, 0, 300, 300), func(layout debugui.ContainerLayout) {
			ctx.Text("test")
			ctx.SetGridLayout(nil, []int{150})
			ctx.Loop(5, func(i int) {
				ctx.GridCell(func(bounds image.Rectangle) {
					ctx.DrawOnlyWidget(func(screen *ebiten.Image) {
						col := color.RGBA{R: 255}
						vector.FillRect(screen, float32(bounds.Min.X), float32(bounds.Min.Y), float32(bounds.Dx()), float32(bounds.Dy()), col, true)
					})
				})
			})
		})
		return nil
	})

	return err
}

func (g *Game) Draw(screen *ebiten.Image) {
	g.ui.Draw(screen)
}

func (g *Game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) {
	return outsideWidth, outsideHeight
}

func main() {
	err := ebiten.RunGame(&Game{})
	if err != nil {
		panic(err)
	}
}

Image

Activity

  1. Vmarcelo49 commented on Dec 29, 2025

    @Vmarcelo49
    Contributor

    The issue is that when DrawOnlyWidget is used inside GridCell, it creates a nested widget that uses the default 18px height instead of the GridCell's 150px height. During scrolling, only the first 18px are "rendered", causing the widget to disappear prematurely as soon as those pixels scroll out of view.

  2. Vmarcelo49 commented on Dec 29, 2025

    @Vmarcelo49
    Contributor

    I am trying to find a fix for this that does not change either functions signatures.

  3. t-geindre commented on Dec 30, 2025

    @t-geindre
    Author

    I ran the same code with your pullrequest and it fixes the issue 👍
    Just to be sure, as far as I understand the API, there is no other way to get the available rect when drawing a widget than putting it in a grid cell to get an image.Rect?

  4. hajimehoshi commented on Sep 26, 2026

    @hajimehoshi
    Member

    Sorry for my terribly late reply. I'll take a look

  5. added a commit that references this issue on Sep 26, 2026
    01cb4a4
  6. added this to the v0.3.1 milestone on Sep 26, 2026
  7. hajimehoshi commented on Sep 26, 2026

    @hajimehoshi
    Member

    Confirmed. I'll review the PR

  8. added 3 commits that reference this issue on Sep 26, 2026
    9b81555
    7059efa
    9b34d36
  9. added a commit that references this issue on Sep 26, 2026
    a40c4af
  10. hajimehoshi commented on Sep 26, 2026

    @hajimehoshi
    Member

    Use a40c4af6cbb46b4a5df6d1070c2d7fcf6ebaff9a until I release v0.3.1 a few days later. Thanks,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions