Skip to content
Open
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
14 changes: 8 additions & 6 deletions menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,17 @@ func menu() int16 {
for {
pressed, _ := buttons.ReadInput()

if released && buttons.Pins[shifter.BUTTON_UP].Get() && selected > 0 {
selected--
if released && buttons.Pins[shifter.BUTTON_UP].Get(){
prevSel := selected
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better if we pre-allocate/define the variable outside the loop (at the same time as selected instead to create it each time.
Also, maybe call it prevSelected to keep the parallelism with selected

what do you thing?

selected = (numOpts + selected -1) % numOpts
tinydraw.FilledCircle(&display, 32, 37+10*selected, 2, color.RGBA{200, 200, 0, 255})
tinydraw.FilledCircle(&display, 32, 37+10*(selected+1), 2, color.RGBA{255, 255, 255, 255})
tinydraw.FilledCircle(&display, 32, 37+10*prevSel, 2, color.RGBA{255, 255, 255, 255})
}
if released && buttons.Pins[shifter.BUTTON_DOWN].Get() && selected < (numOpts-1) {
selected++
if released && buttons.Pins[shifter.BUTTON_DOWN].Get() {
prevSel := selected
selected = (selected +1 ) % numOpts
tinydraw.FilledCircle(&display, 32, 37+10*selected, 2, color.RGBA{200, 200, 0, 255})
tinydraw.FilledCircle(&display, 32, 37+10*(selected-1), 2, color.RGBA{255, 255, 255, 255})
tinydraw.FilledCircle(&display, 32, 37+10*prevSel, 2, color.RGBA{255, 255, 255, 255})
}
if released && buttons.Pins[shifter.BUTTON_START].Get() {
break
Expand Down