diff --git a/internal/system/box.go b/internal/system/box.go index d34b46e..10d3cfe 100644 --- a/internal/system/box.go +++ b/internal/system/box.go @@ -128,6 +128,15 @@ func (this *box) borderSum () tomo.Inset { return sum } +func (this *box) borderAndPaddingSum () tomo.Inset { + sum := this.borderSum() + sum[0] += this.padding[0] + sum[1] += this.padding[1] + sum[2] += this.padding[2] + sum[3] += this.padding[3] + return sum +} + func (this *box) SetBounds (bounds image.Rectangle) { if this.bounds == bounds { return } this.bounds = bounds diff --git a/internal/system/containerbox.go b/internal/system/containerbox.go index 836ee89..51c4eb1 100644 --- a/internal/system/containerbox.go +++ b/internal/system/containerbox.go @@ -73,6 +73,24 @@ func (this *containerBox) ScrollTo (point image.Point) { this.invalidateLayout() } +func (this *containerBox) RecommendedHeight (width int) int { + if this.layout == nil { + return this.MinimumSize().Y + } else { + return this.layout.RecommendedHeight(this.layoutHints(), this.children, width) + + this.borderAndPaddingSum().Vertical() + } +} + +func (this *containerBox) RecommendedWidth (height int) int { + if this.layout == nil { + return this.MinimumSize().X + } else { + return this.layout.RecommendedWidth(this.layoutHints(), this.children, height) + + this.borderAndPaddingSum().Horizontal() + } +} + func (this *containerBox) OnContentBoundsChange (callback func()) event.Cookie { return this.on.contentBoundsChange.Connect(callback) } diff --git a/internal/system/textbox.go b/internal/system/textbox.go index 9d64052..ffbadca 100644 --- a/internal/system/textbox.go +++ b/internal/system/textbox.go @@ -65,6 +65,15 @@ func (this *textBox) ScrollTo (point image.Point) { this.invalidateLayout() } +func (this *textBox) RecommendedHeight (width int) int { + return this.drawer.ReccomendedHeightFor(width) + this.borderAndPaddingSum().Vertical() +} + +func (this *textBox) RecommendedWidth (height int) int { + // TODO maybe not the best idea? + return this.MinimumSize().X +} + func (this *textBox) OnContentBoundsChange (callback func()) event.Cookie { return this.on.contentBoundsChange.Connect(callback) }