Skip to main content

theme

Package theme provides theming support for the Drift framework.

func ButtonOf

func ButtonOf(ctx core.BuildContext, label string, onTap func()) widgets.Button

ButtonOf creates a [widgets.Button] with visual properties filled from the current theme's ButtonThemeData.

This is the recommended way to create buttons that follow the app's theme. The returned button has:

  • Color set to ButtonThemeData.BackgroundColor
  • TextColor set to ButtonThemeData.ForegroundColor
  • Padding set to ButtonThemeData.Padding
  • FontSize set to ButtonThemeData.FontSize
  • BorderRadius set to ButtonThemeData.BorderRadius
  • Haptic set to true

To override specific properties, chain WithX methods on the returned button. WithX always takes precedence over theme values:

theme.ButtonOf(ctx, "Save", onSave).
WithBorderRadius(0). // sharp corners instead of themed radius
WithPadding(layout.EdgeInsetsAll(20)) // custom padding

For fully explicit buttons without theme styling, use [widgets.Button] struct literals.

Example:

func (s *myState) Build(ctx core.BuildContext) core.Widget {
return widgets.Column{
Children: []core.Widget{
theme.ButtonOf(ctx, "Primary Action", s.onPrimary),
widgets.VSpace(12),
theme.ButtonOf(ctx, "Secondary", s.onSecondary).
WithColor(colors.Secondary, colors.OnSecondary),
},
}
}

func CheckboxOf

func CheckboxOf(ctx core.BuildContext, value bool, onChanged func(bool)) widgets.Checkbox

CheckboxOf creates a [widgets.Checkbox] with visual properties filled from the current theme's CheckboxThemeData.

This is the recommended way to create checkboxes that follow the app's theme. The returned checkbox has:

  • ActiveColor set to CheckboxThemeData.ActiveColor
  • CheckColor set to CheckboxThemeData.CheckColor
  • BorderColor set to CheckboxThemeData.BorderColor
  • BackgroundColor set to CheckboxThemeData.BackgroundColor
  • Size set to CheckboxThemeData.Size
  • BorderRadius set to CheckboxThemeData.BorderRadius

To override specific properties, chain WithX methods on the returned checkbox.

For fully explicit checkboxes without theme styling, use [widgets.Checkbox] struct literals.

Example:

theme.CheckboxOf(ctx, isChecked, func(value bool) {
s.SetState(func() { s.isChecked = value })
})

func CircularProgressIndicatorOf

func CircularProgressIndicatorOf(ctx core.BuildContext, value *float64) widgets.CircularProgressIndicator

CircularProgressIndicatorOf creates a [widgets.CircularProgressIndicator] with visual properties filled from the current theme's colors.

This is the recommended way to create circular progress indicators that follow the app's theme. The returned indicator has:

  • Color set to ColorScheme.Primary
  • TrackColor set to ColorScheme.SurfaceVariant
  • Size set to 36 (standard size)
  • StrokeWidth set to 4

Pass nil for value to create an indeterminate (spinning) indicator, or pass a pointer to a float64 (0.0 to 1.0) for determinate progress.

Example:

// Indeterminate (spinning)
theme.CircularProgressIndicatorOf(ctx, nil)

// Determinate (50% complete)
progress := 0.5
theme.CircularProgressIndicatorOf(ctx, &progress)

func DatePickerOf

func DatePickerOf(ctx core.BuildContext, value *time.Time, onChanged func(time.Time)) widgets.DatePicker

DatePickerOf creates a [widgets.DatePicker] with visual properties filled from the current theme's colors.

This is the recommended way to create date pickers that follow the app's theme. The returned date picker has a pre-configured InputDecoration with themed colors and a placeholder of "Select date".

Example:

theme.DatePickerOf(ctx, selectedDate, func(date time.Time) {
s.SetState(func() { s.selectedDate = &date })
})

func DividerOf

func DividerOf(ctx core.BuildContext) widgets.Divider

DividerOf creates a [widgets.Divider] with visual properties filled from the current theme's DividerThemeData.

This is the recommended way to create horizontal dividers that follow the app's theme. The returned divider has:

  • Height set to DividerThemeData.Space
  • Thickness set to DividerThemeData.Thickness
  • Color set to DividerThemeData.Color
  • Indent set to DividerThemeData.Indent
  • EndIndent set to DividerThemeData.EndIndent

For fully explicit dividers without theme styling, use [widgets.Divider] struct literals.

Example:

theme.DividerOf(ctx)

func DropdownOf

func DropdownOf[T comparable](ctx core.BuildContext, value T, items []widgets.DropdownItem[T], onChanged func(T)) widgets.Dropdown[T]

DropdownOf creates a [widgets.Dropdown] with visual properties filled from the current theme's DropdownThemeData.

This is the recommended way to create dropdowns that follow the app's theme. The returned dropdown has:

  • BackgroundColor set to DropdownThemeData.BackgroundColor
  • BorderColor set to DropdownThemeData.BorderColor
  • MenuBackgroundColor set to DropdownThemeData.MenuBackgroundColor
  • MenuBorderColor set to DropdownThemeData.MenuBorderColor
  • BorderRadius set to DropdownThemeData.BorderRadius
  • Height set to DropdownThemeData.Height
  • ItemPadding set to DropdownThemeData.ItemPadding
  • TextStyle.Color set to DropdownThemeData.TextColor
  • SelectedItemColor set to DropdownThemeData.SelectedItemColor

To override specific properties, chain WithX methods on the returned dropdown.

For fully explicit dropdowns without theme styling, use [widgets.Dropdown] struct literals.

Example:

theme.DropdownOf(ctx, selectedPlan, []widgets.DropdownItem[string]{
{Value: "starter", Label: "Starter"},
{Value: "pro", Label: "Pro"},
}, func(value string) {
s.SetState(func() { s.selectedPlan = value })
})

func IconOf

func IconOf(ctx core.BuildContext, glyph string) widgets.Icon

IconOf creates a [widgets.Icon] with visual properties filled from the current theme's colors.

This is the recommended way to create icons that follow the app's theme. The returned icon has:

  • Size set to 24 (standard icon size)
  • Color set to ColorScheme.OnSurface

To override specific properties, set fields on the returned icon:

icon := theme.IconOf(ctx, "★")
icon.Size = 32
icon.Color = colors.Primary

For fully explicit icons without theme styling, use [widgets.Icon] struct literals.

Example:

theme.IconOf(ctx, "✓")

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 LinearProgressIndicatorOf

func LinearProgressIndicatorOf(ctx core.BuildContext, value *float64) widgets.LinearProgressIndicator

LinearProgressIndicatorOf creates a [widgets.LinearProgressIndicator] with visual properties filled from the current theme's colors.

This is the recommended way to create linear progress indicators that follow the app's theme. The returned indicator has:

  • Color set to ColorScheme.Primary
  • TrackColor set to ColorScheme.SurfaceVariant
  • Height set to 4
  • BorderRadius set to 2

Pass nil for value to create an indeterminate (animating) indicator, or pass a pointer to a float64 (0.0 to 1.0) for determinate progress.

Example:

// Indeterminate (animating)
theme.LinearProgressIndicatorOf(ctx, nil)

// Determinate (75% complete)
progress := 0.75
theme.LinearProgressIndicatorOf(ctx, &progress)

func RadioOf

func RadioOf[T comparable](ctx core.BuildContext, value, groupValue T, onChanged func(T)) widgets.Radio[T]

RadioOf creates a [widgets.Radio] with visual properties filled from the current theme's RadioThemeData.

This is the recommended way to create radio buttons that follow the app's theme. The returned radio has:

  • ActiveColor set to RadioThemeData.ActiveColor
  • InactiveColor set to RadioThemeData.InactiveColor
  • BackgroundColor set to RadioThemeData.BackgroundColor
  • Size set to RadioThemeData.Size

For fully explicit radio buttons without theme styling, use [widgets.Radio] struct literals.

Example:

theme.RadioOf(ctx, "email", selectedMethod, func(value string) {
s.SetState(func() { s.selectedMethod = value })
})

func RichTextOf

func RichTextOf(ctx core.BuildContext, spans ...graphics.TextSpan) widgets.RichText

RichTextOf creates a [widgets.RichText] with themed defaults for color and font size. Theme values are set on the widget-level [widgets.RichText.Style] field, which acts as the lowest-priority base: the Content span tree's own styles override it, and child spans override their parents as usual.

To override layout properties, chain With* methods on the returned widget:

theme.RichTextOf(ctx, spans...).WithAlign(graphics.TextAlignCenter).WithMaxLines(3)

Example:

theme.RichTextOf(ctx,
graphics.Span("Hello "),
graphics.Span("World").Bold(),
)

func TabBarOf

func TabBarOf(ctx core.BuildContext, items []widgets.TabItem, currentIndex int, onTap func(int)) widgets.TabBar

TabBarOf creates a [widgets.TabBar] with visual properties filled from the current theme's TabBarThemeData.

This is the recommended way to create tab bars that follow the app's theme. The returned tab bar has:

  • BackgroundColor set to TabBarThemeData.BackgroundColor
  • ActiveColor set to TabBarThemeData.ActiveColor
  • InactiveColor set to TabBarThemeData.InactiveColor
  • IndicatorColor set to TabBarThemeData.IndicatorColor
  • IndicatorHeight set to TabBarThemeData.IndicatorHeight
  • Padding set to TabBarThemeData.Padding
  • Height set to TabBarThemeData.Height
  • LabelStyle set to TextTheme.LabelSmall

For fully explicit tab bars without theme styling, use [widgets.TabBar] struct literals.

Example:

theme.TabBarOf(ctx, []widgets.TabItem{
{Label: "Home"},
{Label: "Search"},
{Label: "Profile"},
}, currentIndex, func(index int) {
s.SetState(func() { s.currentIndex = index })
})

func TextFieldOf

func TextFieldOf(ctx core.BuildContext, controller *platform.TextEditingController) widgets.TextField

TextFieldOf creates a [widgets.TextField] with visual properties filled from the current theme's TextFieldThemeData.

This is the recommended way to create text fields that follow the app's theme. The returned text field has all visual properties pre-filled from the theme, including colors, dimensions, and typography styles.

To override specific properties, chain WithX methods on the returned text field.

For fully explicit text fields without theme styling, use [widgets.TextField] struct literals (you must provide all visual properties).

Example:

theme.TextFieldOf(ctx, controller).
WithPlaceholder("Enter email").
WithLabel("Email")

func TextFormFieldOf

func TextFormFieldOf(ctx core.BuildContext) widgets.TextFormField

TextFormFieldOf creates a [widgets.TextFormField] with visual properties filled from the current theme's TextFieldThemeData.

This is the recommended way to create form text fields that follow the app's theme. The returned text form field has all visual properties pre-filled from the theme via an embedded TextField, including colors, dimensions, and typography styles.

To override specific properties, chain WithX methods on the returned text form field.

For fully explicit text form fields without theme styling, use [widgets.TextFormField] struct literals (you must provide all visual properties).

Example:

theme.TextFormFieldOf(ctx).
WithLabel("Email").
WithPlaceholder("Enter your email").
WithValidator(func(value string) string {
if !strings.Contains(value, "@") {
return "Invalid email address"
}
return ""
})

func TextOf

func TextOf(ctx core.BuildContext, content string, style graphics.TextStyle) widgets.Text

TextOf creates a [widgets.Text] with the given content and style.

This is a convenient way to create text that follows the app's typography. Pass a style from the theme's TextTheme for consistent typography:

_, _, textTheme := theme.UseTheme(ctx)
theme.TextOf(ctx, "Welcome", textTheme.HeadlineMedium)

Example:

func (s *myState) Build(ctx core.BuildContext) core.Widget {
_, _, textTheme := theme.UseTheme(ctx)
return widgets.Column{
Children: []core.Widget{
theme.TextOf(ctx, "Welcome", textTheme.HeadlineMedium),
widgets.VSpace(8),
theme.TextOf(ctx, "Please sign in to continue", textTheme.BodyLarge),
},
}
}

func TimePickerOf

func TimePickerOf(ctx core.BuildContext, hour, minute int, onChanged func(hour, minute int)) widgets.TimePicker

TimePickerOf creates a [widgets.TimePicker] with visual properties filled from the current theme's colors.

This is the recommended way to create time pickers that follow the app's theme. The returned time picker has a pre-configured InputDecoration with themed colors.

Example:

theme.TimePickerOf(ctx, hour, minute, func(h, m int) {
s.SetState(func() { s.hour, s.minute = h, m })
})

func ToggleOf

func ToggleOf(ctx core.BuildContext, value bool, onChanged func(bool)) widgets.Toggle

ToggleOf creates a [widgets.Toggle] with visual properties filled from the current theme's SwitchThemeData.

This is the recommended way to create toggles that follow the app's theme. The returned toggle has:

  • ActiveColor set to SwitchThemeData.ActiveTrackColor
  • InactiveColor set to SwitchThemeData.InactiveTrackColor
  • ThumbColor set to SwitchThemeData.ThumbColor
  • Width set to SwitchThemeData.Width
  • Height set to SwitchThemeData.Height

For fully explicit toggles without theme styling, use [widgets.Toggle] struct literals.

Example:

theme.ToggleOf(ctx, isEnabled, func(value bool) {
s.SetState(func() { s.isEnabled = value })
})

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)

func VerticalDividerOf

func VerticalDividerOf(ctx core.BuildContext) widgets.VerticalDivider

VerticalDividerOf creates a [widgets.VerticalDivider] with visual properties filled from the current theme's DividerThemeData.

This is the recommended way to create vertical dividers that follow the app's theme. The returned divider has:

  • Width set to DividerThemeData.Space
  • Thickness set to DividerThemeData.Thickness
  • Color set to DividerThemeData.Color
  • Indent set to DividerThemeData.Indent
  • EndIndent set to DividerThemeData.EndIndent

For fully explicit vertical dividers without theme styling, use [widgets.VerticalDivider] struct literals.

Example:

theme.VerticalDividerOf(ctx)

type AppTheme

AppTheme provides unified theme data via InheritedWidget.

type AppTheme struct {
core.InheritedBase
Data *AppThemeData
Child core.Widget
}

func (AppTheme) ChildWidget

func (a AppTheme) ChildWidget() core.Widget

ChildWidget returns the child widget.

func (AppTheme) ShouldRebuildDependents

func (a AppTheme) ShouldRebuildDependents(oldWidget core.InheritedWidget) bool

ShouldRebuildDependents returns true if the theme data has changed.

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).

func (*AppThemeData) Copy

func (a *AppThemeData) Copy() *AppThemeData

Copy returns a deep copy of the theme data. All nested structs and pointer fields are independently copied so tests can mutate without affecting the original.

type BottomSheetThemeData

BottomSheetThemeData defines default styling for BottomSheet widgets.

type BottomSheetThemeData struct {
// BackgroundColor is the sheet's background color.
BackgroundColor graphics.Color
// HandleColor is the drag handle indicator color.
HandleColor graphics.Color
// BarrierColor is the color of the semi-transparent barrier behind the sheet.
BarrierColor graphics.Color
// BorderRadius is the corner radius for the top corners of the sheet.
BorderRadius float64
// HandleWidth is the width of the drag handle indicator.
HandleWidth float64
// HandleHeight is the height of the drag handle indicator.
HandleHeight float64
// HandleTopPadding is the padding above the drag handle.
HandleTopPadding float64
// HandleBottomPadding is the padding below the drag handle.
HandleBottomPadding float64
}

func DefaultBottomSheetTheme

func DefaultBottomSheetTheme(colors ColorScheme) BottomSheetThemeData

DefaultBottomSheetTheme returns BottomSheetThemeData derived from a ColorScheme.

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 graphics.Color
// ForegroundColor is the default text/icon color.
ForegroundColor graphics.Color
// DisabledBackgroundColor is the background when disabled.
DisabledBackgroundColor graphics.Color
// DisabledForegroundColor is the text color when disabled.
DisabledForegroundColor graphics.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 graphics.Color
// CheckColor is the checkmark color.
CheckColor graphics.Color
// BorderColor is the outline color when unchecked.
BorderColor graphics.Color
// BackgroundColor is the fill color when unchecked.
BackgroundColor graphics.Color
// DisabledActiveColor is the fill color when checked and disabled.
DisabledActiveColor graphics.Color
// DisabledCheckColor is the checkmark color when disabled.
DisabledCheckColor graphics.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 graphics.Color
// OnPrimary is the color for text/icons on primary.
OnPrimary graphics.Color
// PrimaryContainer is a tonal container for primary.
PrimaryContainer graphics.Color
// OnPrimaryContainer is the color for text/icons on primary container.
OnPrimaryContainer graphics.Color

// Secondary is a supporting brand color.
Secondary graphics.Color
// OnSecondary is the color for text/icons on secondary.
OnSecondary graphics.Color
// SecondaryContainer is a tonal container for secondary.
SecondaryContainer graphics.Color
// OnSecondaryContainer is the color for text/icons on secondary container.
OnSecondaryContainer graphics.Color

// Tertiary is an accent color for contrast.
Tertiary graphics.Color
// OnTertiary is the color for text/icons on tertiary.
OnTertiary graphics.Color
// TertiaryContainer is a tonal container for tertiary.
TertiaryContainer graphics.Color
// OnTertiaryContainer is the color for text/icons on tertiary container.
OnTertiaryContainer graphics.Color

// Surface is the color for cards, sheets, menus.
Surface graphics.Color
// OnSurface is the color for text/icons on surface.
OnSurface graphics.Color
// SurfaceVariant is an alternative surface color.
SurfaceVariant graphics.Color
// OnSurfaceVariant is the color for text/icons on surface variant.
OnSurfaceVariant graphics.Color

// SurfaceDim is a dimmed surface for less emphasis.
SurfaceDim graphics.Color
// SurfaceBright is a bright surface for more emphasis.
SurfaceBright graphics.Color
// SurfaceContainerLowest is the lowest emphasis container surface.
SurfaceContainerLowest graphics.Color
// SurfaceContainerLow is a low emphasis container surface.
SurfaceContainerLow graphics.Color
// SurfaceContainer is the default container surface.
SurfaceContainer graphics.Color
// SurfaceContainerHigh is a high emphasis container surface.
SurfaceContainerHigh graphics.Color
// SurfaceContainerHighest is the highest emphasis container surface.
SurfaceContainerHighest graphics.Color

// Background is the app background color.
Background graphics.Color
// OnBackground is the color for text/icons on background.
OnBackground graphics.Color

// Error is the color for error states.
Error graphics.Color
// OnError is the color for text/icons on error.
OnError graphics.Color
// ErrorContainer is a tonal container for error.
ErrorContainer graphics.Color
// OnErrorContainer is the color for text/icons on error container.
OnErrorContainer graphics.Color

// Outline is the color for borders and dividers.
Outline graphics.Color
// OutlineVariant is a subtle outline for decorative elements.
OutlineVariant graphics.Color

// Shadow is the color for elevation shadows.
Shadow graphics.Color
// Scrim is the color for modal barriers.
Scrim graphics.Color

// InverseSurface is the surface color for inverse contexts.
InverseSurface graphics.Color
// OnInverseSurface is the color for text/icons on inverse surface.
OnInverseSurface graphics.Color
// InversePrimary is the primary color for inverse contexts.
InversePrimary graphics.Color

// SurfaceTint is the tint color applied to surfaces.
SurfaceTint graphics.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/graphics"
"github.com/go-drift/drift/pkg/theme"
"github.com/go-drift/drift/pkg/widgets"
)

func main() {
// Direct usage (outside of widget context) for demonstration:
colors := theme.LightColorScheme()
_ = widgets.Container{
Color: colors.Primary,
Child: widgets.Text{
Content: "Themed text",
Style: graphics.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 graphics.Color
SystemGreen graphics.Color
SystemIndigo graphics.Color
SystemOrange graphics.Color
SystemPink graphics.Color
SystemPurple graphics.Color
SystemRed graphics.Color
SystemTeal graphics.Color
SystemYellow graphics.Color

// Gray colors - semantic grays for various uses
SystemGray graphics.Color
SystemGray2 graphics.Color
SystemGray3 graphics.Color
SystemGray4 graphics.Color
SystemGray5 graphics.Color
SystemGray6 graphics.Color

// Background colors - for view hierarchies
SystemBackground graphics.Color
SecondarySystemBackground graphics.Color
TertiarySystemBackground graphics.Color

// Grouped background colors - for grouped content
SystemGroupedBackground graphics.Color
SecondarySystemGroupedBackground graphics.Color
TertiarySystemGroupedBackground graphics.Color

// Label colors - for text content
Label graphics.Color
SecondaryLabel graphics.Color
TertiaryLabel graphics.Color
QuaternaryLabel graphics.Color

// Fill colors - for shapes and controls
SystemFill graphics.Color
SecondarySystemFill graphics.Color
TertiarySystemFill graphics.Color
QuaternarySystemFill graphics.Color

// Separator colors - for dividers
Separator graphics.Color
OpaqueSeparator graphics.Color

// Link color
Link graphics.Color

// Placeholder text color
PlaceholderText graphics.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 graphics.TextStyle

// ActionTextStyle is for interactive text elements.
ActionTextStyle graphics.TextStyle

// NavTitleTextStyle is for navigation bar titles.
NavTitleTextStyle graphics.TextStyle

// NavLargeTitleTextStyle is for large navigation bar titles.
NavLargeTitleTextStyle graphics.TextStyle

// TabLabelTextStyle is for tab bar labels.
TabLabelTextStyle graphics.TextStyle

// PickerTextStyle is for picker/wheel items.
PickerTextStyle graphics.TextStyle

// DateTimePickerTextStyle is for date/time picker items.
DateTimePickerTextStyle graphics.TextStyle

// LargeTitleTextStyle is for large prominent text.
LargeTitleTextStyle graphics.TextStyle

// Title1TextStyle is for title level 1.
Title1TextStyle graphics.TextStyle

// Title2TextStyle is for title level 2.
Title2TextStyle graphics.TextStyle

// Title3TextStyle is for title level 3.
Title3TextStyle graphics.TextStyle

// HeadlineTextStyle is for headline text.
HeadlineTextStyle graphics.TextStyle

// SubheadlineTextStyle is for subheadline text.
SubheadlineTextStyle graphics.TextStyle

// BodyTextStyle is for body text.
BodyTextStyle graphics.TextStyle

// CalloutTextStyle is for callout text.
CalloutTextStyle graphics.TextStyle

// FootnoteTextStyle is for footnote text.
FootnoteTextStyle graphics.TextStyle

// Caption1TextStyle is for caption level 1.
Caption1TextStyle graphics.TextStyle

// Caption2TextStyle is for caption level 2.
Caption2TextStyle graphics.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 graphics.Color) CupertinoTextThemeData

DefaultCupertinoTextTheme creates a text theme with iOS-style defaults.

type CupertinoTheme

CupertinoTheme provides CupertinoThemeData to descendant widgets via InheritedWidget.

type CupertinoTheme struct {
core.InheritedBase
// Data is the Cupertino theme configuration.
Data *CupertinoThemeData
// Child is the child widget tree.
Child core.Widget
}

func (CupertinoTheme) ChildWidget

func (t CupertinoTheme) ChildWidget() core.Widget

ChildWidget returns the child widget.

func (CupertinoTheme) ShouldRebuildDependents

func (t CupertinoTheme) ShouldRebuildDependents(oldWidget core.InheritedWidget) bool

ShouldRebuildDependents returns true if the theme data has changed.

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 graphics.Color

// PrimaryContrastingColor is used for text/icons on primary color.
PrimaryContrastingColor graphics.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 graphics.Color

// ScaffoldBackgroundColor is the default page background color.
ScaffoldBackgroundColor graphics.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 *graphics.Color, primaryContrastingColor *graphics.Color, colors *CupertinoColors, textTheme *CupertinoTextThemeData, barBackgroundColor *graphics.Color, scaffoldBackgroundColor *graphics.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 DialogThemeData

DialogThemeData defines default styling for [overlay.Dialog] and [overlay.AlertDialog] widgets.

Override individual fields by setting DialogTheme on ThemeData:

custom := theme.DialogThemeData{
BackgroundColor: colors.Surface,
BorderRadius: 16,
Elevation: 2,
Padding: layout.EdgeInsetsAll(16),
}
themeData.DialogTheme = &custom
type DialogThemeData struct {
// BackgroundColor is the dialog surface color.
// Default: ColorScheme.SurfaceContainerHigh.
BackgroundColor graphics.Color
// BorderRadius is the corner radius in pixels.
// Default: 28 (Material 3).
BorderRadius float64
// Elevation is the shadow elevation level (1-5).
// Passed to [graphics.BoxShadowElevation]. Default: 3.
Elevation int
// Padding is the inner padding applied to the dialog container.
// Default: 24px on all sides.
Padding layout.EdgeInsets
// TitleContentSpacing is the vertical gap between title and content
// in [overlay.AlertDialog]. Default: 16.
TitleContentSpacing float64
// ContentActionsSpacing is the vertical gap above the actions row
// in [overlay.AlertDialog]. Default: 24.
ContentActionsSpacing float64
// ActionSpacing is the horizontal gap between action buttons
// in [overlay.AlertDialog]. Default: 8.
ActionSpacing float64
// AlertDialogWidth is the default width for [overlay.AlertDialog] when
// its Width field is zero. Default: 280 (Material 3 minimum).
AlertDialogWidth float64
}

func DefaultDialogTheme

func DefaultDialogTheme(colors ColorScheme) DialogThemeData

DefaultDialogTheme returns DialogThemeData derived from a ColorScheme. Used when [ThemeData.DialogTheme] is nil.

type DividerThemeData

DividerThemeData defines default styling for Divider and VerticalDivider widgets.

type DividerThemeData struct {
// Color is the line color.
Color graphics.Color
// Space is the default Height (Divider) or Width (VerticalDivider).
Space float64
// Thickness is the line thickness.
Thickness float64
// Indent is the leading inset (left for Divider, top for VerticalDivider).
Indent float64
// EndIndent is the trailing inset (right for Divider, bottom for VerticalDivider).
EndIndent float64
}

func DefaultDividerTheme

func DefaultDividerTheme(colors ColorScheme) DividerThemeData

DefaultDividerTheme returns DividerThemeData derived from a ColorScheme.

type DropdownThemeData

DropdownThemeData defines default styling for Dropdown widgets.

type DropdownThemeData struct {
// BackgroundColor is the trigger background.
BackgroundColor graphics.Color
// BorderColor is the trigger border color.
BorderColor graphics.Color
// MenuBackgroundColor is the dropdown menu background.
MenuBackgroundColor graphics.Color
// MenuBorderColor is the dropdown menu border color.
MenuBorderColor graphics.Color
// SelectedItemColor is the background for the selected item.
SelectedItemColor graphics.Color
// TextColor is the default text color.
TextColor graphics.Color
// DisabledTextColor is the text color when disabled.
DisabledTextColor graphics.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
// FontSize is the default text font size.
FontSize 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 graphics.Color
// InactiveColor is the border color when unselected.
InactiveColor graphics.Color
// BackgroundColor is the fill color when unselected.
BackgroundColor graphics.Color
// DisabledActiveColor is the fill color when selected and disabled.
DisabledActiveColor graphics.Color
// DisabledInactiveColor is the border color when disabled.
DisabledInactiveColor graphics.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 graphics.Color
// InactiveTrackColor is the track color when off.
InactiveTrackColor graphics.Color
// ThumbColor is the thumb fill color.
ThumbColor graphics.Color
// DisabledActiveTrackColor is the track color when on and disabled.
DisabledActiveTrackColor graphics.Color
// DisabledInactiveTrackColor is the track color when off and disabled.
DisabledInactiveTrackColor graphics.Color
// DisabledThumbColor is the thumb color when disabled.
DisabledThumbColor graphics.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 graphics.Color
// ActiveColor is the color for the selected tab.
ActiveColor graphics.Color
// InactiveColor is the color for unselected tabs.
InactiveColor graphics.Color
// IndicatorColor is the color for the selection indicator.
IndicatorColor graphics.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 graphics.Color
// BorderColor is the default border color.
BorderColor graphics.Color
// FocusColor is the border color when focused.
FocusColor graphics.Color
// ErrorColor is the border color when in error state.
ErrorColor graphics.Color
// LabelColor is the label text color.
LabelColor graphics.Color
// TextColor is the input text color.
TextColor graphics.Color
// PlaceholderColor is the placeholder text color.
PlaceholderColor graphics.Color
// Padding is the default inner padding.
Padding layout.EdgeInsets
// BorderRadius is the default corner radius.
BorderRadius float64
// BorderWidth is the default border stroke width.
BorderWidth 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 graphics.TextStyle
DisplayMedium graphics.TextStyle
DisplaySmall graphics.TextStyle

// Headline styles are for high-emphasis text.
HeadlineLarge graphics.TextStyle
HeadlineMedium graphics.TextStyle
HeadlineSmall graphics.TextStyle

// Title styles are for medium-emphasis text.
TitleLarge graphics.TextStyle
TitleMedium graphics.TextStyle
TitleSmall graphics.TextStyle

// Body styles are for long-form text.
BodyLarge graphics.TextStyle
BodyMedium graphics.TextStyle
BodySmall graphics.TextStyle

// Label styles are for small text like buttons.
LabelLarge graphics.TextStyle
LabelMedium graphics.TextStyle
LabelSmall graphics.TextStyle
}

func DefaultTextTheme

func DefaultTextTheme(textColor graphics.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 {
core.InheritedBase
// Data is the theme configuration.
Data *ThemeData
// Child is the child widget tree.
Child 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{
Child: widgets.Text{Content: "Themed App"},
}

// Wrap the root widget with a Theme
themedApp := theme.Theme{
Data: theme.DefaultDarkTheme(),
Child: root,
}
_ = themedApp
}

func (Theme) ChildWidget

func (t Theme) ChildWidget() core.Widget

ChildWidget returns the child widget.

func (Theme) ShouldRebuildDependents

func (t Theme) ShouldRebuildDependents(oldWidget core.InheritedWidget) bool

ShouldRebuildDependents returns true if the theme data has changed.

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
BottomSheetTheme *BottomSheetThemeData
DividerTheme *DividerThemeData
DialogTheme *DialogThemeData
}

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) BottomSheetThemeOf

func (t *ThemeData) BottomSheetThemeOf() BottomSheetThemeData

BottomSheetThemeOf returns the bottom sheet theme, deriving from ColorScheme if not set.

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/graphics"
"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 = graphics.RGB(0, 150, 136) // Teal

// Create a new theme with the custom colors
customTheme := baseTheme.CopyWith(&customColors, nil, nil)
_ = customTheme
}

func (*ThemeData) DialogThemeOf

func (t *ThemeData) DialogThemeOf() DialogThemeData

DialogThemeOf returns the dialog theme, falling back to DefaultDialogTheme when [ThemeData.DialogTheme] is nil.

func (*ThemeData) DividerThemeOf

func (t *ThemeData) DividerThemeOf() DividerThemeData

DividerThemeOf returns the divider theme, deriving from ColorScheme if not set.

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