Skip to content

Commit

Permalink
Merge pull request #1305 from cogentcore/custom
Browse files Browse the repository at this point in the history
rename NoLayout -> Custom and remove print statement
  • Loading branch information
kkoreilly authored Nov 14, 2024
2 parents 006fc7b + 5374440 commit 7f87bc3
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 20 deletions.
13 changes: 6 additions & 7 deletions core/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ func (wb *WidgetBase) sizeUpParts() {
}

func (fr *Frame) SizeUp() {
if fr.Styles.Display == styles.NoLayout {
if fr.Styles.Display == styles.Custom {
fr.SizeUpWidget()
fr.sizeUpChildren()
return
Expand Down Expand Up @@ -1152,7 +1152,7 @@ func (fr *Frame) SizeDown(iter int) bool {
// iteration is required. It allocates sizes to fit given parent-allocated
// total size.
func (fr *Frame) sizeDownFrame(iter int) bool {
if fr.Styles.Display == styles.NoLayout {
if fr.Styles.Display == styles.Custom {
fr.WidgetBase.SizeDown(iter) // behave like a widget
return fr.sizeDownChildren(iter)
}
Expand Down Expand Up @@ -1545,7 +1545,7 @@ func (wb *WidgetBase) sizeFinalParts() {
}

func (fr *Frame) SizeFinal() {
if fr.Styles.Display == styles.NoLayout {
if fr.Styles.Display == styles.Custom {
fr.WidgetBase.SizeFinal() // behave like a widget
fr.sizeFinalChildren()
return
Expand Down Expand Up @@ -1653,7 +1653,7 @@ func (wb *WidgetBase) positionChildren() {
// Position: uses the final sizes to position everything within layouts
// according to alignment settings.
func (fr *Frame) Position() {
if fr.Styles.Display == styles.NoLayout {
if fr.Styles.Display == styles.Custom {
fr.positionFromPos()
return
}
Expand Down Expand Up @@ -1847,7 +1847,7 @@ func (fr *Frame) applyScenePosChildren() {
// This step can be performed when scrolling after updating Scroll.
func (fr *Frame) ApplyScenePos() {
fr.scrollResetIfNone()
if fr.Styles.Display == styles.NoLayout {
if fr.Styles.Display == styles.Custom {
fr.WidgetBase.ApplyScenePos()
fr.applyScenePosChildren()
fr.PositionScrolls()
Expand Down Expand Up @@ -1875,12 +1875,11 @@ func (fr *Frame) scrollResetIfNone() {
}
}

// positionFromPos does NoLayout positioning from style positions.
// positionFromPos does Custom positioning from style positions.
func (fr *Frame) positionFromPos() {
fr.forVisibleChildren(func(i int, cw Widget, cwb *WidgetBase) bool {
cwb.Geom.RelPos.X = cwb.Styles.Pos.X.Dots
cwb.Geom.RelPos.Y = cwb.Styles.Pos.Y.Dots
fmt.Println("set pos:", cwb.Geom.RelPos)
return tree.Continue
})
}
Expand Down
6 changes: 3 additions & 3 deletions core/layout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,14 @@ func TestParentRelativeSize(t *testing.T) {
b.AssertRender(t, "layout/parent-relative")
}

func TestNoLayoutPos(t *testing.T) {
func TestCustomLayout(t *testing.T) {
b := NewBody()
b.Styler(func(s *styles.Style) {
s.Min.Set(units.Dp(100))
})
fr := NewFrame(b)
fr.Styler(func(s *styles.Style) {
s.Display = styles.NoLayout
s.Display = styles.Custom
s.Grow.Set(1, 1)
})
NewFrame(fr).Styler(func(s *styles.Style) {
Expand All @@ -256,5 +256,5 @@ func TestNoLayoutPos(t *testing.T) {
s.Min.Set(units.Dp(40))
s.Pos.Set(units.Dp(50))
})
b.AssertRender(t, "layout/no-layout")
b.AssertRender(t, "layout/custom")
}
8 changes: 4 additions & 4 deletions styles/enumgen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions styles/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ const (
// of elements in the X axis.
Grid

// NoLayout means that no automatic layout will be applied to elements,
// Custom means that no automatic layout will be applied to elements,
// which can then be managed via custom code by setting the [Style.Pos] position.
NoLayout
Custom

// None means the item is not displayed: sets the Invisible state
DisplayNone
Expand Down
2 changes: 1 addition & 1 deletion styles/style.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ type Style struct { //types:add
VirtualKeyboard VirtualKeyboards

// Pos is used for the position of the widget if the parent frame
// has [Style.Display] = [NoLayout].
// has [Style.Display] = [Custom].
Pos units.XY `display:"inline"`

// ordering factor for rendering depth -- lower numbers rendered first.
Expand Down
Loading

0 comments on commit 7f87bc3

Please sign in to comment.