feat(tracker/gioui): add theme.yml which contains all styling

This commit is contained in:
5684185+vsariola@users.noreply.github.com
2025-05-01 23:49:07 +03:00
parent 8245fbda24
commit afb1fee4ed
22 changed files with 740 additions and 636 deletions

View File

@ -1,82 +1,143 @@
package gioui
import (
_ "embed"
"fmt"
"image/color"
"gioui.org/font/gofont"
"gioui.org/text"
"gioui.org/unit"
"gioui.org/widget"
"gioui.org/widget/material"
"golang.org/x/exp/shiny/materialdesign/icons"
"gopkg.in/yaml.v2"
)
var fontCollection []text.FontFace = gofont.Collection()
type Theme struct {
Define any // this is just needed for yaml.UnmarshalStrict, so we can have "defines" in the yaml
Material material.Theme
Button struct {
Filled ButtonStyle
Text ButtonStyle
Disabled ButtonStyle
Menu ButtonStyle
}
Oscilloscope OscilloscopeStyle
NumericUpDown NumericUpDownStyle
DialogTitle LabelStyle
DialogText LabelStyle
SongPanel struct {
RowHeader LabelStyle
RowValue LabelStyle
Expander LabelStyle
Version LabelStyle
ErrorColor color.NRGBA
Bg color.NRGBA
}
Alert struct {
Warning PopupAlertStyle
Error PopupAlertStyle
Info PopupAlertStyle
}
NoteEditor struct {
TrackTitle LabelStyle
OrderRow LabelStyle
PatternRow LabelStyle
Note LabelStyle
PatternNo LabelStyle
Unique LabelStyle
Loop color.NRGBA
Header LabelStyle
Play color.NRGBA
OneBeat color.NRGBA
TwoBeat color.NRGBA
}
Dialog struct {
Bg color.NRGBA
Title LabelStyle
Text LabelStyle
}
OrderEditor struct {
TrackTitle LabelStyle
RowTitle LabelStyle
Cell LabelStyle
Loop color.NRGBA
CellBg color.NRGBA
Play color.NRGBA
}
Menu struct {
Text LabelStyle
ShortCut color.NRGBA
Hover color.NRGBA
Disabled color.NRGBA
}
InstrumentEditor struct {
Octave LabelStyle
Voices LabelStyle
InstrumentComment EditorStyle
UnitComment EditorStyle
InstrumentList struct {
Number LabelStyle
Name EditorStyle
NameMuted EditorStyle
ScrollBar ScrollBarStyle
}
UnitList struct {
Name EditorStyle
NameDisabled EditorStyle
Comment LabelStyle
Stack LabelStyle
Disabled LabelStyle
Warning color.NRGBA
Error color.NRGBA
}
}
UnitEditor struct {
Hint LabelStyle
Chooser LabelStyle
ParameterName LabelStyle
InvalidParam color.NRGBA
SendTarget color.NRGBA
}
Cursor CursorStyle
Selection CursorStyle
Tooltip struct {
Color color.NRGBA
Bg color.NRGBA
}
Popup struct {
Bg color.NRGBA
Shadow color.NRGBA
}
ScrollBar ScrollBarStyle
}
var white = color.NRGBA{R: 255, G: 255, B: 255, A: 255}
var black = color.NRGBA{R: 0, G: 0, B: 0, A: 255}
var transparent = color.NRGBA{A: 0}
type CursorStyle struct {
Active color.NRGBA
ActiveAlt color.NRGBA // alternative color for the cursor, used e.g. when the midi input is active
Inactive color.NRGBA
}
var primaryColor = color.NRGBA{R: 206, G: 147, B: 216, A: 255}
var secondaryColor = color.NRGBA{R: 128, G: 222, B: 234, A: 255}
//go:embed theme.yml
var defaultTheme []byte
var highEmphasisTextColor = color.NRGBA{R: 222, G: 222, B: 222, A: 222}
var mediumEmphasisTextColor = color.NRGBA{R: 153, G: 153, B: 153, A: 153}
var disabledTextColor = color.NRGBA{R: 255, G: 255, B: 255, A: 97}
func NewTheme() *Theme {
var theme Theme
err := yaml.UnmarshalStrict(defaultTheme, &theme)
if err != nil {
panic(fmt.Errorf("failed to default theme: %w", err))
}
ReadCustomConfigYml("theme.yml", &theme)
theme.Material.Shaper = &text.Shaper{}
theme.Material.Icon.CheckBoxChecked = must(widget.NewIcon(icons.ToggleCheckBox))
theme.Material.Icon.CheckBoxUnchecked = must(widget.NewIcon(icons.ToggleCheckBoxOutlineBlank))
theme.Material.Icon.RadioChecked = must(widget.NewIcon(icons.ToggleRadioButtonChecked))
theme.Material.Icon.RadioUnchecked = must(widget.NewIcon(icons.ToggleRadioButtonUnchecked))
return &theme
}
var backgroundColor = color.NRGBA{R: 18, G: 18, B: 18, A: 255}
var labelDefaultFont = fontCollection[6].Font
var labelDefaultFontSize = unit.Sp(18)
var rowMarkerPatternTextColor = secondaryColor
var rowMarkerRowTextColor = mediumEmphasisTextColor
var trackerFont = fontCollection[6].Font
var trackerFontSize = unit.Sp(16)
var trackerInactiveTextColor = highEmphasisTextColor
var trackerActiveTextColor = color.NRGBA{R: 255, G: 255, B: 130, A: 255}
var trackerPlayColor = color.NRGBA{R: 55, G: 55, B: 61, A: 255}
var trackerPatMarker = primaryColor
var oneBeatHighlight = color.NRGBA{R: 31, G: 37, B: 38, A: 255}
var twoBeatHighlight = color.NRGBA{R: 31, G: 51, B: 53, A: 255}
var patternPlayColor = color.NRGBA{R: 55, G: 55, B: 61, A: 255}
var patternTextColor = primaryColor
var patternCellColor = color.NRGBA{R: 255, G: 255, B: 255, A: 3}
var loopMarkerColor = color.NRGBA{R: 252, G: 186, B: 3, A: 255}
var instrumentHoverColor = color.NRGBA{R: 30, G: 31, B: 38, A: 255}
var instrumentNameHintColor = color.NRGBA{R: 200, G: 200, B: 200, A: 255}
var songSurfaceColor = color.NRGBA{R: 24, G: 24, B: 24, A: 255}
var popupSurfaceColor = color.NRGBA{R: 50, G: 50, B: 51, A: 255}
var popupShadowColor = color.NRGBA{R: 0, G: 0, B: 0, A: 192}
var dragListSelectedColor = color.NRGBA{R: 55, G: 55, B: 61, A: 255}
var dragListHoverColor = color.NRGBA{R: 42, G: 45, B: 61, A: 255}
var inactiveLightSurfaceColor = color.NRGBA{R: 37, G: 37, B: 38, A: 255}
var activeLightSurfaceColor = color.NRGBA{R: 45, G: 45, B: 45, A: 255}
var numberInputBgColor = color.NRGBA{R: 255, G: 255, B: 255, A: 3}
var cursorColor = color.NRGBA{R: 100, G: 140, B: 255, A: 48}
var selectionColor = color.NRGBA{R: 100, G: 140, B: 255, A: 12}
var inactiveSelectionColor = color.NRGBA{R: 140, G: 140, B: 140, A: 16}
var cursorForTrackMidiInColor = color.NRGBA{R: 255, G: 100, B: 140, A: 48}
var cursorNeighborForTrackMidiInColor = color.NRGBA{R: 255, G: 100, B: 140, A: 24}
var errorColor = color.NRGBA{R: 207, G: 102, B: 121, A: 255}
var menuHoverColor = color.NRGBA{R: 30, G: 31, B: 38, A: 255}
var scrollBarColor = color.NRGBA{R: 255, G: 255, B: 255, A: 32}
var warningColor = color.NRGBA{R: 251, G: 192, B: 45, A: 255}
var dialogBgColor = color.NRGBA{R: 0, G: 0, B: 0, A: 224}
var paramIsSendTargetColor = color.NRGBA{R: 120, G: 120, B: 210, A: 255}
var paramValueInvalidColor = color.NRGBA{R: 120, G: 120, B: 120, A: 190}
var oscilloscopeLimitColor = color.NRGBA{R: 255, G: 255, B: 255, A: 8}
var oscilloscopeCursorColor = color.NRGBA{R: 252, G: 186, B: 3, A: 255}
func must[T any](ic T, err error) T {
if err != nil {
panic(err)
}
return ic
}