theme
Package theme provides theming support for the Drift framework.
func IsCupertino
func IsCupertino(ctx core.BuildContext) bool
IsCupertino returns true if a CupertinoTheme is active in the widget tree.
func IsMaterial
func IsMaterial(ctx core.BuildContext) bool
IsMaterial returns true if no CupertinoTheme is active (Material is the default).
func UseCupertinoTheme
func UseCupertinoTheme(ctx core.BuildContext) (*CupertinoThemeData, CupertinoColors, CupertinoTextThemeData)
UseCupertinoTheme returns all Cupertino theme components in a single call.
func UseTheme
func UseTheme(ctx core.BuildContext) (*ThemeData, ColorScheme, TextTheme)
UseTheme returns all theme components in a single call. This replaces the common pattern:
themeData := theme.ThemeOf(ctx)
colors := themeData.ColorScheme
textTheme := themeData.TextTheme
With:
_, colors, textTheme := theme.UseTheme(ctx)
Example:
This example shows how to get all theme components at once using UseTheme. This is the recommended approach when you need multiple theme values.
package main
import (
"github.com/go-drift/drift/pkg/theme"
)
func main() {
// In a widget's Build method:
// func (w MyWidget) Build(ctx core.BuildContext) core.Widget {
// themeData, colors, textTheme := theme.UseTheme(ctx)
//
// return widgets.Column{
// ChildrenWidgets: []core.Widget{
// widgets.Text{
// Content: "Headline",
// Style: textTheme.HeadlineMedium,
// },
// widgets.Container{
// Color: colors.Surface,
// ChildWidget: widgets.Text{
// Content: "Body text",
// Style: textTheme.BodyLarge,
// },
// },
// },
// }
// }
_ = theme.DefaultLightTheme()
}
type AppTheme
AppTheme provides unified theme data via InheritedWidget.
type AppTheme struct {
Data *AppThemeData
ChildWidget core.Widget
}
func (AppTheme) Child
func (a AppTheme) Child() core.Widget
Child returns the child widget.
func (AppTheme) CreateElement
func (a AppTheme) CreateElement() core.Element
CreateElement returns an InheritedElement for this AppTheme.
func (AppTheme) Key
func (a AppTheme) Key() any
Key returns nil (no key).
func (AppTheme) UpdateShouldNotify
func (a AppTheme) UpdateShouldNotify(oldWidget core.InheritedWidget) bool
UpdateShouldNotify returns true if the theme data has changed.
func (AppTheme) UpdateShouldNotifyDependent
func (a AppTheme) UpdateShouldNotifyDependent(oldWidget core.InheritedWidget, aspects map[any]struct{}) bool
UpdateShouldNotifyDependent returns true for any aspects since AppTheme doesn't support granular aspect tracking yet.
type AppThemeData
AppThemeData holds both Material and Cupertino theme data. Brightness is derived from Material.Brightness to avoid divergence.
type AppThemeData struct {
Platform TargetPlatform
Material *ThemeData
Cupertino *CupertinoThemeData
}
func AppThemeMaybeOf
func AppThemeMaybeOf(ctx core.BuildContext) *AppThemeData
AppThemeMaybeOf returns the nearest AppThemeData, or nil if not found. Returns nil if no AppTheme is found or if Data is nil.
func AppThemeOf
func AppThemeOf(ctx core.BuildContext) *AppThemeData
AppThemeOf returns the nearest AppThemeData. Returns a cached default if no AppTheme is found or if Data is nil.
func NewAppThemeData
func NewAppThemeData(platform TargetPlatform, brightness Brightness) *AppThemeData
NewAppThemeData creates theme data for the given platform and brightness.
func (*AppThemeData) Brightness
func (a *AppThemeData) Brightness() Brightness
Brightness returns the theme brightness (derived from Material theme).
type Brightness
Brightness indicates whether a theme is light or dark.
type Brightness int
const (
// BrightnessLight is a light theme with dark text on light backgrounds.
BrightnessLight Brightness = iota
// BrightnessDark is a dark theme with light text on dark backgrounds.
BrightnessDark
)
type ButtonThemeData
ButtonThemeData defines default styling for Button widgets.
type ButtonThemeData struct {
// BackgroundColor is the default button background.
BackgroundColor rendering.Color
// ForegroundColor is the default text/icon color.
ForegroundColor rendering.Color
// DisabledBackgroundColor is the background when disabled.
DisabledBackgroundColor rendering.Color
// DisabledForegroundColor is the text color when disabled.
DisabledForegroundColor rendering.Color
// Padding is the default button padding.
Padding layout.EdgeInsets
// BorderRadius is the default corner radius.
BorderRadius float64
// FontSize is the default label font size.
FontSize float64
}
func DefaultButtonTheme
func DefaultButtonTheme(colors ColorScheme) ButtonThemeData
DefaultButtonTheme returns ButtonThemeData derived from a ColorScheme.
type CheckboxThemeData
CheckboxThemeData defines default styling for Checkbox widgets.
type CheckboxThemeData struct {
// ActiveColor is the fill color when checked.
ActiveColor rendering.Color
// CheckColor is the checkmark color.
CheckColor rendering.Color
// BorderColor is the outline color when unchecked.
BorderColor rendering.Color
// BackgroundColor is the fill color when unchecked.
BackgroundColor rendering.Color
// DisabledActiveColor is the fill color when checked and disabled.
DisabledActiveColor rendering.Color
// DisabledCheckColor is the checkmark color when disabled.
DisabledCheckColor rendering.Color
// Size is the default checkbox size.
Size float64
// BorderRadius is the default corner radius.
BorderRadius float64
}
func DefaultCheckboxTheme
func DefaultCheckboxTheme(colors ColorScheme) CheckboxThemeData
DefaultCheckboxTheme returns CheckboxThemeData derived from a ColorScheme.
type ColorScheme
ColorScheme defines the color palette for a theme. Based on Material Design 3 color system with full 45-color support.
type ColorScheme struct {
// Primary is the main brand color.
Primary rendering.Color
// OnPrimary is the color for text/icons on primary.
OnPrimary rendering.Color
// PrimaryContainer is a tonal container for primary.
PrimaryContainer rendering.Color
// OnPrimaryContainer is the color for text/icons on primary container.
OnPrimaryContainer rendering.Color
// Secondary is a supporting brand color.
Secondary rendering.Color
// OnSecondary is the color for text/icons on secondary.
OnSecondary rendering.Color
// SecondaryContainer is a tonal container for secondary.
SecondaryContainer rendering.Color
// OnSecondaryContainer is the color for text/icons on secondary container.
OnSecondaryContainer rendering.Color
// Tertiary is an accent color for contrast.
Tertiary rendering.Color
// OnTertiary is the color for text/icons on tertiary.
OnTertiary rendering.Color
// TertiaryContainer is a tonal container for tertiary.
TertiaryContainer rendering.Color
// OnTertiaryContainer is the color for text/icons on tertiary container.
OnTertiaryContainer rendering.Color
// Surface is the color for cards, sheets, menus.
Surface rendering.Color
// OnSurface is the color for text/icons on surface.
OnSurface rendering.Color
// SurfaceVariant is an alternative surface color.
SurfaceVariant rendering.Color
// OnSurfaceVariant is the color for text/icons on surface variant.
OnSurfaceVariant rendering.Color
// SurfaceDim is a dimmed surface for less emphasis.
SurfaceDim rendering.Color
// SurfaceBright is a bright surface for more emphasis.
SurfaceBright rendering.Color
// SurfaceContainerLowest is the lowest emphasis container surface.
SurfaceContainerLowest rendering.Color
// SurfaceContainerLow is a low emphasis container surface.
SurfaceContainerLow rendering.Color
// SurfaceContainer is the default container surface.
SurfaceContainer rendering.Color
// SurfaceContainerHigh is a high emphasis container surface.
SurfaceContainerHigh rendering.Color
// SurfaceContainerHighest is the highest emphasis container surface.
SurfaceContainerHighest rendering.Color
// Background is the app background color.
Background rendering.Color
// OnBackground is the color for text/icons on background.
OnBackground rendering.Color
// Error is the color for error states.
Error rendering.Color
// OnError is the color for text/icons on error.
OnError rendering.Color
// ErrorContainer is a tonal container for error.
ErrorContainer rendering.Color
// OnErrorContainer is the color for text/icons on error container.
OnErrorContainer rendering.Color
// Outline is the color for borders and dividers.
Outline rendering.Color
// OutlineVariant is a subtle outline for decorative elements.
OutlineVariant rendering.Color
// Shadow is the color for elevation shadows.
Shadow rendering.Color
// Scrim is the color for modal barriers.
Scrim rendering.Color
// InverseSurface is the surface color for inverse contexts.
InverseSurface rendering.Color
// OnInverseSurface is the color for text/icons on inverse surface.
OnInverseSurface rendering.Color
// InversePrimary is the primary color for inverse contexts.
InversePrimary rendering.Color
// SurfaceTint is the tint color applied to surfaces.
SurfaceTint rendering.Color
// Brightness indicates if this is a light or dark scheme.
Brightness Brightness
}
func ColorsOf
func ColorsOf(ctx core.BuildContext) ColorScheme
ColorsOf returns the ColorScheme from the nearest Theme ancestor. If no Theme is found, returns the default light color scheme.
Example:
This example shows how to access theme colors in a widget's Build method. In a real widget, BuildContext is provided by the framework.
package main
import (
"github.com/go-drift/drift/pkg/rendering"
"github.com/go-drift/drift/pkg/theme"
"github.com/go-drift/drift/pkg/widgets"
)
func main() {
// In a widget's Build method:
// func (w MyWidget) Build(ctx core.BuildContext) core.Widget {
// colors := theme.ColorsOf(ctx)
// return widgets.Container{
// Color: colors.Primary,
// ChildWidget: widgets.Text{
// Content: "Themed text",
// Style: rendering.TextStyle{Color: colors.OnPrimary},
// },
// }
// }
// Direct usage (outside of widget context) for demonstration:
colors := theme.LightColorScheme()
_ = widgets.Container{
Color: colors.Primary,
ChildWidget: widgets.Text{
Content: "Themed text",
Style: rendering.TextStyle{Color: colors.OnPrimary},
},
}
}
func DarkColorScheme
func DarkColorScheme() ColorScheme
DarkColorScheme returns the default dark color scheme. Colors are based on Material Design 3 baseline purple theme.
func LightColorScheme
func LightColorScheme() ColorScheme
LightColorScheme returns the default light color scheme. Colors are based on Material Design 3 baseline purple theme.
type CupertinoColors
CupertinoColors defines the iOS-style color palette. Based on Apple's Human Interface Guidelines system colors.
type CupertinoColors struct {
// System colors - vibrant, accessible colors
SystemBlue rendering.Color
SystemGreen rendering.Color
SystemIndigo rendering.Color
SystemOrange rendering.Color
SystemPink rendering.Color
SystemPurple rendering.Color
SystemRed rendering.Color
SystemTeal rendering.Color
SystemYellow rendering.Color
// Gray colors - semantic grays for various uses
SystemGray rendering.Color
SystemGray2 rendering.Color
SystemGray3 rendering.Color
SystemGray4 rendering.Color
SystemGray5 rendering.Color
SystemGray6 rendering.Color
// Background colors - for view hierarchies
SystemBackground rendering.Color
SecondarySystemBackground rendering.Color
TertiarySystemBackground rendering.Color
// Grouped background colors - for grouped content
SystemGroupedBackground rendering.Color
SecondarySystemGroupedBackground rendering.Color
TertiarySystemGroupedBackground rendering.Color
// Label colors - for text content
Label rendering.Color
SecondaryLabel rendering.Color
TertiaryLabel rendering.Color
QuaternaryLabel rendering.Color
// Fill colors - for shapes and controls
SystemFill rendering.Color
SecondarySystemFill rendering.Color
TertiarySystemFill rendering.Color
QuaternarySystemFill rendering.Color
// Separator colors - for dividers
Separator rendering.Color
OpaqueSeparator rendering.Color
// Link color
Link rendering.Color
// Placeholder text color
PlaceholderText rendering.Color
}
func CupertinoColorsOf
func CupertinoColorsOf(ctx core.BuildContext) CupertinoColors
CupertinoColorsOf returns the CupertinoColors from the nearest CupertinoTheme ancestor. If no CupertinoTheme is found, returns the default light colors.
func DarkCupertinoColors
func DarkCupertinoColors() CupertinoColors
DarkCupertinoColors returns the iOS dark mode color palette.
func LightCupertinoColors
func LightCupertinoColors() CupertinoColors
LightCupertinoColors returns the iOS light mode color palette.
type CupertinoTextThemeData
CupertinoTextThemeData defines text styles for iOS-style interfaces. Based on Apple's Human Interface Guidelines typography.
type CupertinoTextThemeData struct {
// TextStyle is the default body text style.
TextStyle rendering.TextStyle
// ActionTextStyle is for interactive text elements.
ActionTextStyle rendering.TextStyle
// NavTitleTextStyle is for navigation bar titles.
NavTitleTextStyle rendering.TextStyle
// NavLargeTitleTextStyle is for large navigation bar titles.
NavLargeTitleTextStyle rendering.TextStyle
// TabLabelTextStyle is for tab bar labels.
TabLabelTextStyle rendering.TextStyle
// PickerTextStyle is for picker/wheel items.
PickerTextStyle rendering.TextStyle
// DateTimePickerTextStyle is for date/time picker items.
DateTimePickerTextStyle rendering.TextStyle
// LargeTitleTextStyle is for large prominent text.
LargeTitleTextStyle rendering.TextStyle
// Title1TextStyle is for title level 1.
Title1TextStyle rendering.TextStyle
// Title2TextStyle is for title level 2.
Title2TextStyle rendering.TextStyle
// Title3TextStyle is for title level 3.
Title3TextStyle rendering.TextStyle
// HeadlineTextStyle is for headline text.
HeadlineTextStyle rendering.TextStyle
// SubheadlineTextStyle is for subheadline text.
SubheadlineTextStyle rendering.TextStyle
// BodyTextStyle is for body text.
BodyTextStyle rendering.TextStyle
// CalloutTextStyle is for callout text.
CalloutTextStyle rendering.TextStyle
// FootnoteTextStyle is for footnote text.
FootnoteTextStyle rendering.TextStyle
// Caption1TextStyle is for caption level 1.
Caption1TextStyle rendering.TextStyle
// Caption2TextStyle is for caption level 2.
Caption2TextStyle rendering.TextStyle
}
func CupertinoTextThemeOf
func CupertinoTextThemeOf(ctx core.BuildContext) CupertinoTextThemeData
CupertinoTextThemeOf returns the CupertinoTextThemeData from the nearest CupertinoTheme ancestor. If no CupertinoTheme is found, returns the default text theme.
func DefaultCupertinoTextTheme
func DefaultCupertinoTextTheme(textColor rendering.Color) CupertinoTextThemeData
DefaultCupertinoTextTheme creates a text theme with iOS-style defaults.
type CupertinoTheme
CupertinoTheme provides CupertinoThemeData to descendant widgets via InheritedWidget.
type CupertinoTheme struct {
// Data is the Cupertino theme configuration.
Data *CupertinoThemeData
// ChildWidget is the child widget tree.
ChildWidget core.Widget
}
func (CupertinoTheme) Child
func (t CupertinoTheme) Child() core.Widget
Child returns the child widget.
func (CupertinoTheme) CreateElement
func (t CupertinoTheme) CreateElement() core.Element
CreateElement returns an InheritedElement for this CupertinoTheme.
func (CupertinoTheme) Key
func (t CupertinoTheme) Key() any
Key returns nil (no key).
func (CupertinoTheme) UpdateShouldNotify
func (t CupertinoTheme) UpdateShouldNotify(oldWidget core.InheritedWidget) bool
UpdateShouldNotify returns true if the theme data has changed.
func (CupertinoTheme) UpdateShouldNotifyDependent
func (t CupertinoTheme) UpdateShouldNotifyDependent(oldWidget core.InheritedWidget, aspects map[any]struct{}) bool
UpdateShouldNotifyDependent returns true for any aspects since CupertinoTheme doesn't support granular aspect tracking yet.
type CupertinoThemeData
CupertinoThemeData contains all theme configuration for iOS-style interfaces.
type CupertinoThemeData struct {
// Brightness indicates if this is a light or dark theme.
Brightness Brightness
// PrimaryColor is the primary accent color (defaults to SystemBlue).
PrimaryColor rendering.Color
// PrimaryContrastingColor is used for text/icons on primary color.
PrimaryContrastingColor rendering.Color
// Colors provides the full iOS color palette.
Colors CupertinoColors
// TextTheme provides iOS-style text styles.
TextTheme CupertinoTextThemeData
// BarBackgroundColor is the color for navigation/tab bars.
BarBackgroundColor rendering.Color
// ScaffoldBackgroundColor is the default page background color.
ScaffoldBackgroundColor rendering.Color
}
func CupertinoMaybeOf
func CupertinoMaybeOf(ctx core.BuildContext) *CupertinoThemeData
CupertinoMaybeOf returns the nearest CupertinoThemeData, or nil if not found. When using AppTheme, returns data only if Cupertino mode is active.
func CupertinoThemeOf
func CupertinoThemeOf(ctx core.BuildContext) *CupertinoThemeData
CupertinoThemeOf returns the nearest CupertinoThemeData in the tree. If no CupertinoTheme ancestor is found, returns the default light theme.
func DefaultCupertinoDarkTheme
func DefaultCupertinoDarkTheme() *CupertinoThemeData
DefaultCupertinoDarkTheme returns the default iOS dark theme.
func DefaultCupertinoLightTheme
func DefaultCupertinoLightTheme() *CupertinoThemeData
DefaultCupertinoLightTheme returns the default iOS light theme.
func (*CupertinoThemeData) CopyWith
func (t *CupertinoThemeData) CopyWith(brightness *Brightness, primaryColor *rendering.Color, primaryContrastingColor *rendering.Color, colors *CupertinoColors, textTheme *CupertinoTextThemeData, barBackgroundColor *rendering.Color, scaffoldBackgroundColor *rendering.Color) *CupertinoThemeData
CopyWith returns a new CupertinoThemeData with the specified fields overridden.
func (*CupertinoThemeData) ResolveFrom
func (t *CupertinoThemeData) ResolveFrom(brightness Brightness) *CupertinoThemeData
ResolveFrom creates a CupertinoThemeData by resolving colors for the given brightness.
type DropdownThemeData
DropdownThemeData defines default styling for Dropdown widgets.
type DropdownThemeData struct {
// BackgroundColor is the trigger background.
BackgroundColor rendering.Color
// BorderColor is the trigger border color.
BorderColor rendering.Color
// MenuBackgroundColor is the dropdown menu background.
MenuBackgroundColor rendering.Color
// MenuBorderColor is the dropdown menu border color.
MenuBorderColor rendering.Color
// SelectedItemColor is the background for the selected item.
SelectedItemColor rendering.Color
// TextColor is the default text color.
TextColor rendering.Color
// DisabledTextColor is the text color when disabled.
DisabledTextColor rendering.Color
// BorderRadius is the default corner radius.
BorderRadius float64
// ItemPadding is the default padding for menu items.
ItemPadding layout.EdgeInsets
// Height is the default trigger/item height.
Height float64
}
func DefaultDropdownTheme
func DefaultDropdownTheme(colors ColorScheme) DropdownThemeData
DefaultDropdownTheme returns DropdownThemeData derived from a ColorScheme.
type RadioThemeData
RadioThemeData defines default styling for Radio widgets.
type RadioThemeData struct {
// ActiveColor is the fill color when selected.
ActiveColor rendering.Color
// InactiveColor is the border color when unselected.
InactiveColor rendering.Color
// BackgroundColor is the fill color when unselected.
BackgroundColor rendering.Color
// DisabledActiveColor is the fill color when selected and disabled.
DisabledActiveColor rendering.Color
// DisabledInactiveColor is the border color when disabled.
DisabledInactiveColor rendering.Color
// Size is the default radio diameter.
Size float64
}
func DefaultRadioTheme
func DefaultRadioTheme(colors ColorScheme) RadioThemeData
DefaultRadioTheme returns RadioThemeData derived from a ColorScheme.
type SwitchThemeData
SwitchThemeData defines default styling for Switch widgets.
type SwitchThemeData struct {
// ActiveTrackColor is the track color when on.
ActiveTrackColor rendering.Color
// InactiveTrackColor is the track color when off.
InactiveTrackColor rendering.Color
// ThumbColor is the thumb fill color.
ThumbColor rendering.Color
// DisabledActiveTrackColor is the track color when on and disabled.
DisabledActiveTrackColor rendering.Color
// DisabledInactiveTrackColor is the track color when off and disabled.
DisabledInactiveTrackColor rendering.Color
// DisabledThumbColor is the thumb color when disabled.
DisabledThumbColor rendering.Color
// Width is the default switch width.
Width float64
// Height is the default switch height.
Height float64
}
func DefaultSwitchTheme
func DefaultSwitchTheme(colors ColorScheme) SwitchThemeData
DefaultSwitchTheme returns SwitchThemeData derived from a ColorScheme.
type TabBarThemeData
TabBarThemeData defines default styling for TabBar widgets.
type TabBarThemeData struct {
// BackgroundColor is the tab bar background.
BackgroundColor rendering.Color
// ActiveColor is the color for the selected tab.
ActiveColor rendering.Color
// InactiveColor is the color for unselected tabs.
InactiveColor rendering.Color
// IndicatorColor is the color for the selection indicator.
IndicatorColor rendering.Color
// IndicatorHeight is the height of the selection indicator.
IndicatorHeight float64
// Padding is the default tab item padding.
Padding layout.EdgeInsets
// Height is the default tab bar height.
Height float64
}
func DefaultTabBarTheme
func DefaultTabBarTheme(colors ColorScheme) TabBarThemeData
DefaultTabBarTheme returns TabBarThemeData derived from a ColorScheme.
type TargetPlatform
TargetPlatform identifies the design language/platform style.
type TargetPlatform int
const (
// TargetPlatformMaterial uses Material Design (Android/default).
TargetPlatformMaterial TargetPlatform = iota
// TargetPlatformCupertino uses iOS/Cupertino design.
TargetPlatformCupertino
)
func PlatformOf
func PlatformOf(ctx core.BuildContext) TargetPlatform
PlatformOf returns the target platform based on which theme is active. If a CupertinoTheme is found in the widget tree, returns TargetPlatformCupertino. Otherwise, returns TargetPlatformMaterial.
type TextFieldThemeData
TextFieldThemeData defines default styling for TextField widgets.
type TextFieldThemeData struct {
// BackgroundColor is the field background.
BackgroundColor rendering.Color
// BorderColor is the default border color.
BorderColor rendering.Color
// FocusColor is the border color when focused.
FocusColor rendering.Color
// ErrorColor is the border color when in error state.
ErrorColor rendering.Color
// LabelColor is the label text color.
LabelColor rendering.Color
// TextColor is the input text color.
TextColor rendering.Color
// PlaceholderColor is the placeholder text color.
PlaceholderColor rendering.Color
// Padding is the default inner padding.
Padding layout.EdgeInsets
// BorderRadius is the default corner radius.
BorderRadius float64
// Height is the default field height.
Height float64
}
func DefaultTextFieldTheme
func DefaultTextFieldTheme(colors ColorScheme) TextFieldThemeData
DefaultTextFieldTheme returns TextFieldThemeData derived from a ColorScheme.
type TextTheme
TextTheme defines text styles for various purposes. Based on Material Design 3 type scale.
type TextTheme struct {
// Display styles are for short, important text.
DisplayLarge rendering.TextStyle
DisplayMedium rendering.TextStyle
DisplaySmall rendering.TextStyle
// Headline styles are for high-emphasis text.
HeadlineLarge rendering.TextStyle
HeadlineMedium rendering.TextStyle
HeadlineSmall rendering.TextStyle
// Title styles are for medium-emphasis text.
TitleLarge rendering.TextStyle
TitleMedium rendering.TextStyle
TitleSmall rendering.TextStyle
// Body styles are for long-form text.
BodyLarge rendering.TextStyle
BodyMedium rendering.TextStyle
BodySmall rendering.TextStyle
// Label styles are for small text like buttons.
LabelLarge rendering.TextStyle
LabelMedium rendering.TextStyle
LabelSmall rendering.TextStyle
}
func DefaultTextTheme
func DefaultTextTheme(textColor rendering.Color) TextTheme
DefaultTextTheme creates a TextTheme with default sizes and the given text color.
func TextThemeOf
func TextThemeOf(ctx core.BuildContext) TextTheme
TextThemeOf returns the TextTheme from the nearest Theme ancestor. If no Theme is found, returns the default text theme.
func (TextTheme) Apply
func (t TextTheme) Apply(scale float64) TextTheme
Apply applies a scale factor to all text sizes in the theme.
type Theme
Theme provides ThemeData to descendant widgets via InheritedWidget.
type Theme struct {
// Data is the theme configuration.
Data *ThemeData
// ChildWidget is the child widget tree.
ChildWidget core.Widget
}
Example:
This example shows how to wrap your app with a Theme provider.
package main
import (
"github.com/go-drift/drift/pkg/theme"
"github.com/go-drift/drift/pkg/widgets"
)
func main() {
root := widgets.Center{
ChildWidget: widgets.Text{Content: "Themed App"},
}
// Wrap the root widget with a Theme
themedApp := theme.Theme{
Data: theme.DefaultDarkTheme(),
ChildWidget: root,
}
_ = themedApp
}
func (Theme) Child
func (t Theme) Child() core.Widget
Child returns the child widget.
func (Theme) CreateElement
func (t Theme) CreateElement() core.Element
CreateElement returns an InheritedElement for this Theme.
func (Theme) Key
func (t Theme) Key() any
Key returns nil (no key).
func (Theme) UpdateShouldNotify
func (t Theme) UpdateShouldNotify(oldWidget core.InheritedWidget) bool
UpdateShouldNotify returns true if the theme data has changed.
func (Theme) UpdateShouldNotifyDependent
func (t Theme) UpdateShouldNotifyDependent(oldWidget core.InheritedWidget, aspects map[any]struct{}) bool
UpdateShouldNotifyDependent returns true for any aspects since Theme doesn't support granular aspect tracking yet.
type ThemeData
ThemeData contains all theme configuration for an application.
type ThemeData struct {
// ColorScheme defines the color palette.
ColorScheme ColorScheme
// TextTheme defines text styles.
TextTheme TextTheme
// Brightness indicates if this is a light or dark theme.
Brightness Brightness
// Component themes - optional, derived from ColorScheme if nil.
ButtonTheme *ButtonThemeData
CheckboxTheme *CheckboxThemeData
SwitchTheme *SwitchThemeData
TextFieldTheme *TextFieldThemeData
TabBarTheme *TabBarThemeData
RadioTheme *RadioThemeData
DropdownTheme *DropdownThemeData
}
func DefaultDarkTheme
func DefaultDarkTheme() *ThemeData
DefaultDarkTheme returns the default dark theme.
func DefaultLightTheme
func DefaultLightTheme() *ThemeData
DefaultLightTheme returns the default light theme.
func MaybeOf
func MaybeOf(ctx core.BuildContext) *ThemeData
MaybeOf returns the nearest ThemeData, or nil if not found.
func ThemeOf
func ThemeOf(ctx core.BuildContext) *ThemeData
ThemeOf returns the nearest ThemeData in the tree. If no Theme ancestor is found, returns the default light theme.
func (*ThemeData) ButtonThemeOf
func (t *ThemeData) ButtonThemeOf() ButtonThemeData
ButtonThemeOf returns the button theme, deriving from ColorScheme if not set.
func (*ThemeData) CheckboxThemeOf
func (t *ThemeData) CheckboxThemeOf() CheckboxThemeData
CheckboxThemeOf returns the checkbox theme, deriving from ColorScheme if not set.
func (*ThemeData) CopyWith
func (t *ThemeData) CopyWith(colorScheme *ColorScheme, textTheme *TextTheme, brightness *Brightness) *ThemeData
CopyWith returns a new ThemeData with the specified fields overridden.
Example:
This example shows how to customize a theme using CopyWith.
package main
import (
"github.com/go-drift/drift/pkg/rendering"
"github.com/go-drift/drift/pkg/theme"
)
func main() {
// Start with the default light theme
baseTheme := theme.DefaultLightTheme()
// Create a custom color scheme with a different primary color
customColors := theme.LightColorScheme()
customColors.Primary = rendering.RGB(0, 150, 136) // Teal
// Create a new theme with the custom colors
customTheme := baseTheme.CopyWith(&customColors, nil, nil)
_ = customTheme
}
func (*ThemeData) DropdownThemeOf
func (t *ThemeData) DropdownThemeOf() DropdownThemeData
DropdownThemeOf returns the dropdown theme, deriving from ColorScheme if not set.
func (*ThemeData) RadioThemeOf
func (t *ThemeData) RadioThemeOf() RadioThemeData
RadioThemeOf returns the radio theme, deriving from ColorScheme if not set.
func (*ThemeData) SwitchThemeOf
func (t *ThemeData) SwitchThemeOf() SwitchThemeData
SwitchThemeOf returns the switch theme, deriving from ColorScheme if not set.
func (*ThemeData) TabBarThemeOf
func (t *ThemeData) TabBarThemeOf() TabBarThemeData
TabBarThemeOf returns the tab bar theme, deriving from ColorScheme if not set.
func (*ThemeData) TextFieldThemeOf
func (t *ThemeData) TextFieldThemeOf() TextFieldThemeData
TextFieldThemeOf returns the text field theme, deriving from ColorScheme if not set.
Generated by gomarkdoc