Fix AudioOptions navigation

This commit is contained in:
NeilClack
2026-08-08 00:59:22 -05:00
parent 843170b282
commit 1b80265e80
2 changed files with 24 additions and 22 deletions
+16 -14
View File
@@ -15,10 +15,12 @@ import (
"rhemawavetech.com/rhemawave/internal/shaderManager" "rhemawavetech.com/rhemawave/internal/shaderManager"
) )
// focusToggle is the focus state of the audio on/off toggle, the bottommost // focusToggle is the focus state of the audio on/off toggle, the topmost
// focusable item. Focus states increase from top to bottom on screen: // focusable item on screen (Y increases upward). Focus states increase from
// 0 = Audio Track entry, 1 = Output Device entry, focusToggle = toggle. // top to bottom: focusToggle = toggle, 1 = Output Device, maxFocus = Audio Track.
const focusToggle = 2 const focusToggle = 0
const maxFocus = 2
const triangleSize = float32(16) const triangleSize = float32(16)
@@ -304,10 +306,10 @@ func (p *AudioOptions) updateCursorPosition() {
switch { switch {
case p.focusState == focusToggle: case p.focusState == focusToggle:
item = &p.AudioStatusToggle item = &p.AudioStatusToggle
case p.focusState == 0:
item = &p.audioTrackItem
case p.focusState == 1: case p.focusState == 1:
item = &p.outputDeviceItem item = &p.outputDeviceItem
case p.focusState == 2:
item = &p.audioTrackItem
default: default:
return return
} }
@@ -329,16 +331,16 @@ func (p *AudioOptions) ToggleAudio() {
} }
// moveFocus returns the focus state after moving by delta (1 = down, -1 = up) // moveFocus returns the focus state after moving by delta (1 = down, -1 = up)
// on screen. Focus states run 0 (Audio Track) to focusToggle (toggle), so // on screen. Focus states run focusToggle (toggle) to maxFocus (Audio Track),
// navigation never skips the Output Device entry. // so navigation never skips the Output Device entry.
func moveFocus(current, delta int) int { func moveFocus(current, delta int) int {
next := current + delta next := current + delta
if next < 0 { if next < focusToggle {
next = 0
}
if next > focusToggle {
next = focusToggle next = focusToggle
} }
if next > maxFocus {
next = maxFocus
}
return next return next
} }
@@ -353,10 +355,10 @@ func (p *AudioOptions) HandleEvent(event *sdl.Event) error {
switch p.focusState { switch p.focusState {
case focusToggle: case focusToggle:
p.ToggleAudio() p.ToggleAudio()
case 0:
p.Context.NavigateTo(TRACKS)
case 1: case 1:
p.Context.NavigateTo(AUDIO_DEVICES) p.Context.NavigateTo(AUDIO_DEVICES)
case 2:
p.Context.NavigateTo(TRACKS)
} }
case sdl.K_DOWN: case sdl.K_DOWN:
+8 -8
View File
@@ -9,14 +9,14 @@ func TestMoveFocus(t *testing.T) {
delta int delta int
want int want int
}{ }{
{"down from track goes to device", 0, 1, 1}, {"down from toggle goes to device", focusToggle, 1, 1},
{"down from device goes to toggle", 1, 1, focusToggle}, {"down from device goes to track", 1, 1, 2},
{"down from toggle stays", focusToggle, 1, focusToggle}, {"down from track stays", 2, 1, 2},
{"up from toggle goes to device", focusToggle, -1, 1}, {"up from track goes to device", 2, -1, 1},
{"up from device goes to track", 1, -1, 0}, {"up from device goes to toggle", 1, -1, focusToggle},
{"up from track stays", 0, -1, 0}, {"up from toggle stays", focusToggle, -1, focusToggle},
{"down does not overshoot below toggle", focusToggle, 5, focusToggle}, {"down does not overshoot below track", maxFocus, 5, maxFocus},
{"up does not undershoot above track", 0, -5, 0}, {"up does not undershoot above toggle", focusToggle, -5, focusToggle},
} }
for _, tt := range tests { for _, tt := range tests {