Skip to content

Commit

Permalink
cleaup code
Browse files Browse the repository at this point in the history
  • Loading branch information
dreacot committed Oct 11, 2023
1 parent 30fac38 commit 17f13d3
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions ui/cryptomaterial/segmented_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ type SegmentedControl struct {
list *ClickableList

selectedIndex int
segmentItems []string
segmentTitles []string

changed bool
}

func (t *Theme) SegmentedControl(segmentItems []string) *SegmentedControl {
func (t *Theme) SegmentedControl(segmentTitles []string) *SegmentedControl {
list := t.NewClickableList(layout.Horizontal)
list.IsHoverable = false

return &SegmentedControl{
list: list,
theme: t,
segmentItems: segmentItems,
list: list,
theme: t,
segmentTitles: segmentTitles,
}
}

Expand Down Expand Up @@ -77,6 +77,9 @@ func (sc *SegmentedControl) Layout(gtx C) D {

func (sc *SegmentedControl) handleEvents() {
if segmentItemClicked, clickedSegmentIndex := sc.list.ItemClicked(); segmentItemClicked {
if sc.selectedIndex != clickedSegmentIndex {
sc.changed = true
}
sc.selectedIndex = clickedSegmentIndex
}
}
Expand All @@ -98,6 +101,7 @@ func (sc *SegmentedControl) SetSelectedSegment(segment string) {
for i, item := range sc.segmentItems {
if item == segment {
sc.selectedIndex = i
break
}
}
}

0 comments on commit 17f13d3

Please sign in to comment.