DocumentContainer sets minimum size properly
This commit is contained in:
parent
0fd56f272c
commit
493c5210a7
@ -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()
|
||||
|
@ -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()
|
||||
}
|
||||
@ -329,6 +311,17 @@ func (element *DocumentContainer) doLayout () {
|
||||
|
||||
element.contentBounds =
|
||||
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())
|
||||
|
Reference in New Issue
Block a user