Skip to content

Commit

Permalink
[theme] export .onPrimaryColorNamed() to enable preview in fyne_settings
Browse files Browse the repository at this point in the history
  • Loading branch information
toaster committed Apr 30, 2024
1 parent e6b87b9 commit 06342d9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
5 changes: 4 additions & 1 deletion cmd/fyne_settings/settings/appearance.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,11 @@ func (p *previewTheme) Color(n fyne.ThemeColorName, _ fyne.ThemeVariant) color.C
variant = theme.VariantLight
}

if n == theme.ColorNamePrimary {
switch n {
case theme.ColorNamePrimary:
return theme.PrimaryColorNamed(p.s.fyneSettings.PrimaryColor)
case theme.ColorNameOnPrimary:
return theme.OnPrimaryColorNamed(p.s.fyneSettings.PrimaryColor)
}

return p.t.Color(n, variant)
Expand Down
49 changes: 26 additions & 23 deletions theme/color.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,32 @@ func OnPrimaryColor() color.Color {
return safeColorLookup(ColorNameOnPrimary, currentVariant())
}

// OnPrimaryColorNamed returns a theme specific color used for text and icons against the named primary color.
//
// Since: 2.5
func OnPrimaryColorNamed(name string) color.Color {
switch name {
case ColorRed:
return backgroundColorLight
case ColorOrange:
return backgroundColorDark
case ColorYellow:
return backgroundColorDark
case ColorGreen:
return backgroundColorDark
case ColorPurple:
return backgroundColorLight
case ColorBrown:
return backgroundColorLight
case ColorGray:
return backgroundColorDark
}

// We return the “on” value for ColorBlue for every other value.
// There is no need to have it in the switch above.
return backgroundColorLight
}

// OverlayBackgroundColor returns the theme's background color for overlays like dialogs.
//
// Since: 2.3
Expand Down Expand Up @@ -370,29 +396,6 @@ func WarningColor() color.Color {
return safeColorLookup(ColorNameWarning, currentVariant())
}

func onPrimaryColorNamed(name string) color.Color {
switch name {
case ColorRed:
return backgroundColorLight
case ColorOrange:
return backgroundColorDark
case ColorYellow:
return backgroundColorDark
case ColorGreen:
return backgroundColorDark
case ColorPurple:
return backgroundColorLight
case ColorBrown:
return backgroundColorLight
case ColorGray:
return backgroundColorDark
}

// We return the “on” value for ColorBlue for every other value.
// There is no need to have it in the switch above.
return backgroundColorLight
}

func safeColorLookup(n fyne.ThemeColorName, v fyne.ThemeVariant) color.Color {
col := Current().Color(n, v)
if col == nil {
Expand Down
2 changes: 1 addition & 1 deletion theme/theme.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (t *builtinTheme) Color(n fyne.ThemeColorName, v fyne.ThemeVariant) color.C
if n == ColorNamePrimary || n == ColorNameHyperlink {
return PrimaryColorNamed(primary)
} else if n == ColorNameOnPrimary {
return onPrimaryColorNamed(primary)
return OnPrimaryColorNamed(primary)
} else if n == ColorNameFocus {
return focusColorNamed(primary)
} else if n == ColorNameSelection {
Expand Down

0 comments on commit 06342d9

Please sign in to comment.