Add global show_label_background setting with UI control
This commit is contained in:
parent
bb86e495c0
commit
c6103cd9a8
@ -3,6 +3,7 @@
|
||||
"log_level": "info",
|
||||
"default_page": "main",
|
||||
"font": "medium",
|
||||
"show_label_background": true,
|
||||
"devices": [
|
||||
{
|
||||
"serial": "",
|
||||
|
||||
@ -57,6 +57,7 @@ func Run(ctx context.Context, cfg *config.Config, opts RunOptions) error {
|
||||
for i, d := range decks {
|
||||
pageMgrs[i] = NewPageManager(d)
|
||||
pageMgrs[i].defaultFont = cfg.Font
|
||||
pageMgrs[i].showLabelBackground = cfg.ShowLabelBackground
|
||||
pageMgrs[i].LoadPages(cfg.Pages)
|
||||
}
|
||||
primaryPM := pageMgrs[0]
|
||||
@ -230,6 +231,7 @@ func Run(ctx context.Context, cfg *config.Config, opts RunOptions) error {
|
||||
activePages = append(activePages, pm.ActivePageName())
|
||||
pm.stopPeriodicKeys()
|
||||
pm.defaultFont = cfg.Font
|
||||
pm.showLabelBackground = cfg.ShowLabelBackground
|
||||
pm.LoadPages(cfg.Pages)
|
||||
}
|
||||
ge.ReloadTiming(cfg.Timing.LongPressMs, cfg.Timing.DoubleTapMs)
|
||||
@ -315,6 +317,7 @@ func reconnectDeck(ctx context.Context, cfg *config.Config, pm **PageManager, as
|
||||
if err == nil {
|
||||
*pm = NewPageManager(newDeck)
|
||||
(*pm).defaultFont = cfg.Font
|
||||
(*pm).showLabelBackground = cfg.ShowLabelBackground
|
||||
(*pm).LoadPages(cfg.Pages)
|
||||
(*pm).ActivatePage(cfg.DefaultPage)
|
||||
(*pm).startPeriodicKeys()
|
||||
|
||||
@ -11,15 +11,16 @@ import (
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Version int `json:"version"`
|
||||
LogLevel string `json:"log_level"`
|
||||
DefaultPage string `json:"default_page"`
|
||||
Font string `json:"font,omitempty"`
|
||||
Devices []DeviceConfig `json:"devices"`
|
||||
Pages []PageConfig `json:"pages"`
|
||||
AutoSwitch []SwitchRule `json:"auto_switch"`
|
||||
Screensaver ScreensaverCfg `json:"screensaver"`
|
||||
Timing TimingConfig `json:"timing,omitempty"`
|
||||
Version int `json:"version"`
|
||||
LogLevel string `json:"log_level"`
|
||||
DefaultPage string `json:"default_page"`
|
||||
Font string `json:"font,omitempty"`
|
||||
ShowLabelBackground bool `json:"show_label_background"`
|
||||
Devices []DeviceConfig `json:"devices"`
|
||||
Pages []PageConfig `json:"pages"`
|
||||
AutoSwitch []SwitchRule `json:"auto_switch"`
|
||||
Screensaver ScreensaverCfg `json:"screensaver"`
|
||||
Timing TimingConfig `json:"timing,omitempty"`
|
||||
}
|
||||
|
||||
type TimingConfig struct {
|
||||
@ -113,9 +114,10 @@ type ScreensaverCfg struct {
|
||||
|
||||
func DefaultConfig() *Config {
|
||||
return &Config{
|
||||
Version: 1,
|
||||
LogLevel: "info",
|
||||
DefaultPage: "default",
|
||||
Version: 1,
|
||||
LogLevel: "info",
|
||||
DefaultPage: "default",
|
||||
ShowLabelBackground: true,
|
||||
Pages: []PageConfig{
|
||||
{
|
||||
Name: "default",
|
||||
|
||||
10
render.go
10
render.go
@ -13,7 +13,7 @@ import (
|
||||
"streamdeck-lets-go/internal/config"
|
||||
)
|
||||
|
||||
func RenderKeyToImage(k *config.KeyConfig, keySize int) image.Image {
|
||||
func RenderKeyToImage(k *config.KeyConfig, keySize int, showLabelBackground bool) image.Image {
|
||||
if k == nil {
|
||||
return blankImage(keySize, color.RGBA{0, 0, 0, 255})
|
||||
}
|
||||
@ -46,7 +46,7 @@ func RenderKeyToImage(k *config.KeyConfig, keySize int) image.Image {
|
||||
if k.FontSize != nil {
|
||||
fontSize = *k.FontSize
|
||||
}
|
||||
return composeImageWithLabel(img, k.Label, keySize, fontSize)
|
||||
return composeImageWithLabel(img, k.Label, keySize, fontSize, showLabelBackground)
|
||||
}
|
||||
g := gift.New(gift.Resize(keySize, keySize, gift.LanczosResampling))
|
||||
rgba := image.NewRGBA(image.Rect(0, 0, keySize, keySize))
|
||||
@ -79,7 +79,7 @@ func blankImage(size int, c color.Color) image.Image {
|
||||
return img
|
||||
}
|
||||
|
||||
func composeImageWithLabel(src image.Image, text string, keySize int, fontSize float64) image.Image {
|
||||
func composeImageWithLabel(src image.Image, text string, keySize int, fontSize float64, showLabelBackground bool) image.Image {
|
||||
g := gift.New(gift.Resize(keySize, keySize, gift.LanczosResampling))
|
||||
rgba := image.NewRGBA(image.Rect(0, 0, keySize, keySize))
|
||||
g.Draw(rgba, src)
|
||||
@ -89,7 +89,9 @@ func composeImageWithLabel(src image.Image, text string, keySize int, fontSize f
|
||||
barHeight = 18
|
||||
}
|
||||
barRect := image.Rect(0, keySize-barHeight, keySize, keySize)
|
||||
draw.Draw(rgba, barRect, &image.Uniform{color.RGBA{0, 0, 0, 180}}, image.Point{}, draw.Over)
|
||||
if showLabelBackground {
|
||||
draw.Draw(rgba, barRect, &image.Uniform{color.RGBA{0, 0, 0, 180}}, image.Point{}, draw.Over)
|
||||
}
|
||||
|
||||
if text != "" {
|
||||
face, err := parseDisplayFace(fontSize)
|
||||
|
||||
@ -119,6 +119,7 @@ document.addEventListener('alpine:init', () => {
|
||||
this.settingsForm = {
|
||||
brightness: this.getDeviceConfig(this.activeDeckSerial)?.brightness ?? 75,
|
||||
font: this.config.font || 'medium',
|
||||
show_label_background: this.config.show_label_background ?? true,
|
||||
screensaver_enabled: this.config.screensaver?.enabled || false,
|
||||
screensaver_idle: this.config.screensaver?.idle_seconds || 30,
|
||||
screensaver_brightness: this.config.screensaver?.brightness || 10,
|
||||
@ -598,6 +599,7 @@ document.addEventListener('alpine:init', () => {
|
||||
}
|
||||
dev.brightness = parseInt(this.settingsForm.brightness)
|
||||
this.config.font = this.settingsForm.font || 'medium'
|
||||
this.config.show_label_background = this.settingsForm.show_label_background
|
||||
this.config.screensaver = {
|
||||
enabled: this.settingsForm.screensaver_enabled,
|
||||
idle_seconds: parseInt(this.settingsForm.screensaver_idle) || 30,
|
||||
|
||||
@ -122,6 +122,10 @@
|
||||
<option value="regular">Regular</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="checkbox-row">
|
||||
<input type="checkbox" id="show-label-bg" x-model="settingsForm.show_label_background">
|
||||
<label for="show-label-bg">Show label background</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Screensaver -->
|
||||
|
||||
2
web.go
2
web.go
@ -404,7 +404,7 @@ func (s *WebServer) handleRender(w http.ResponseWriter, r *http.Request) {
|
||||
kc.Background = bg
|
||||
}
|
||||
|
||||
img := RenderKeyToImage(kc, keySize)
|
||||
img := RenderKeyToImage(kc, keySize, s.cfg.ShowLabelBackground)
|
||||
|
||||
w.Header().Set("Content-Type", "image/png")
|
||||
w.Header().Set("Cache-Control", "no-cache")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user