From 493c5210a74cfdefae4099967a39b32a50e8f351 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Fri, 17 Mar 2023 01:52:26 -0400 Subject: [PATCH] DocumentContainer sets minimum size properly --- elements/containers/container.go | 1 + elements/containers/document.go | 37 +++++++++++++------------------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/elements/containers/container.go b/elements/containers/container.go index 2df7bea..7a54be1 100644 --- a/elements/containers/container.go +++ b/elements/containers/container.go @@ -41,6 +41,7 @@ func NewContainer (layout layouts.Layout) (element *Container) { // SetLayout sets the layout of this container. func (element *Container) SetLayout (layout layouts.Layout) { element.layout = layout + element.updateMinimumSize() if element.core.HasImage() { element.redoAll() element.core.DamageAll() diff --git a/elements/containers/document.go b/elements/containers/document.go index b515c1c..08f408b 100644 --- a/elements/containers/document.go +++ b/elements/containers/document.go @@ -52,7 +52,7 @@ func (element *DocumentContainer) Adopt (child elements.Element) { child.SetParent(element) // refresh stale data - element.reflectChildProperties() + element.updateMinimumSize() if element.core.HasImage() && !element.warping { element.redoAll() element.core.DamageAll() @@ -91,7 +91,7 @@ func (element *DocumentContainer) Disown (child elements.Element) { } } - element.reflectChildProperties() + element.updateMinimumSize() if element.core.HasImage() && !element.warping { element.redoAll() element.core.DamageAll() @@ -116,7 +116,7 @@ func (element *DocumentContainer) DisownAll () { } element.children = nil - element.reflectChildProperties() + element.updateMinimumSize() if element.core.HasImage() && !element.warping { element.redoAll() element.core.DamageAll() @@ -282,27 +282,12 @@ func (element *DocumentContainer) ScrollAxes () (horizontal, vertical bool) { return false, true } -func (element *DocumentContainer) reflectChildProperties () { - focusable := false - for _, entry := range element.children { - _, focusable := entry.Element.(elements.Focusable) - if focusable { - focusable = true - break - } - } - if !focusable && element.Focused() { - element.Propagator.HandleUnfocus() - } -} - func (element *DocumentContainer) doLayout () { margin := element.theme.Margin(theme.PatternBackground) padding := element.theme.Padding(theme.PatternBackground) bounds := padding.Apply(element.Bounds()) element.contentBounds = image.Rectangle { } - minimumWidth := 0 dot := bounds.Min.Sub(element.scroll) for index, entry := range element.children { if index > 0 { @@ -310,9 +295,6 @@ func (element *DocumentContainer) doLayout () { } width, height := entry.MinimumSize() - if width > minimumWidth { - minimumWidth = width - } if width < bounds.Dx() { width = bounds.Dx() } @@ -328,7 +310,18 @@ func (element *DocumentContainer) doLayout () { } element.contentBounds = - element.contentBounds.Sub(element.contentBounds.Min) + element.contentBounds.Sub(element.contentBounds.Min) +} + +func (element *DocumentContainer) updateMinimumSize () { + padding := element.theme.Padding(theme.PatternBackground) + minimumWidth := 0 + for _, entry := range element.children { + width, _ := entry.MinimumSize() + if width > minimumWidth { + minimumWidth = width + } + } element.core.SetMinimumSize ( minimumWidth + padding.Horizontal(), padding.Vertical())