Skip to content

Commit

Permalink
Merge pull request #556 from gucio321/splitable-widgets
Browse files Browse the repository at this point in the history
Widgets: add Range methods to some of widgets
  • Loading branch information
AllenDang authored Nov 14, 2022
2 parents 8769e58 + d2572f1 commit 126ef9a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ExtraWidgets.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,19 @@ func Condition(cond bool, layoutIf, layoutElse Layout) *ConditionWidget {
}
}

func (c *ConditionWidget) Range(rangeFunc func(w Widget)) {
var l Layout
if c.cond {
l = c.layoutIf
} else {
l = c.layoutElse
}

if l != nil {
l.Range(rangeFunc)
}
}

// Build implements Widget interface.
func (c *ConditionWidget) Build() {
if c.cond {
Expand Down
14 changes: 14 additions & 0 deletions StyleSetter.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ func (ss *StyleSetter) To(widgets ...Widget) *StyleSetter {
return ss
}

func (ss *StyleSetter) Range(rangeFunc func(w Widget)) {
if ss.layout != nil {
Layout{
Custom(func() {
ss.Push()
}),
ss.layout,
Custom(func() {
ss.Pop()
}),
}.Range(rangeFunc)
}
}

// Build implements Widget.
func (ss *StyleSetter) Build() {
if ss.layout == nil || len(ss.layout) == -1 {
Expand Down

0 comments on commit 126ef9a

Please sign in to comment.