From 7284d899e967497e3dea267aa7d917c0714571f4 Mon Sep 17 00:00:00 2001 From: Justin Do Date: Tue, 5 Dec 2023 15:17:06 +0700 Subject: [PATCH] update logic on slider and segmented control --- ui/cryptomaterial/segmented_control.go | 8 ++++++++ ui/cryptomaterial/slider.go | 3 +++ 2 files changed, 11 insertions(+) diff --git a/ui/cryptomaterial/segmented_control.go b/ui/cryptomaterial/segmented_control.go index a64277693..769aad40a 100644 --- a/ui/cryptomaterial/segmented_control.go +++ b/ui/cryptomaterial/segmented_control.go @@ -33,6 +33,8 @@ type SegmentedControl struct { slideAction *SlideAction slideActionTitle *SlideAction segmentType SegmentType + + IsAllowsCycle bool } func (t *Theme) SegmentedControl(segmentTitles []string, segmentType SegmentType) *SegmentedControl { @@ -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++ @@ -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-- diff --git a/ui/cryptomaterial/slider.go b/ui/cryptomaterial/slider.go index 3fe556864..d92ae4df2 100644 --- a/ui/cryptomaterial/slider.go +++ b/ui/cryptomaterial/slider.go @@ -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,