feat(config): fine-grained style control for border & title (#557)
This commit is contained in:
parent
bc1b3210e3
commit
a0c9ad487d
3 changed files with 42 additions and 21 deletions
|
|
@ -94,19 +94,17 @@ cancel = "Esc"
|
|||
background_color = "default"
|
||||
|
||||
[theme.title]
|
||||
# Title color of non-focused widgets
|
||||
color = "default"
|
||||
# Title color of the focused widget
|
||||
active_color = "green"
|
||||
alignment = "left"
|
||||
style = { foreground = "default" }
|
||||
active_style = { foreground = "green" }
|
||||
|
||||
[theme.border]
|
||||
enabled = true
|
||||
# [top, bottom, left, right]
|
||||
padding = [0, 0, 1, 1]
|
||||
set = "round"
|
||||
color = "default"
|
||||
active_color = "green"
|
||||
style = { foreground = "default" }
|
||||
active_style = { foreground = "green" }
|
||||
|
||||
[theme.guilds_tree]
|
||||
auto_expand_folders = true
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package config
|
|||
|
||||
import (
|
||||
"github.com/ayn2op/tview"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
)
|
||||
|
||||
type BorderSetWrapper struct{ tview.BorderSet }
|
||||
|
|
@ -36,19 +37,46 @@ func (aw *AlignmentWrapper) UnmarshalTOML(v any) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
type StyleWrapper struct{ tcell.Style }
|
||||
|
||||
func (sw *StyleWrapper) UnmarshalTOML(v any) error {
|
||||
m, ok := v.(map[string]any)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
for k, v := range m {
|
||||
s, ok := v.(string)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
switch k {
|
||||
case "foreground":
|
||||
color := tcell.GetColor(s)
|
||||
sw.Style = sw.Foreground(color)
|
||||
case "background":
|
||||
color := tcell.GetColor(s)
|
||||
sw.Style = sw.Background(color)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type (
|
||||
BorderTheme struct {
|
||||
Enabled bool `toml:"enabled"`
|
||||
Padding [4]int `toml:"padding"`
|
||||
Set BorderSetWrapper `toml:"set"`
|
||||
|
||||
Color string `toml:"color"`
|
||||
ActiveColor string `toml:"active_color"`
|
||||
Style StyleWrapper `toml:"style"`
|
||||
ActiveStyle StyleWrapper `toml:"active_style"`
|
||||
}
|
||||
|
||||
TitleTheme struct {
|
||||
Color string `toml:"color"`
|
||||
ActiveColor string `toml:"active_color"`
|
||||
Style StyleWrapper `toml:"style"`
|
||||
ActiveStyle StyleWrapper `toml:"active_style"`
|
||||
Alignment AlignmentWrapper `toml:"alignment"`
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package ui
|
|||
import (
|
||||
"github.com/ayn2op/discordo/internal/config"
|
||||
"github.com/ayn2op/tview"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
)
|
||||
|
||||
func NewConfiguredBox(box *tview.Box, cfg *config.Theme) *tview.Box {
|
||||
|
|
@ -11,22 +10,18 @@ func NewConfiguredBox(box *tview.Box, cfg *config.Theme) *tview.Box {
|
|||
t := cfg.Title
|
||||
p := b.Padding
|
||||
box.
|
||||
SetBorderStyle(b.Style.Style).
|
||||
SetBorderSet(b.Set.BorderSet).
|
||||
SetBorderPadding(p[0], p[1], p[2], p[3]).
|
||||
SetTitleStyle(t.Style.Style).
|
||||
SetTitleAlignment(t.Alignment.Alignment).
|
||||
SetFocusFunc(func() {
|
||||
borderColor := tcell.GetColor(b.ActiveColor)
|
||||
box.SetBorderStyle(tcell.StyleDefault.Foreground(borderColor))
|
||||
|
||||
titleColor := tcell.GetColor(t.ActiveColor)
|
||||
box.SetTitleStyle(tcell.StyleDefault.Foreground(titleColor))
|
||||
box.SetBorderStyle(b.ActiveStyle.Style)
|
||||
box.SetTitleStyle(t.ActiveStyle.Style)
|
||||
}).
|
||||
SetBlurFunc(func() {
|
||||
borderColor := tcell.GetColor(b.Color)
|
||||
box.SetBorderStyle(tcell.StyleDefault.Foreground(borderColor))
|
||||
|
||||
titleColor := tcell.GetColor(t.Color)
|
||||
box.SetTitleStyle(tcell.StyleDefault.Foreground(titleColor))
|
||||
box.SetBorderStyle(b.Style.Style)
|
||||
box.SetTitleStyle(t.Style.Style)
|
||||
})
|
||||
|
||||
if b.Enabled {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue