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
35 changes: 35 additions & 0 deletions core/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,11 @@ func (wb *WidgetBase) sizeUpParts() {
}

func (fr *Frame) SizeUp() {
if fr.Styles.Display == styles.NoLayout {
fr.SizeUpWidget()
fr.sizeUpChildren()
return
}
if !fr.HasChildren() {
fr.SizeUpWidget() // behave like a widget
return
Expand Down Expand Up @@ -1147,6 +1152,10 @@ 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 {
fr.WidgetBase.SizeDown(iter) // behave like a widget
return fr.sizeDownChildren(iter)
}
if !fr.HasChildren() || !fr.layout.shapeCheck(fr, "SizeDown") {
return fr.WidgetBase.SizeDown(iter) // behave like a widget
}
Expand Down Expand Up @@ -1536,6 +1545,11 @@ func (wb *WidgetBase) sizeFinalParts() {
}

func (fr *Frame) SizeFinal() {
if fr.Styles.Display == styles.NoLayout {
fr.WidgetBase.SizeFinal() // behave like a widget
fr.sizeFinalChildren()
return
}
if !fr.HasChildren() || !fr.layout.shapeCheck(fr, "SizeFinal") {
fr.WidgetBase.SizeFinal() // behave like a widget
return
Expand Down Expand Up @@ -1639,6 +1653,10 @@ 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 {
fr.positionFromPos()
return
}
if !fr.HasChildren() || !fr.layout.shapeCheck(fr, "Position") {
fr.WidgetBase.Position() // behave like a widget
return
Expand Down Expand Up @@ -1829,6 +1847,13 @@ 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 {
fr.WidgetBase.ApplyScenePos()
fr.applyScenePosChildren()
fr.PositionScrolls()
fr.applyScenePosParts() // in case they fit inside parent
return
}
// note: ly.Geom.Scroll has the X, Y scrolling offsets, set by Layouter.ScrollChanged function
if !fr.HasChildren() || !fr.layout.shapeCheck(fr, "ScenePos") {
fr.WidgetBase.ApplyScenePos() // behave like a widget
Expand All @@ -1850,6 +1875,16 @@ func (fr *Frame) scrollResetIfNone() {
}
}

// positionFromPos does NoLayout 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
})
}

// DirectRenderDrawBBoxes returns the destination and source bounding boxes
// for RenderDraw call for widgets that do direct rendering.
// The destBBox.Min point can be passed as the dp destination point for Draw
Expand Down
23 changes: 23 additions & 0 deletions core/layout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,26 @@ func TestParentRelativeSize(t *testing.T) {
})
b.AssertRender(t, "layout/parent-relative")
}

func TestNoLayoutPos(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.Grow.Set(1, 1)
})
NewFrame(fr).Styler(func(s *styles.Style) {
s.Background = colors.Scheme.Select.Container
s.Min.Set(units.Dp(40))
s.Pos.Set(units.Dp(5))
})
NewFrame(fr).Styler(func(s *styles.Style) {
s.Background = colors.Scheme.Error.Base
s.Min.Set(units.Dp(40))
s.Pos.Set(units.Dp(50))
})
b.AssertRender(t, "layout/no-layout")
}
4 changes: 2 additions & 2 deletions styles/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (d Directions) Other() Directions {
return Row
}

// Displays determines how items are displayed
// Displays determines how items are displayed.
type Displays int32 //enums:enum -trim-prefix Display -transform kebab

const (
Expand All @@ -110,7 +110,7 @@ const (
Grid

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

// None means the item is not displayed: sets the Invisible state
Expand Down
2 changes: 1 addition & 1 deletion styles/style.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ type Style struct { //types:add
// in the horizontal axis to allow for longer, word wrapped text to fill
// the available space, but then it does not grow thereafter, so that alignment
// operations still work (Grow elements do not align because they absorb all
// available space).
// available space). Do NOT set this for non-Text elements.
GrowWrap bool

// RenderBox determines whether to render the standard box model for the element.
Expand Down
4 changes: 2 additions & 2 deletions styles/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,14 @@ type WhiteSpaces int32 //enums:enum -trim-prefix WhiteSpace
const (
// WhiteSpaceNormal means that all white space is collapsed to a single
// space, and text wraps when necessary. To get full word wrapping to
// expand to all available space, you also need to set GrowWrap = 1.
// expand to all available space, you also need to set GrowWrap = true.
// Use the SetTextWrap convenience method to set both.
WhiteSpaceNormal WhiteSpaces = iota

// WhiteSpaceNowrap means that sequences of whitespace will collapse into
// a single whitespace. Text will never wrap to the next line except
// if there is an explicit line break via a <br> tag. In general you
// also don't want simple non-wrapping text labels to Grow (GrowWrap = 0).
// also don't want simple non-wrapping text labels to Grow (GrowWrap = false).
// Use the SetTextWrap method to set both.
WhiteSpaceNowrap

Expand Down