diff --git a/box.go b/box.go index 772a9ea..c526c07 100644 --- a/box.go +++ b/box.go @@ -82,6 +82,13 @@ func (b *Box) SetVisible(visible bool) { b.visible = visible } +// Clip returns whether the widget and its children are restricted to drawing +// within the widget's rect area of the screen. For best performance, Clip +// should return false unless clipping is actually needed. +func (b *Box) Clip() bool { + return false +} + // Cursor returns the cursor shape shown when a mouse cursor hovers over the // widget, or -1 to let widgets beneath determine the cursor shape. func (b *Box) Cursor() ebiten.CursorShapeType { diff --git a/game.go b/game.go index ba65ca3..e979d3e 100644 --- a/game.go +++ b/game.go @@ -429,11 +429,18 @@ func draw(w Widget, screen *ebiten.Image) error { } r := w.Rect() - subScreen := screen.SubImage(r).(*ebiten.Image) + subScreen := screen + if w.Clip() { + subScreen = screen.SubImage(r).(*ebiten.Image) + } background := w.Background() if background.A > 0 { - subScreen.Fill(background) + if subScreen == screen { + screen.SubImage(r).(*ebiten.Image).Fill(background) + } else { + subScreen.Fill(background) + } } err := w.Draw(subScreen) diff --git a/list.go b/list.go index 331ae36..24d767f 100644 --- a/list.go +++ b/list.go @@ -161,6 +161,13 @@ func (l *List) SetVisible(visible bool) { l.grid.SetVisible(visible) } +// Clip returns whether the widget and its children are restricted to drawing +// within the widget's rect area of the screen. For best performance, Clip +// should return false unless clipping is actually needed. +func (l *List) Clip() bool { + return true +} + // SetColumnSizes sets the size of each column. A size of -1 represents an equal // proportion of the available space. func (l *List) SetColumnSizes(size ...int) { diff --git a/select.go b/select.go index aebb316..68c03ed 100644 --- a/select.go +++ b/select.go @@ -58,6 +58,13 @@ func (s *Select) SetRect(r image.Rectangle) { s.list.SetRect(listRect) } +// Clip returns whether the widget and its children are restricted to drawing +// within the widget's rect area of the screen. For best performance, Clip +// should return false unless clipping is actually needed. +func (s *Select) Clip() bool { + return false +} + // SetHighlightColor sets the color used to highlight the currently selected item. func (s *Select) SetHighlightColor(c color.RGBA) { s.list.SetHighlightColor(c) diff --git a/widget.go b/widget.go index e1b1089..a195d71 100644 --- a/widget.go +++ b/widget.go @@ -34,6 +34,11 @@ type Widget interface { // SetVisible sets the visibility of the widget. SetVisible(visible bool) + // Clip returns whether the widget and its children are restricted to drawing + // within the widget's rect area of the screen. For best performance, Clip + // should return false unless clipping is actually needed. + Clip() bool + // Cursor returns the cursor shape shown when a mouse cursor hovers over // the widget, or -1 to let widgets beneath determine the cursor shape. Cursor() ebiten.CursorShapeType diff --git a/window.go b/window.go index 899402f..e72da90 100644 --- a/window.go +++ b/window.go @@ -55,6 +55,13 @@ func (w *Window) SetRect(r image.Rectangle) { w.modified = true } +// Clip returns whether the widget and its children are restricted to drawing +// within the widget's rect area of the screen. For best performance, Clip +// should return false unless clipping is actually needed. +func (w *Window) Clip() bool { + return false +} + // SetFont sets the font and text size of the window titles. Scaling is not applied. func (w *Window) SetFont(fnt *text.GoTextFaceSource, size int) { w.Lock()