Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions core/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -1153,8 +1153,7 @@ func (fr *Frame) SizeDown(iter int) bool {
// total size.
func (fr *Frame) sizeDownFrame(iter int) bool {
if fr.Styles.Display == styles.Custom {
fr.WidgetBase.SizeDown(iter) // behave like a widget
return fr.sizeDownChildren(iter)
return fr.sizeDownCustom(iter)
}
if !fr.HasChildren() || !fr.layout.shapeCheck(fr, "SizeDown") {
return fr.WidgetBase.SizeDown(iter) // behave like a widget
Expand Down Expand Up @@ -1486,6 +1485,27 @@ func (fr *Frame) sizeDownAllocActualStacked(iter int) {
})
}

func (fr *Frame) sizeDownCustom(iter int) bool {
prel := fr.updateParentRelSizes()
fr.growToAlloc()
sz := &fr.Geom.Size
if DebugSettings.LayoutTrace {
fmt.Println(fr, "Custom Managing Alloc:", sz.Alloc.Content)
}
styles.SetClampMaxVector(&sz.Alloc.Content, sz.Max) // can't be more than max..
// this allocates our full size to each child, same as ActualStacked all case
asz := sz.Actual.Content
fr.ForWidgetChildren(func(i int, cw Widget, cwb *WidgetBase) bool {
ksz := &cwb.Geom.Size
ksz.Alloc.Total = asz
ksz.setContentFromTotal(&ksz.Alloc)
return tree.Continue
})
redo := fr.sizeDownChildren(iter)
fr.sizeDownParts(iter) // no std role, just get sizes
return prel || redo
}

// sizeFinalUpdateChildrenSizes can optionally be called for layouts
// that dynamically create child elements based on final layout size.
// It ensures that the children are properly sized.
Expand Down Expand Up @@ -1547,7 +1567,7 @@ func (wb *WidgetBase) sizeFinalParts() {
func (fr *Frame) SizeFinal() {
if fr.Styles.Display == styles.Custom {
fr.WidgetBase.SizeFinal() // behave like a widget
fr.sizeFinalChildren()
fr.WidgetBase.sizeFinalChildren()
return
}
if !fr.HasChildren() || !fr.layout.shapeCheck(fr, "SizeFinal") {
Expand Down Expand Up @@ -1655,6 +1675,7 @@ func (wb *WidgetBase) positionChildren() {
func (fr *Frame) Position() {
if fr.Styles.Display == styles.Custom {
fr.positionFromPos()
fr.positionChildren()
return
}
if !fr.HasChildren() || !fr.layout.shapeCheck(fr, "Position") {
Expand Down
14 changes: 14 additions & 0 deletions core/layout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,17 @@ func TestCustomLayout(t *testing.T) {
})
b.AssertRender(t, "layout/custom")
}

func TestCustomLayoutButton(t *testing.T) {
b := NewBody()
b.Styler(func(s *styles.Style) {
s.Display = styles.Custom
s.Min.Set(units.Dp(200), units.Dp(100))
})
bt := NewButton(b).SetText("Hello")
bt.Styler(func(s *styles.Style) {
s.Min.X.Dp(100)
s.Pos.Set(units.Dp(25))
})
b.AssertRender(t, "layout/custom-button")
}