Remove devices list and device vector length check

This commit is contained in:
NeilClack
2026-04-23 17:26:22 -05:00
parent 9575833392
commit 05a7098886
8 changed files with 71 additions and 80 deletions
+35 -41
View File
@@ -5,7 +5,6 @@ import (
"github.com/go-gl/gl/v3.3-core/gl"
"github.com/veandco/go-sdl2/sdl"
"gorm.io/gorm"
"rhemawavetech.com/rhemawave/internal/colors"
"rhemawavetech.com/rhemawave/internal/db"
"rhemawavetech.com/rhemawave/internal/fontManager"
@@ -25,7 +24,7 @@ type AudioDevices struct {
selectedIndex int
verticalMargin int32
CfgPtr *db.AppConfig
dbPtr *gorm.DB
// DbPtr *gorm.DB
}
func (p *AudioDevices) Init(ctx *PageCtx) error {
@@ -57,7 +56,7 @@ func (p *AudioDevices) Init(ctx *PageCtx) error {
}
// Get font size from database
baseFontSize := p.Base.Context.CfgPtr.StandardFontSize
baseFontSize := p.Context.CfgPtr.StandardFontSize
// Calculate scales
titleScale := float32(64) / float32(baseFontSize)
@@ -85,7 +84,7 @@ func (p *AudioDevices) Init(ctx *PageCtx) error {
}
// Get currently selected device from database
currentDevice := p.Base.Context.CfgPtr.SelectedAudioDevice
currentDevice := p.Context.CfgPtr.SelectedAudioDevice
// Create UI items for each device
for i, name := range devices { // Iterate over the devices
@@ -103,7 +102,7 @@ func (p *AudioDevices) Init(ctx *PageCtx) error {
}
}
on := p.Base.Context.CfgPtr.AudioEnabled
on := p.Context.CfgPtr.AudioEnabled
audioStatus := "Turn Audio On"
if on {
@@ -166,11 +165,11 @@ func (p *AudioDevices) HandleEvent(event *sdl.Event) error {
// Handle audio disable
if selection == "Turn Audio Off" || selection == "Turn Audio On" {
newStatus := !p.Base.Context.CfgPtr.AudioEnabled
updatedConfig := p.Base.Context.CfgPtr
newStatus := !p.Context.CfgPtr.AudioEnabled
updatedConfig := p.Context.CfgPtr
updatedConfig.AudioEnabled = newStatus
p.Base.Context.DbPtr.Save(&updatedConfig)
p.Base.Context.RefreshConfig()
p.Context.DbPtr.Save(&updatedConfig)
p.Context.RefreshConfig()
return nil
}
@@ -186,12 +185,12 @@ func (p *AudioDevices) HandleEvent(event *sdl.Event) error {
}
// Save settings
p.Base.Context.CfgPtr.SelectedAudioDevice = deviceName
p.Base.Context.CfgPtr.AudioEnabled = true
p.Base.Context.DbPtr.Save(p.Base.Context.CfgPtr)
p.Base.Context.RefreshConfig()
p.Context.CfgPtr.SelectedAudioDevice = deviceName
p.Context.CfgPtr.AudioEnabled = true
p.Context.DbPtr.Save(p.Context.CfgPtr)
p.Context.RefreshConfig()
case sdl.K_BACKSPACE:
p.Base.Context.NavigateTo(SETTINGS)
p.Context.NavigateTo(SETTINGS)
}
return nil
@@ -202,36 +201,31 @@ func (p *AudioDevices) Render() error {
p.RenderTexture(p.textShader, p.title.ID, p.title.Position(), p.title.RawDimensions(), p.title.Color)
p.RenderTexture(p.textShader, p.prompt.ID, p.prompt.Position(), p.prompt.RawDimensions(), p.prompt.Color)
// No devices to display
if len(p.devices) == 0 {
return nil
}
// Render highlight box behind highlighted item
p.RenderSolidColorQuad(
p.solidShader,
p.devices[p.highlightIndex].Position(),
p.devices[p.highlightIndex].RawDimensions(),
colors.White,
)
//p.RenderSolidColorQuad(
// p.solidShader,
// p.devices[p.highlightIndex].Position(),
// p.devices[p.highlightIndex].RawDimensions(),
// colors.White,
//)
// Render device items with appropriate colors
for i, item := range p.devices {
if i == p.highlightIndex && i == p.selectedIndex {
// Currently highlighted AND selected device - dark green
item.Color = colors.DarkGreen
} else if i == p.highlightIndex {
// Just highlighted - black (shows on white background)
item.Color = colors.Black
} else if i == p.selectedIndex {
// Just selected - green
item.Color = colors.Green
} else {
// Normal item - white
item.Color = colors.White
}
p.RenderTexture(p.textShader, item.ID, item.Position(), item.RawDimensions(), item.Color)
}
//for i, item := range p.devices {
// if i == p.highlightIndex && i == p.selectedIndex {
// // Currently highlighted AND selected device - dark green
// item.Color = colors.DarkGreen
// } else if i == p.highlightIndex {
// // Just highlighted - black (shows on white background)
// item.Color = colors.Black
// } else if i == p.selectedIndex {
// // Just selected - green
// item.Color = colors.Green
// } else {
// // Normal item - white
// item.Color = colors.White
// }
// p.RenderTexture(p.textShader, item.ID, item.Position(), item.RawDimensions(), item.Color)
//}
return nil
}