From 7809aac72f5611c70ea3736dbf1a09c6c8ae3f39 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 25 Jul 2024 21:05:03 -0400 Subject: [PATCH] Actually use layouts --- internal/system/containerbox.go | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/internal/system/containerbox.go b/internal/system/containerbox.go index aa84b44..304192c 100644 --- a/internal/system/containerbox.go +++ b/internal/system/containerbox.go @@ -20,7 +20,6 @@ type containerBox struct { attrLayout attrHierarchy[tomo.AttrLayout] children []anyBox - layout tomo.Layout on struct { contentBoundsChange event.FuncBroadcaster @@ -187,19 +186,21 @@ func (this *containerBox) setAttr (attr tomo.Attr, user bool) { } func (this *containerBox) recommendedHeight (width int) int { - if this.layout == nil || this.attrOverflow.Value().Y { + layout := this.attrLayout.Value().Layout + if layout == nil || this.attrOverflow.Value().Y { return this.minSize.Value().Y } else { - return this.layout.RecommendedHeight(this.layoutHints(), this.boxQuerier(), width) + + return layout.RecommendedHeight(this.layoutHints(), this.boxQuerier(), width) + this.borderAndPaddingSum().Vertical() } } func (this *containerBox) recommendedWidth (height int) int { - if this.layout == nil || this.attrOverflow.Value().X { + layout := this.attrLayout.Value().Layout + if layout == nil || this.attrOverflow.Value().X { return this.minSize.Value().X } else { - return this.layout.RecommendedWidth(this.layoutHints(), this.boxQuerier(), height) + + return layout.RecommendedWidth(this.layoutHints(), this.boxQuerier(), height) + this.borderAndPaddingSum().Horizontal() } } @@ -274,8 +275,9 @@ func (this *containerBox) layoutHints () tomo.LayoutHints { func (this *containerBox) contentMinimum () image.Point { overflow := this.attrOverflow.Value() minimum := this.box.contentMinimum() - if this.layout != nil { - layoutMinimum := this.layout.MinimumSize ( + layout := this.attrLayout.Value().Layout + if layout != nil { + layoutMinimum := layout.MinimumSize ( this.layoutHints(), this.boxQuerier()) if overflow.X { layoutMinimum.X = 0 } @@ -288,12 +290,13 @@ func (this *containerBox) contentMinimum () image.Point { func (this *containerBox) doLayout () { this.box.doLayout() previousContentBounds := this.contentBounds + layout := this.attrLayout.Value().Layout // by default, use innerBounds (translated to 0, 0) for contentBounds. // if a direction overflows, use the layout's minimum size for it. var minimum image.Point - if this.layout != nil { - minimum = this.layout.MinimumSize ( + if layout != nil { + minimum = layout.MinimumSize ( this.layoutHints(), this.boxQuerier()) } @@ -304,10 +307,10 @@ func (this *containerBox) doLayout () { if overflow.Y { this.contentBounds.Max.Y = this.contentBounds.Min.Y + minimum.Y } // arrange children - if this.layout != nil { + if layout != nil { layoutHints := this.layoutHints() layoutHints.Bounds = this.contentBounds - this.layout.Arrange(layoutHints, this.boxArranger()) + layout.Arrange(layoutHints, this.boxArranger()) } // build an accurate contentBounds by unioning the bounds of all child @@ -323,7 +326,7 @@ func (this *containerBox) doLayout () { // offset children and contentBounds by scroll for _, box := range this.children { - assertAnyBox(box).setBounds(box.Bounds().Add(this.scroll).Add(innerBounds.Min)) + box.setBounds(box.Bounds().Add(this.scroll).Add(innerBounds.Min)) } this.contentBounds = this.contentBounds.Add(this.scroll)