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
29 changes: 14 additions & 15 deletions core/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,17 +650,18 @@ func (wb *WidgetBase) updateParentRelSizes() bool {
return false
}
sz := &wb.Geom.Size
effmin := sz.Min
s := &wb.Styles
psz := pwb.Geom.Size.Alloc.Content.Sub(pwb.Geom.Size.InnerSpace)
got := false
for d := math32.X; d <= math32.Y; d++ {
if s.Min.Dim(d).Unit == units.UnitPw {
got = true
sz.Min.SetDim(d, psz.X*0.01*s.Min.Dim(d).Value)
effmin.SetDim(d, psz.X*0.01*s.Min.Dim(d).Value)
}
if s.Min.Dim(d).Unit == units.UnitPh {
got = true
sz.Min.SetDim(d, psz.Y*0.01*s.Min.Dim(d).Value)
effmin.SetDim(d, psz.Y*0.01*s.Min.Dim(d).Value)
}
if s.Max.Dim(d).Unit == units.UnitPw {
got = true
Expand All @@ -672,8 +673,8 @@ func (wb *WidgetBase) updateParentRelSizes() bool {
}
}
if got {
sz.FitSizeMax(&sz.Actual.Total, sz.Min)
sz.FitSizeMax(&sz.Alloc.Total, sz.Min)
sz.FitSizeMax(&sz.Actual.Total, effmin)
sz.FitSizeMax(&sz.Alloc.Total, effmin)
sz.setContentFromTotal(&sz.Actual)
sz.setContentFromTotal(&sz.Alloc)
}
Expand Down Expand Up @@ -1004,9 +1005,9 @@ func (fr *Frame) sizeFromChildrenStacked() math32.Vector2 {
// as Actual sizes must always represent the minimums (see Position).
// Returns true if any change in Actual size occurred.
func (wb *WidgetBase) SizeDown(iter int) bool {
prel := wb.updateParentRelSizes()
wb.updateParentRelSizes()
redo := wb.sizeDownParts(iter)
return prel || redo
return redo
}

func (wb *WidgetBase) sizeDownParts(iter int) bool {
Expand Down Expand Up @@ -1103,7 +1104,7 @@ func (fr *Frame) sizeDownFrame(iter int) bool {
if !fr.HasChildren() || !fr.layout.shapeCheck(fr, "SizeDown") {
return fr.WidgetBase.SizeDown(iter) // behave like a widget
}
prel := fr.updateParentRelSizes()
fr.updateParentRelSizes()
sz := &fr.Geom.Size
styles.SetClampMaxVector(&sz.Alloc.Content, sz.Max) // can't be more than max..
sz.setTotalFromContent(&sz.Alloc)
Expand All @@ -1120,11 +1121,11 @@ func (fr *Frame) sizeDownFrame(iter int) bool {
}
fr.This.(Layouter).SizeDownSetAllocs(iter)
redo := fr.sizeDownChildren(iter)
if prel || redo || wrapped {
if redo || wrapped {
fr.sizeFromChildrenFit(iter, SizeDownPass)
}
fr.sizeDownParts(iter) // no std role, just get sizes
return chg || wrapped || redo || prel
return chg || wrapped || redo
}

// SizeDownSetAllocs is the key SizeDown step that sets the allocations
Expand Down Expand Up @@ -1431,7 +1432,7 @@ func (fr *Frame) sizeDownAllocActualStacked(iter int) {
}

func (fr *Frame) sizeDownCustom(iter int) bool {
prel := fr.updateParentRelSizes()
fr.updateParentRelSizes()
fr.growToAlloc()
sz := &fr.Geom.Size
if DebugSettings.LayoutTrace {
Expand All @@ -1448,7 +1449,7 @@ func (fr *Frame) sizeDownCustom(iter int) bool {
})
redo := fr.sizeDownChildren(iter)
fr.sizeDownParts(iter) // no std role, just get sizes
return prel || redo
return redo
}

// sizeFinalUpdateChildrenSizes can optionally be called for layouts
Expand Down Expand Up @@ -1548,15 +1549,13 @@ func (fr *Frame) sizeFinalChildren() {
}

// styleSizeUpdate updates styling size values for widget and its parent,
// which should be called after these are updated. Returns true if any changed.
// which should be called after these are updated. Returns true if any changed.
func (wb *WidgetBase) styleSizeUpdate() bool {
pwb := wb.parentWidget()
if pwb == nil {
return false
}
if !wb.updateParentRelSizes() {
return false
}
wb.updateParentRelSizes()
scsz := wb.Scene.SceneGeom.Size
sz := wb.Geom.Size.Alloc.Content
psz := pwb.Geom.Size.Alloc.Content
Expand Down
66 changes: 66 additions & 0 deletions core/layout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,72 @@ func TestParentRelativeSize(t *testing.T) {
b.AssertRender(t, "layout/parent-relative")
}

func TestParentRelativeSizeSplits(t *testing.T) {
b := NewBody()
b.Styler(func(s *styles.Style) {
s.Min.Set(units.Dp(400))
})

splitFrame := NewSplits(b)
splitFrame.Styler(func(s *styles.Style) {
s.Grow.Set(1, 1)
s.Direction = styles.Row
})
splitFrame.SetSplits(20, 60, 20)
//
firstFrame := NewFrame(splitFrame)
firstFrame.Styler(func(s *styles.Style) {
s.Grow.Set(1, 1)
s.Border.Width.Set(units.Dp(4))
s.CenterAll()
})
NewText(firstFrame).SetText("20% Split Frame")

// The center of the split, created so that we can put child widgets in it
centerFrame := NewFrame(splitFrame)
centerFrame.Styler(func(s *styles.Style) {
s.Direction = styles.Column
s.Grow.Set(1, 1)
//s.Overflow.Set(styles.OverflowHidden)
})

// represents a top "menu" bar that has buttons in it
centerMenu := NewFrame(centerFrame)
centerMenu.Styler(func(s *styles.Style) {
s.Min.Set(units.Pw(100), units.Ph(10))
s.Max.Set(units.Pw(100), units.Ph(10))
s.Border.Width.Set(units.Dp(4))
s.CenterAll()
})
NewText(centerMenu).SetText("Menu Bar")

// the frame that the child widget will use to wrap its content so that from the outside we only have a single frame
centerContentArea := NewFrame(centerFrame)
centerContentArea.Styler(func(s *styles.Style) {
s.Grow.Set(1, 1)
s.Border.Width.Set(units.Dp(4))
s.Overflow.Set(styles.OverflowScroll)
})
//
// represents content that will be too large for this frame, user will need to scroll this on both
// axes to interact with it correctly
internalCenter := NewFrame(centerContentArea)
internalCenter.Styler(func(s *styles.Style) {
s.Min.Set(units.Pw(125), units.Ph(125))
s.CenterAll()
})
NewText(internalCenter).SetText("Content in center frame")
//
lastFrame := NewFrame(splitFrame)
lastFrame.Styler(func(s *styles.Style) {
s.Grow.Set(1, 1)
s.CenterAll()
s.Border.Width.Set(units.Dp(4))
})
NewText(lastFrame).SetText("20% Split Frame")
b.AssertRender(t, "layout/parent-relative-splits")
}

func TestCustomLayout(t *testing.T) {
b := NewBody()
b.Styler(func(s *styles.Style) {
Expand Down
7 changes: 7 additions & 0 deletions core/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,13 @@ func (tx *Text) SizeDown(iter int) bool {
return chg
}

// todo: could enable this if we see any stragglers
// func (tx *Text) SizeFinal() {
// tx.WidgetBase.SizeFinal()
// asz := tx.Geom.Size.Actual.Content
// tx.configTextAlloc(asz)
// }

func (tx *Text) Render() {
tx.WidgetBase.Render()
tx.Scene.Painter.DrawText(tx.paintText, tx.Geom.Pos.Content)
Expand Down
Loading