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.
|
// SetLayout sets the layout of this container.
|
||||||
func (element *Container) SetLayout (layout layouts.Layout) {
|
func (element *Container) SetLayout (layout layouts.Layout) {
|
||||||
element.layout = layout
|
element.layout = layout
|
||||||
|
element.updateMinimumSize()
|
||||||
if element.core.HasImage() {
|
if element.core.HasImage() {
|
||||||
element.redoAll()
|
element.redoAll()
|
||||||
element.core.DamageAll()
|
element.core.DamageAll()
|
||||||
|
@ -52,7 +52,7 @@ func (element *DocumentContainer) Adopt (child elements.Element) {
|
|||||||
child.SetParent(element)
|
child.SetParent(element)
|
||||||
|
|
||||||
// refresh stale data
|
// refresh stale data
|
||||||
element.reflectChildProperties()
|
element.updateMinimumSize()
|
||||||
if element.core.HasImage() && !element.warping {
|
if element.core.HasImage() && !element.warping {
|
||||||
element.redoAll()
|
element.redoAll()
|
||||||
element.core.DamageAll()
|
element.core.DamageAll()
|
||||||
@ -91,7 +91,7 @@ func (element *DocumentContainer) Disown (child elements.Element) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
element.reflectChildProperties()
|
element.updateMinimumSize()
|
||||||
if element.core.HasImage() && !element.warping {
|
if element.core.HasImage() && !element.warping {
|
||||||
element.redoAll()
|
element.redoAll()
|
||||||
element.core.DamageAll()
|
element.core.DamageAll()
|
||||||
@ -116,7 +116,7 @@ func (element *DocumentContainer) DisownAll () {
|
|||||||
}
|
}
|
||||||
element.children = nil
|
element.children = nil
|
||||||
|
|
||||||
element.reflectChildProperties()
|
element.updateMinimumSize()
|
||||||
if element.core.HasImage() && !element.warping {
|
if element.core.HasImage() && !element.warping {
|
||||||
element.redoAll()
|
element.redoAll()
|
||||||
element.core.DamageAll()
|
element.core.DamageAll()
|
||||||
@ -282,27 +282,12 @@ func (element *DocumentContainer) ScrollAxes () (horizontal, vertical bool) {
|
|||||||
return false, true
|
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 () {
|
func (element *DocumentContainer) doLayout () {
|
||||||
margin := element.theme.Margin(theme.PatternBackground)
|
margin := element.theme.Margin(theme.PatternBackground)
|
||||||
padding := element.theme.Padding(theme.PatternBackground)
|
padding := element.theme.Padding(theme.PatternBackground)
|
||||||
bounds := padding.Apply(element.Bounds())
|
bounds := padding.Apply(element.Bounds())
|
||||||
element.contentBounds = image.Rectangle { }
|
element.contentBounds = image.Rectangle { }
|
||||||
|
|
||||||
minimumWidth := 0
|
|
||||||
dot := bounds.Min.Sub(element.scroll)
|
dot := bounds.Min.Sub(element.scroll)
|
||||||
for index, entry := range element.children {
|
for index, entry := range element.children {
|
||||||
if index > 0 {
|
if index > 0 {
|
||||||
@ -310,9 +295,6 @@ func (element *DocumentContainer) doLayout () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
width, height := entry.MinimumSize()
|
width, height := entry.MinimumSize()
|
||||||
if width > minimumWidth {
|
|
||||||
minimumWidth = width
|
|
||||||
}
|
|
||||||
if width < bounds.Dx() {
|
if width < bounds.Dx() {
|
||||||
width = bounds.Dx()
|
width = bounds.Dx()
|
||||||
}
|
}
|
||||||
@ -329,6 +311,17 @@ func (element *DocumentContainer) doLayout () {
|
|||||||
|
|
||||||
element.contentBounds =
|
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 (
|
element.core.SetMinimumSize (
|
||||||
minimumWidth + padding.Horizontal(),
|
minimumWidth + padding.Horizontal(),
|
||||||
padding.Vertical())
|
padding.Vertical())
|
||||||
|
Reference in New Issue
Block a user