-
|
I'm not sure how to get the current theme variant to look up a color. I'm trying to set the color of a background canvas rectangle in a stack container, since the foreground content has a transparent background and I don't want to see the content behind the stack container. The theme API for querying colors requires a variant. I'm not overriding the theme in any way, so I want to just get the current variant. What is the correct/intended method to get the current theme variant? // Theme defines the method to look up colors, sizes and fonts that make up a Fyne theme.
//
// Since: 2.0
type Theme interface {
Color(ThemeColorName, ThemeVariant) color.Color // What I'm trying to use
Font(TextStyle) Resource
Icon(ThemeIconName) Resource
Size(ThemeSizeName) float32
}What I'm doing now doesn't seem right. It looks like there are light and dark constants for this value, but not a "Current." // What I'm doing right now
respBG := canvas.NewRectangle(theme.Current().Color(theme.ColorNameBackground, 0 /* maybe isn't used? */))The builtin theme seems to potentially disregard this parameter anyway, so I'm not sure what to use to reference the current theme. // theme.go
// Existing constants
// Keep in mind to add new constants to the tests at test/theme.go.
const (
// VariantDark is the version of a theme that satisfies a user preference for a dark look.
//
// Since: 2.0
VariantDark = internaltheme.VariantDark
// VariantLight is the version of a theme that satisfies a user preference for a light look.
//
// Since: 2.0
VariantLight = internaltheme.VariantLight
)
/* ... */
// Color implementation of the builtinTheme, where it looks like the parameter is overridden.
func (t *builtinTheme) Color(n fyne.ThemeColorName, v fyne.ThemeVariant) color.Color {
if t.variant != internaltheme.VariantNameUserPreference {
v = t.variant
}
/* ... */ |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 10 replies
-
|
It's |
Beta Was this translation helpful? Give feedback.
-
|
I think you might have been asking the wrong question. |
Beta Was this translation helpful? Give feedback.
-
|
One additional item to consider is that the app theme is not necessarily what applies to a single widget. Since 2.6 we have a The |
Beta Was this translation helpful? Give feedback.
It's
fyne.CurrentApp().Settings().ThemeVariant()IIRC. Perhaps adding atheme.CurrentVariant()as an alias would be a worthwhile feature request