Fix AudioOptions navigation
This commit is contained in:
@@ -15,10 +15,12 @@ import (
|
||||
"rhemawavetech.com/rhemawave/internal/shaderManager"
|
||||
)
|
||||
|
||||
// focusToggle is the focus state of the audio on/off toggle, the bottommost
|
||||
// focusable item. Focus states increase from top to bottom on screen:
|
||||
// 0 = Audio Track entry, 1 = Output Device entry, focusToggle = toggle.
|
||||
const focusToggle = 2
|
||||
// focusToggle is the focus state of the audio on/off toggle, the topmost
|
||||
// focusable item on screen (Y increases upward). Focus states increase from
|
||||
// top to bottom: focusToggle = toggle, 1 = Output Device, maxFocus = Audio Track.
|
||||
const focusToggle = 0
|
||||
|
||||
const maxFocus = 2
|
||||
|
||||
const triangleSize = float32(16)
|
||||
|
||||
@@ -304,10 +306,10 @@ func (p *AudioOptions) updateCursorPosition() {
|
||||
switch {
|
||||
case p.focusState == focusToggle:
|
||||
item = &p.AudioStatusToggle
|
||||
case p.focusState == 0:
|
||||
item = &p.audioTrackItem
|
||||
case p.focusState == 1:
|
||||
item = &p.outputDeviceItem
|
||||
case p.focusState == 2:
|
||||
item = &p.audioTrackItem
|
||||
default:
|
||||
return
|
||||
}
|
||||
@@ -329,16 +331,16 @@ func (p *AudioOptions) ToggleAudio() {
|
||||
}
|
||||
|
||||
// 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
|
||||
// navigation never skips the Output Device entry.
|
||||
// on screen. Focus states run focusToggle (toggle) to maxFocus (Audio Track),
|
||||
// so navigation never skips the Output Device entry.
|
||||
func moveFocus(current, delta int) int {
|
||||
next := current + delta
|
||||
if next < 0 {
|
||||
next = 0
|
||||
}
|
||||
if next > focusToggle {
|
||||
if next < focusToggle {
|
||||
next = focusToggle
|
||||
}
|
||||
if next > maxFocus {
|
||||
next = maxFocus
|
||||
}
|
||||
return next
|
||||
}
|
||||
|
||||
@@ -353,10 +355,10 @@ func (p *AudioOptions) HandleEvent(event *sdl.Event) error {
|
||||
switch p.focusState {
|
||||
case focusToggle:
|
||||
p.ToggleAudio()
|
||||
case 0:
|
||||
p.Context.NavigateTo(TRACKS)
|
||||
case 1:
|
||||
p.Context.NavigateTo(AUDIO_DEVICES)
|
||||
case 2:
|
||||
p.Context.NavigateTo(TRACKS)
|
||||
}
|
||||
|
||||
case sdl.K_DOWN:
|
||||
|
||||
@@ -9,14 +9,14 @@ func TestMoveFocus(t *testing.T) {
|
||||
delta int
|
||||
want int
|
||||
}{
|
||||
{"down from track goes to device", 0, 1, 1},
|
||||
{"down from device goes to toggle", 1, 1, focusToggle},
|
||||
{"down from toggle stays", focusToggle, 1, focusToggle},
|
||||
{"up from toggle goes to device", focusToggle, -1, 1},
|
||||
{"up from device goes to track", 1, -1, 0},
|
||||
{"up from track stays", 0, -1, 0},
|
||||
{"down does not overshoot below toggle", focusToggle, 5, focusToggle},
|
||||
{"up does not undershoot above track", 0, -5, 0},
|
||||
{"down from toggle goes to device", focusToggle, 1, 1},
|
||||
{"down from device goes to track", 1, 1, 2},
|
||||
{"down from track stays", 2, 1, 2},
|
||||
{"up from track goes to device", 2, -1, 1},
|
||||
{"up from device goes to toggle", 1, -1, focusToggle},
|
||||
{"up from toggle stays", focusToggle, -1, focusToggle},
|
||||
{"down does not overshoot below track", maxFocus, 5, maxFocus},
|
||||
{"up does not undershoot above toggle", focusToggle, -5, focusToggle},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
||||
Reference in New Issue
Block a user