Skip to content

Commit

Permalink
update logic on slider and segmented control
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeBoy committed Dec 5, 2023
1 parent aaca032 commit 7284d89
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ui/cryptomaterial/segmented_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ type SegmentedControl struct {
slideAction *SlideAction
slideActionTitle *SlideAction
segmentType SegmentType

IsAllowsCycle bool
}

func (t *Theme) SegmentedControl(segmentTitles []string, segmentType SegmentType) *SegmentedControl {
Expand Down Expand Up @@ -243,6 +245,9 @@ func (sc *SegmentedControl) handleActionEvent(isNext bool) {
l := len(sc.segmentTitles) - 1 // index starts at 0
if isNext {
if sc.selectedIndex == l {
if !sc.IsAllowsCycle {
return
}
sc.selectedIndex = 0
} else {
sc.selectedIndex++
Expand All @@ -251,6 +256,9 @@ func (sc *SegmentedControl) handleActionEvent(isNext bool) {
sc.slideActionTitle.PushLeft()
} else {
if sc.selectedIndex == 0 {
if !sc.IsAllowsCycle {
return
}
sc.selectedIndex = l
} else {
sc.selectedIndex--
Expand Down
3 changes: 3 additions & 0 deletions ui/cryptomaterial/slider.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ func (s *Slider) Layout(gtx C, items []layout.Widget) D {
return s.slideAction.TransformLayout(gtx, s.slideItems[s.selected].widgetItem)
}),
layout.Stacked(func(gtx C) D {
if len(s.slideItems) == 1 {
return D{}
}
return layout.Inset{
Right: values.MarginPadding15,
Left: values.MarginPadding15,
Expand Down

0 comments on commit 7284d89

Please sign in to comment.