diff --git a/internal/system/hierarchy.go b/internal/system/hierarchy.go index 26d30a0..2224ce4 100644 --- a/internal/system/hierarchy.go +++ b/internal/system/hierarchy.go @@ -86,6 +86,47 @@ func (this *Hierarchy) MinimumSize () image.Point { return this.minimumSize } +// AfterEvent should be called at the end of every event cycle. +func (this *Hierarchy) AfterEvent () { + if this.canvas == nil { return } + + if this.needRedo { + // set child bounds + childBounds := this.canvas.Bounds() + childBounds = childBounds.Sub(childBounds.Min) + if this.root != nil { + this.root.SetBounds(childBounds) + } + + // full relayout/redraw + if this.root != nil { + this.root.recursiveRedo() + } + this.link.PushAll() + this.needRedo = false + return + } + + for len(this.needMinimum) > 0 { + this.needMinimum.Pop().doMinimumSize() + } + if !this.minimumClean { + this.doMinimumSize() + } + for len(this.needLayout) > 0 { + this.needLayout.Pop().doLayout() + } + var toPush image.Rectangle + for len(this.needDraw) > 0 { + box := this.needDraw.Pop() + box.doDraw() + toPush = toPush.Union(box.Bounds()) + } + if !toPush.Empty() { + this.link.PushRegion(toPush) + } +} + func (this *Hierarchy) getHierarchy () *Hierarchy { return this } @@ -231,46 +272,6 @@ func (this *Hierarchy) propagateAlt (callback func (box anyBox) bool) { this.root.propagateAlt(callback) } -func (this *Hierarchy) afterEvent () { - if this.canvas == nil { return } - - if this.needRedo { - // set child bounds - childBounds := this.canvas.Bounds() - childBounds = childBounds.Sub(childBounds.Min) - if this.root != nil { - this.root.SetBounds(childBounds) - } - - // full relayout/redraw - if this.root != nil { - this.root.recursiveRedo() - } - this.link.PushAll() - this.needRedo = false - return - } - - for len(this.needMinimum) > 0 { - this.needMinimum.Pop().doMinimumSize() - } - if !this.minimumClean { - this.doMinimumSize() - } - for len(this.needLayout) > 0 { - this.needLayout.Pop().doLayout() - } - var toPush image.Rectangle - for len(this.needDraw) > 0 { - box := this.needDraw.Pop() - box.doDraw() - toPush = toPush.Union(box.Bounds()) - } - if !toPush.Empty() { - this.link.PushRegion(toPush) - } -} - func (this *Hierarchy) drawBackgroundPart (canvas.Canvas) { // TODO // no-op for now? maybe eventually windows will be able to have a