Documentation
¶
Overview ¶
Package theme provides GTK CSS styling for UI components.
Package theme provides GTK CSS styling for UI components.
Index ¶
- func Coalesce(values ...string) string
- func DetectSystemDarkMode() bool
- func FontCSSVars(fonts FontConfig) string
- func GenerateCSS(p Palette) string
- func GenerateCSSWithScale(p Palette, scale float64) string
- func GenerateCSSWithScaleAndFonts(p Palette, scale float64, fonts FontConfig) string
- func GenerateFindHighlightCSS(p Palette) string
- func HexToRGBA(hex string) (r, g, b, a float32)
- func ResolveColorScheme(configScheme string) bool
- func ValidateHexColor(color string) error
- type FontConfig
- type Manager
- func (m *Manager) ApplyToDisplay(ctx context.Context, display *gdk.Display)
- func (m *Manager) GetBackgroundRGBA() (r, g, b, a float32)
- func (m *Manager) GetCurrentPalette() Palette
- func (m *Manager) GetDarkPalette() Palette
- func (m *Manager) GetLightPalette() Palette
- func (m *Manager) GetWebUIThemeCSS() string
- func (m *Manager) PrefersDark() bool
- func (m *Manager) SetColorScheme(ctx context.Context, scheme string, display *gdk.Display)
- func (m *Manager) UpdateFromConfig(ctx context.Context, cfg *config.Config, display *gdk.Display)
- type Palette
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DetectSystemDarkMode ¶
func DetectSystemDarkMode() bool
DetectSystemDarkMode checks if the system prefers dark mode. It checks multiple sources in order of preference: 1. GTK_THEME environment variable (contains "dark") 2. GNOME gsettings color-scheme (prefer-dark/prefer-light) 3. GTK Settings gtk-application-prefer-dark-theme property Returns true if dark mode is preferred.
func FontCSSVars ¶
func FontCSSVars(fonts FontConfig) string
FontCSSVars generates CSS custom properties for fonts.
func GenerateCSS ¶
GenerateCSS creates GTK4 CSS using the provided palette with default scale.
func GenerateCSSWithScale ¶
GenerateCSSWithScale creates GTK4 CSS using the provided palette and UI scale factor. Scale affects font sizes and widget padding/margins proportionally.
func GenerateCSSWithScaleAndFonts ¶
func GenerateCSSWithScaleAndFonts(p Palette, scale float64, fonts FontConfig) string
GenerateCSSWithScaleAndFonts creates GTK4 CSS using the provided palette, UI scale factor and fonts. Scale affects font sizes and widget padding/margins proportionally.
func GenerateFindHighlightCSS ¶
GenerateFindHighlightCSS builds CSS to style find-in-page matches using the accent color.
func HexToRGBA ¶ added in v0.20.1
HexToRGBA converts a hex color string to RGBA float32 values (0.0-1.0). Supports #RGB, #RRGGBB, and #RRGGBBAA formats. Returns opaque black (0,0,0,1) if parsing fails.
func ResolveColorScheme ¶
ResolveColorScheme determines the effective dark mode preference. It takes the config value ("prefer-dark", "prefer-light", "default") and resolves "default" to the system preference.
func ValidateHexColor ¶
ValidateHexColor checks if a string is a valid hex color.
Types ¶
type FontConfig ¶
FontConfig holds font settings for CSS generation.
func DefaultFontConfig ¶
func DefaultFontConfig() FontConfig
DefaultFontConfig returns safe font fallbacks.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles theme state and CSS application.
func NewManager ¶
NewManager creates a new theme manager from configuration.
func (*Manager) ApplyToDisplay ¶
ApplyToDisplay loads the theme CSS into the display.
func (*Manager) GetBackgroundRGBA ¶ added in v0.20.1
GetBackgroundRGBA returns the current theme's background color as RGBA float32 values. Used to set WebView background color to eliminate white flash during loading.
func (*Manager) GetCurrentPalette ¶
GetCurrentPalette returns the active palette based on current scheme.
func (*Manager) GetDarkPalette ¶
GetDarkPalette returns the dark theme palette.
func (*Manager) GetLightPalette ¶
GetLightPalette returns the light theme palette.
func (*Manager) GetWebUIThemeCSS ¶
GetWebUIThemeCSS returns CSS text that defines both light and dark variables. WebUI uses `:root` for light and `.dark` overrides for dark.
func (*Manager) PrefersDark ¶
PrefersDark returns true if dark mode is active.
func (*Manager) SetColorScheme ¶
SetColorScheme changes the active color scheme at runtime.
type Palette ¶
type Palette struct {
Background string // Main background color
Surface string // Elevated surfaces (cards, popups)
SurfaceVariant string // Secondary surfaces
Text string // Primary text color
Muted string // Secondary/disabled text
Accent string // Primary accent color (actions, highlights)
Border string // Border and divider lines
// Semantic status colors (not user-editable, derived defaults)
Success string // Success/positive feedback
Warning string // Warning/caution feedback
Destructive string // Error/destructive actions
}
Palette holds semantic color tokens for theming.
func DefaultDarkPalette ¶
func DefaultDarkPalette() Palette
DefaultDarkPalette returns the default dark theme palette.
func DefaultLightPalette ¶
func DefaultLightPalette() Palette
DefaultLightPalette returns the default light theme palette.
func PaletteFromConfig ¶
func PaletteFromConfig(cfg *config.ColorPalette, isDark bool) Palette
PaletteFromConfig creates a Palette from config values, filling missing values with defaults.
func (Palette) ToWebCSSVars ¶
ToWebCSSVars generates CSS custom properties for web UI (Tailwind compatibility). Maps GTK palette names to Tailwind variable names used in the WebUI homepage.