diff --git a/backends/x/entity.go b/backends/x/entity.go index 6fde145..bcd5ee1 100644 --- a/backends/x/entity.go +++ b/backends/x/entity.go @@ -52,6 +52,7 @@ func (ent *entity) unlink () { func (entity *entity) link (parent *entity) { entity.parent = parent + entity.clip(parent.clippedBounds) if parent.window != nil { entity.setWindow(parent.window) } @@ -110,6 +111,13 @@ func (entity *entity) forMouseTargetContainers (callback func (tomo.MouseTargetC entity.parent.forMouseTargetContainers(callback) } +func (entity *entity) clip (bounds image.Rectangle) { + entity.clippedBounds = entity.bounds.Intersect(bounds) + for _, child := range entity.children { + child.clip(entity.clippedBounds) + } +} + // ----------- Entity ----------- // func (entity *entity) Invalidate () { @@ -204,7 +212,7 @@ func (entity *entity) CountChildren () int { func (entity *entity) PlaceChild (index int, bounds image.Rectangle) { child := entity.children[index] child.bounds = bounds - child.clippedBounds = entity.bounds.Intersect(bounds) + child.clip(entity.clippedBounds) child.Invalidate() child.InvalidateLayout() } diff --git a/backends/x/system.go b/backends/x/system.go index 540b4e8..ac2b5a7 100644 --- a/backends/x/system.go +++ b/backends/x/system.go @@ -170,6 +170,7 @@ func (system *system) draw () { defer func () { system.invalidateIgnore = false } () for entity := range system.drawingInvalid { + if entity.clippedBounds.Empty() { continue } entity.element.Draw (canvas.Cut ( system.canvas, entity.clippedBounds))