Add support for scrolling flow layouts to ContainerBox impl
This commit is contained in:
parent
a64c27953a
commit
cd72ae5bdd
@ -227,12 +227,6 @@ func (this *containerBox) notifyMinimumSizeChange (child anyBox) {
|
||||
}
|
||||
}
|
||||
|
||||
func (this *containerBox) boundedLayoutHints () tomo.LayoutHints {
|
||||
hints := this.layoutHints()
|
||||
hints.Bounds = this.ContentBounds().Add(this.InnerBounds().Min)
|
||||
return hints
|
||||
}
|
||||
|
||||
func (this *containerBox) layoutHints () tomo.LayoutHints {
|
||||
return tomo.LayoutHints {
|
||||
OverflowX: this.hOverflow,
|
||||
@ -247,7 +241,7 @@ func (this *containerBox) contentMinimum () image.Point {
|
||||
minimum := this.box.contentMinimum()
|
||||
if this.layout != nil {
|
||||
layoutMinimum := this.layout.MinimumSize (
|
||||
this.boundedLayoutHints(),
|
||||
this.layoutHints(),
|
||||
this.children)
|
||||
if this.hOverflow { layoutMinimum.X = 0 }
|
||||
if this.vOverflow { layoutMinimum.Y = 0 }
|
||||
@ -260,8 +254,8 @@ func (this *containerBox) doLayout () {
|
||||
this.box.doLayout()
|
||||
previousContentBounds := this.contentBounds
|
||||
|
||||
// by default, use innerBounds for contentBounds. if a direction
|
||||
// overflows, use the layout's minimum size for it.
|
||||
// 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 (
|
||||
@ -269,19 +263,33 @@ func (this *containerBox) doLayout () {
|
||||
this.children)
|
||||
}
|
||||
innerBounds := this.InnerBounds()
|
||||
this.contentBounds = innerBounds
|
||||
this.contentBounds = innerBounds.Sub(innerBounds.Min)
|
||||
if this.hOverflow { this.contentBounds.Max.X = this.contentBounds.Min.X + minimum.X }
|
||||
if this.vOverflow { this.contentBounds.Max.Y = this.contentBounds.Min.Y + minimum.Y }
|
||||
|
||||
// offset the content bounds by the scroll so children can be positioned
|
||||
// accordingly.
|
||||
this.constrainScroll()
|
||||
this.contentBounds = this.contentBounds.Add(this.scroll).Sub(innerBounds.Min)
|
||||
|
||||
// arrange children
|
||||
if this.layout != nil {
|
||||
this.layout.Arrange(this.boundedLayoutHints(), this.children)
|
||||
layoutHints := this.layoutHints()
|
||||
layoutHints.Bounds = this.contentBounds
|
||||
this.layout.Arrange(layoutHints, this.children)
|
||||
}
|
||||
|
||||
// build an accurate contentBounds by unioning the bounds of all child
|
||||
// boxes
|
||||
this.contentBounds = image.Rectangle { }
|
||||
for _, box := range this.children {
|
||||
bounds := box.Bounds()
|
||||
this.contentBounds = this.contentBounds.Union(bounds)
|
||||
}
|
||||
|
||||
// constrain the scroll
|
||||
this.constrainScroll()
|
||||
|
||||
// offset children and contentBounds by scroll
|
||||
for _, box := range this.children {
|
||||
box.SetBounds(box.Bounds().Add(this.scroll).Add(innerBounds.Min))
|
||||
}
|
||||
this.contentBounds = this.contentBounds.Add(this.scroll)
|
||||
|
||||
if previousContentBounds != this.contentBounds {
|
||||
this.on.contentBoundsChange.Broadcast()
|
||||
|
Reference in New Issue
Block a user