dynamic

package
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2025 License: Apache-2.0 Imports: 10 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ColorCalculation2025 is a delegate implementing color calculation logic
	// following the Material Design 2025 specification.
	ColorCalculation2025 = colorCalculationDelegateImpl2025{}
	// ColorCalculation2021 is a delegate implementing color calculation logic
	// following the Material Design 2021 specification.
	ColorCalculation2021 = colorCalculationDelegateImpl2021{}
)
View Source
var ErrInvalidConstraint = errors.New("not a valid Constraint")
View Source
var ErrInvalidPlatform = errors.New("not a valid Platform")
View Source
var ErrInvalidTonePolarity = errors.New("not a valid TonePolarity")
View Source
var ErrInvalidVariant = errors.New("not a valid Variant")
View Source
var ErrInvalidVersion = errors.New("not a valid Version")

Functions

func EnableLightForeground

func EnableLightForeground(tone float64) float64

EnableLightForeground adjusts a tone to enable light foreground if needed.

func FindDesiredChromaByTone

func FindDesiredChromaByTone(
	hue, chroma, tone float64,
	byDecreasingTone bool,
) float64

FindDesiredChromaByTone finds a tone where the chroma is as close as possible to the requested value

func ForegroundTone

func ForegroundTone(bgTone, ratio float64) float64

ForegroundTone calculates a foreground tone that has sufficient contrast with a background tone

func GetPiecewiseHue

func GetPiecewiseHue(
	sourceColorHct color.Hct,
	hueBreakpoints []float64,
	hues []float64,
) float64

GetPiecewiseHue returns a new hue based on a piece wise function and the input color's hue.

func GetRotatedHue

func GetRotatedHue(
	sourceColorHct color.Hct,
	hueBreakpoints []float64,
	rotations []float64,
) float64

GetRotatedHue returns a shifted hue based on a piece wise function and the input hue.

func IsFidelity

func IsFidelity(scheme *Scheme) bool

IsFidelity returns whether the scheme is a fidelity scheme

func IsMonochrome

func IsMonochrome(scheme *Scheme) bool

IsMonochrome returns whether the scheme is monochrome

func ToneAllowsLightForeground

func ToneAllowsLightForeground(tone float64) bool

ToneAllowsLightForeground determines if a tone allows light foreground.

func TonePrefersLightForeground

func TonePrefersLightForeground(tone float64) bool

TonePrefersLightForeground determines if a tone prefers light foreground.

Types

type ChromaMultiplier

type ChromaMultiplier func(s *Scheme) float64

ChromaMultiplier returns a multiplier for the chroma value based on the Scheme. This is used to scale the chroma of the color and defaults to 1 when unspecified.

type Color

type Color struct {
	Name             string
	Palette          TonalPaletteFunc
	Tone             ToneFunc
	ChromaMultiplier ChromaMultiplier
	IsBackground     bool
	Background       ColorFunc
	SecondBackground ColorFunc
	ToneDeltaPair    ToneDeltaPairFunc
	ContrastCurve    ContrastCurveFunc
}

Color represents a color in a dynamic color scheme

func DynamicColorFromPalette

func DynamicColorFromPalette(args *Color) *Color

func FromPalette

func FromPalette(name string, palette TonalPaletteFunc, tone ToneFunc) *Color

FromPalette creates a DynamicColor from a palette and tone function.

func (*Color) GetArgb

func (dc *Color) GetArgb(scheme *Scheme) color.ARGB

GetArgb returns the ARGB value for the DynamicColor in the given scheme.

func (*Color) GetHct

func (dc *Color) GetHct(scheme *Scheme) color.Hct

GetHct returns the HCT color for the DynamicColor in the given scheme.

func (*Color) GetTone

func (dc *Color) GetTone(scheme *Scheme) float64

GetTone retuns Tone for the dynamic color using given scheme.

type ColorCalculationDelegate

type ColorCalculationDelegate interface {
	// GetHct returns the HCT color for the given scheme and color.
	GetHct(scheme *Scheme, dc *Color) color.Hct
	// GetTone returns the tone value for the given scheme and color.
	GetTone(scheme *Scheme, dc *Color) float64
}

ColorCalculationDelegate provides the HCT and tone of a color within a scheme.

This interface allows different implementations of color calculation logic for different Material Design spec versions.

type ColorFunc

type ColorFunc func(s *Scheme) *Color

ColorFunc returns a pointer to a Color based on the Scheme. Typically used to reference background or related colors dynamically.

type Constraint

type Constraint uint

Constraint describes how to fulfill a tone delta pair constraint.

ENUM(exact, nearer, farther)

const (
	// ConstraintExact is a Constraint of type Exact.
	ConstraintExact Constraint = 0
	// ConstraintNearer is a Constraint of type Nearer.
	ConstraintNearer Constraint = 1
	// ConstraintFarther is a Constraint of type Farther.
	ConstraintFarther Constraint = 2
)

func ParseConstraint

func ParseConstraint(name string) (Constraint, error)

ParseConstraint attempts to convert a string to a Constraint.

func (*Constraint) AppendText

func (x *Constraint) AppendText(b []byte) ([]byte, error)

AppendText appends the textual representation of itself to the end of b (allocating a larger slice if necessary) and returns the updated slice.

Implementations must not retain b, nor mutate any bytes within b[:len(b)].

func (Constraint) IsValid

func (x Constraint) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (Constraint) MarshalText

func (x Constraint) MarshalText() ([]byte, error)

MarshalText implements the text marshaller method.

func (Constraint) String

func (x Constraint) String() string

String implements the Stringer interface.

func (*Constraint) UnmarshalText

func (x *Constraint) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller method.

type ContrastCurve

type ContrastCurve struct {
	// contains filtered or unexported fields
}

ContrastCurve represents a curve that provides contrast values based on contrast level

func GetCurve

func GetCurve(defaultContrast float64) *ContrastCurve

GetCurve returns the contrast curve for a given default contrast.

func NewContrastCurve

func NewContrastCurve(low, normal, medium, high float64) *ContrastCurve

NewContrastCurve creates a new NewContrastCurve with the specified values low: Value for contrast level -1.0 normal: Value for contrast level 0.0 medium: Value for contrast level 0.5 high: Value for contrast level 1.0

func (*ContrastCurve) Get

func (c *ContrastCurve) Get(contrast float64) float64

Get returns the value at a given contrast level contrast: The contrast level. 0.0 is the default (normal); -1.0 is the lowest; 1.0 is the highest. return: The value. For contrast ratios, a number between 1.0 and 21.0.

type ContrastCurveFunc

type ContrastCurveFunc func(s *Scheme) *ContrastCurve

ContrastCurveFunc returns a pointer to a ContrastCurve based on the Scheme. A ContrastCurve defines how a color's contrast behaves at various contrast levels. This is typically used in conjunction with a background color.

type MaterialColorSpec

type MaterialColorSpec interface {
	Background() *Color
	Error() *Color
	ErrorContainer() *Color
	ErrorDim() *Color
	HighestSurface(s *Scheme) *Color
	InverseOnSurface() *Color
	InversePrimary() *Color
	InverseSurface() *Color
	NeutralPaletteKeyColor() *Color
	NeutralVariantPaletteKeyColor() *Color
	OnBackground() *Color
	OnError() *Color
	OnErrorContainer() *Color
	OnPrimary() *Color
	OnPrimaryContainer() *Color
	OnPrimaryFixed() *Color
	OnPrimaryFixedVariant() *Color
	OnSecondary() *Color
	OnSecondaryContainer() *Color
	OnSecondaryFixed() *Color
	OnSecondaryFixedVariant() *Color
	OnSurface() *Color
	OnSurfaceVariant() *Color
	OnTertiary() *Color
	OnTertiaryContainer() *Color
	OnTertiaryFixed() *Color
	OnTertiaryFixedVariant() *Color
	Outline() *Color
	OutlineVariant() *Color
	Primary() *Color
	PrimaryContainer() *Color
	PrimaryDim() *Color
	PrimaryFixed() *Color
	PrimaryFixedDim() *Color
	PrimaryPaletteKeyColor() *Color
	Scrim() *Color
	Secondary() *Color
	SecondaryContainer() *Color
	SecondaryDim() *Color
	SecondaryFixed() *Color
	SecondaryFixedDim() *Color
	SecondaryPaletteKeyColor() *Color
	Shadow() *Color
	Surface() *Color
	SurfaceBright() *Color
	SurfaceContainer() *Color
	SurfaceContainerHigh() *Color
	SurfaceContainerHighest() *Color
	SurfaceContainerLow() *Color
	SurfaceContainerLowest() *Color
	SurfaceDim() *Color
	SurfaceTint() *Color
	SurfaceVariant() *Color
	Tertiary() *Color
	TertiaryContainer() *Color
	TertiaryDim() *Color
	TertiaryFixed() *Color
	TertiaryFixedDim() *Color
	TertiaryPaletteKeyColor() *Color
}

type MaterialSpec2021

type MaterialSpec2021 struct{}

func (MaterialSpec2021) Background

func (m MaterialSpec2021) Background() *Color

func (MaterialSpec2021) Error

func (m MaterialSpec2021) Error() *Color

func (MaterialSpec2021) ErrorContainer

func (m MaterialSpec2021) ErrorContainer() *Color

func (MaterialSpec2021) ErrorDim

func (m MaterialSpec2021) ErrorDim() *Color

func (MaterialSpec2021) HighestSurface

func (m MaterialSpec2021) HighestSurface(s *Scheme) *Color

HighestSurface returns the highest surface color based on dark mode

func (MaterialSpec2021) InverseOnSurface

func (m MaterialSpec2021) InverseOnSurface() *Color

func (MaterialSpec2021) InversePrimary

func (m MaterialSpec2021) InversePrimary() *Color

func (MaterialSpec2021) InverseSurface

func (m MaterialSpec2021) InverseSurface() *Color

func (MaterialSpec2021) NeutralPaletteKeyColor

func (m MaterialSpec2021) NeutralPaletteKeyColor() *Color

func (MaterialSpec2021) NeutralVariantPaletteKeyColor

func (m MaterialSpec2021) NeutralVariantPaletteKeyColor() *Color

func (MaterialSpec2021) OnBackground

func (m MaterialSpec2021) OnBackground() *Color

func (MaterialSpec2021) OnError

func (m MaterialSpec2021) OnError() *Color

func (MaterialSpec2021) OnErrorContainer

func (m MaterialSpec2021) OnErrorContainer() *Color

func (MaterialSpec2021) OnPrimary

func (m MaterialSpec2021) OnPrimary() *Color

func (MaterialSpec2021) OnPrimaryContainer

func (m MaterialSpec2021) OnPrimaryContainer() *Color

func (MaterialSpec2021) OnPrimaryFixed

func (m MaterialSpec2021) OnPrimaryFixed() *Color

func (MaterialSpec2021) OnPrimaryFixedVariant

func (m MaterialSpec2021) OnPrimaryFixedVariant() *Color

func (MaterialSpec2021) OnSecondary

func (m MaterialSpec2021) OnSecondary() *Color

func (MaterialSpec2021) OnSecondaryContainer

func (m MaterialSpec2021) OnSecondaryContainer() *Color

func (MaterialSpec2021) OnSecondaryFixed

func (m MaterialSpec2021) OnSecondaryFixed() *Color

func (MaterialSpec2021) OnSecondaryFixedVariant

func (m MaterialSpec2021) OnSecondaryFixedVariant() *Color

func (MaterialSpec2021) OnSurface

func (m MaterialSpec2021) OnSurface() *Color

func (MaterialSpec2021) OnSurfaceVariant

func (m MaterialSpec2021) OnSurfaceVariant() *Color

func (MaterialSpec2021) OnTertiary

func (m MaterialSpec2021) OnTertiary() *Color

func (MaterialSpec2021) OnTertiaryContainer

func (m MaterialSpec2021) OnTertiaryContainer() *Color

func (MaterialSpec2021) OnTertiaryFixed

func (m MaterialSpec2021) OnTertiaryFixed() *Color

func (MaterialSpec2021) OnTertiaryFixedVariant

func (m MaterialSpec2021) OnTertiaryFixedVariant() *Color

func (MaterialSpec2021) Outline

func (m MaterialSpec2021) Outline() *Color

func (MaterialSpec2021) OutlineVariant

func (m MaterialSpec2021) OutlineVariant() *Color

func (MaterialSpec2021) Primary

func (m MaterialSpec2021) Primary() *Color

func (MaterialSpec2021) PrimaryContainer

func (m MaterialSpec2021) PrimaryContainer() *Color

func (MaterialSpec2021) PrimaryDim

func (m MaterialSpec2021) PrimaryDim() *Color

func (MaterialSpec2021) PrimaryFixed

func (m MaterialSpec2021) PrimaryFixed() *Color

func (MaterialSpec2021) PrimaryFixedDim

func (m MaterialSpec2021) PrimaryFixedDim() *Color

func (MaterialSpec2021) PrimaryPaletteKeyColor

func (m MaterialSpec2021) PrimaryPaletteKeyColor() *Color

func (MaterialSpec2021) Scrim

func (m MaterialSpec2021) Scrim() *Color

func (MaterialSpec2021) Secondary

func (m MaterialSpec2021) Secondary() *Color

func (MaterialSpec2021) SecondaryContainer

func (m MaterialSpec2021) SecondaryContainer() *Color

func (MaterialSpec2021) SecondaryDim

func (m MaterialSpec2021) SecondaryDim() *Color

func (MaterialSpec2021) SecondaryFixed

func (m MaterialSpec2021) SecondaryFixed() *Color

func (MaterialSpec2021) SecondaryFixedDim

func (m MaterialSpec2021) SecondaryFixedDim() *Color

func (MaterialSpec2021) SecondaryPaletteKeyColor

func (m MaterialSpec2021) SecondaryPaletteKeyColor() *Color

func (MaterialSpec2021) Shadow

func (m MaterialSpec2021) Shadow() *Color

func (MaterialSpec2021) Surface

func (m MaterialSpec2021) Surface() *Color

func (MaterialSpec2021) SurfaceBright

func (m MaterialSpec2021) SurfaceBright() *Color

func (MaterialSpec2021) SurfaceContainer

func (m MaterialSpec2021) SurfaceContainer() *Color

func (MaterialSpec2021) SurfaceContainerHigh

func (m MaterialSpec2021) SurfaceContainerHigh() *Color

func (MaterialSpec2021) SurfaceContainerHighest

func (m MaterialSpec2021) SurfaceContainerHighest() *Color

func (MaterialSpec2021) SurfaceContainerLow

func (m MaterialSpec2021) SurfaceContainerLow() *Color

func (MaterialSpec2021) SurfaceContainerLowest

func (m MaterialSpec2021) SurfaceContainerLowest() *Color

func (MaterialSpec2021) SurfaceDim

func (m MaterialSpec2021) SurfaceDim() *Color

func (MaterialSpec2021) SurfaceTint

func (m MaterialSpec2021) SurfaceTint() *Color

func (MaterialSpec2021) SurfaceVariant

func (m MaterialSpec2021) SurfaceVariant() *Color

func (MaterialSpec2021) Tertiary

func (m MaterialSpec2021) Tertiary() *Color

func (MaterialSpec2021) TertiaryContainer

func (m MaterialSpec2021) TertiaryContainer() *Color

func (MaterialSpec2021) TertiaryDim

func (m MaterialSpec2021) TertiaryDim() *Color

func (MaterialSpec2021) TertiaryFixed

func (m MaterialSpec2021) TertiaryFixed() *Color

func (MaterialSpec2021) TertiaryFixedDim

func (m MaterialSpec2021) TertiaryFixedDim() *Color

func (MaterialSpec2021) TertiaryPaletteKeyColor

func (m MaterialSpec2021) TertiaryPaletteKeyColor() *Color

type MaterialSpec2025

type MaterialSpec2025 struct {
	MaterialSpec2021
}

func (MaterialSpec2025) Error

func (m MaterialSpec2025) Error() *Color

func (MaterialSpec2025) ErrorContainer

func (m MaterialSpec2025) ErrorContainer() *Color

func (MaterialSpec2025) ErrorDim

func (m MaterialSpec2025) ErrorDim() *Color

func (MaterialSpec2025) InverseOnSurface

func (m MaterialSpec2025) InverseOnSurface() *Color

func (MaterialSpec2025) InversePrimary

func (m MaterialSpec2025) InversePrimary() *Color

func (MaterialSpec2025) InverseSurface

func (m MaterialSpec2025) InverseSurface() *Color

func (MaterialSpec2025) OnError

func (m MaterialSpec2025) OnError() *Color

func (MaterialSpec2025) OnErrorContainer

func (m MaterialSpec2025) OnErrorContainer() *Color

func (MaterialSpec2025) OnPrimary

func (m MaterialSpec2025) OnPrimary() *Color

func (MaterialSpec2025) OnPrimaryContainer

func (m MaterialSpec2025) OnPrimaryContainer() *Color

func (MaterialSpec2025) OnPrimaryFixed

func (m MaterialSpec2025) OnPrimaryFixed() *Color

func (MaterialSpec2025) OnPrimaryFixedVariant

func (m MaterialSpec2025) OnPrimaryFixedVariant() *Color

func (MaterialSpec2025) OnSecondary

func (m MaterialSpec2025) OnSecondary() *Color

func (MaterialSpec2025) OnSecondaryContainer

func (m MaterialSpec2025) OnSecondaryContainer() *Color

func (MaterialSpec2025) OnSecondaryFixed

func (m MaterialSpec2025) OnSecondaryFixed() *Color

func (MaterialSpec2025) OnSecondaryFixedVariant

func (m MaterialSpec2025) OnSecondaryFixedVariant() *Color

func (MaterialSpec2025) OnSurface

func (m MaterialSpec2025) OnSurface() *Color

func (MaterialSpec2025) OnSurfaceVariant

func (m MaterialSpec2025) OnSurfaceVariant() *Color

func (MaterialSpec2025) OnTertiary

func (m MaterialSpec2025) OnTertiary() *Color

func (MaterialSpec2025) OnTertiaryContainer

func (m MaterialSpec2025) OnTertiaryContainer() *Color

func (MaterialSpec2025) OnTertiaryFixed

func (m MaterialSpec2025) OnTertiaryFixed() *Color

func (MaterialSpec2025) OnTertiaryFixedVariant

func (m MaterialSpec2025) OnTertiaryFixedVariant() *Color

func (MaterialSpec2025) Outline

func (m MaterialSpec2025) Outline() *Color

func (MaterialSpec2025) OutlineVariant

func (m MaterialSpec2025) OutlineVariant() *Color

func (MaterialSpec2025) Primary

func (m MaterialSpec2025) Primary() *Color

func (MaterialSpec2025) PrimaryContainer

func (m MaterialSpec2025) PrimaryContainer() *Color

func (MaterialSpec2025) PrimaryDim

func (m MaterialSpec2025) PrimaryDim() *Color

func (MaterialSpec2025) PrimaryFixed

func (m MaterialSpec2025) PrimaryFixed() *Color

func (MaterialSpec2025) PrimaryFixedDim

func (m MaterialSpec2025) PrimaryFixedDim() *Color

func (MaterialSpec2025) Secondary

func (m MaterialSpec2025) Secondary() *Color

func (MaterialSpec2025) SecondaryContainer

func (m MaterialSpec2025) SecondaryContainer() *Color

func (MaterialSpec2025) SecondaryDim

func (m MaterialSpec2025) SecondaryDim() *Color

func (MaterialSpec2025) SecondaryFixed

func (m MaterialSpec2025) SecondaryFixed() *Color

func (MaterialSpec2025) SecondaryFixedDim

func (m MaterialSpec2025) SecondaryFixedDim() *Color

func (MaterialSpec2025) Surface

func (m MaterialSpec2025) Surface() *Color

func (MaterialSpec2025) SurfaceBright

func (m MaterialSpec2025) SurfaceBright() *Color

func (MaterialSpec2025) SurfaceContainer

func (m MaterialSpec2025) SurfaceContainer() *Color

func (MaterialSpec2025) SurfaceContainerHigh

func (m MaterialSpec2025) SurfaceContainerHigh() *Color

func (MaterialSpec2025) SurfaceContainerHighest

func (m MaterialSpec2025) SurfaceContainerHighest() *Color

func (MaterialSpec2025) SurfaceContainerLow

func (m MaterialSpec2025) SurfaceContainerLow() *Color

func (MaterialSpec2025) SurfaceContainerLowest

func (m MaterialSpec2025) SurfaceContainerLowest() *Color

func (MaterialSpec2025) SurfaceDim

func (m MaterialSpec2025) SurfaceDim() *Color

func (MaterialSpec2025) Tertiary

func (m MaterialSpec2025) Tertiary() *Color

func (MaterialSpec2025) TertiaryContainer

func (m MaterialSpec2025) TertiaryContainer() *Color

func (MaterialSpec2025) TertiaryDim

func (m MaterialSpec2025) TertiaryDim() *Color

func (MaterialSpec2025) TertiaryFixed

func (m MaterialSpec2025) TertiaryFixed() *Color

func (MaterialSpec2025) TertiaryFixedDim

func (m MaterialSpec2025) TertiaryFixedDim() *Color

type Platform

type Platform uint

Platform indicates target platform for generating colors

ENUM(phone, watch)

const (
	// PlatformPhone is a Platform of type Phone.
	PlatformPhone Platform = 0
	// PlatformWatch is a Platform of type Watch.
	PlatformWatch Platform = 1
)

func ParsePlatform

func ParsePlatform(name string) (Platform, error)

ParsePlatform attempts to convert a string to a Platform.

func (*Platform) AppendText

func (x *Platform) AppendText(b []byte) ([]byte, error)

AppendText appends the textual representation of itself to the end of b (allocating a larger slice if necessary) and returns the updated slice.

Implementations must not retain b, nor mutate any bytes within b[:len(b)].

func (Platform) IsValid

func (x Platform) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (Platform) MarshalText

func (x Platform) MarshalText() ([]byte, error)

MarshalText implements the text marshaller method.

func (Platform) String

func (x Platform) String() string

String implements the Stringer interface.

func (*Platform) UnmarshalText

func (x *Platform) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller method.

type Scheme

type Scheme struct {
	// SourceColorHct is the source color of the theme as an HCT color
	SourceColorHct color.Hct
	// Variant is the style variant of the theme (e.g., monochrome, tonal spot,
	// etc.)
	Variant Variant
	// Dark indicates whether the scheme is in dark mode (true) or light mode
	// (false)
	Dark bool
	// Platform specifies the platform on which this scheme is intended to be
	// used
	Platform Platform
	// Version specifies the version of the Material Design spec (2021 or 2025)
	Version Version
	// ContrastLevel represents the contrast level from -1 to 1, where:
	// -1 = minimum contrast, 0 = standard contrast, 1 = maximum contrast
	ContrastLevel float64
	// PrimaryPalette produces colors for primary UI elements. Usually colorful.
	PrimaryPalette palettes.TonalPalette
	// SecondaryPalette produces colors for secondary UI elements. Usually less
	// colorful.
	SecondaryPalette palettes.TonalPalette
	// TertiaryPalette produces colors for tertiary UI elements. Usually a
	// different hue from primary and colorful.
	TertiaryPalette palettes.TonalPalette
	// NeutralPalette produces neutral colors for backgrounds and surfaces.
	// Usually not colorful at all.
	NeutralPalette palettes.TonalPalette
	// NeutralVariantPalette produces neutral variant colors for backgrounds and
	// surfaces. Usually not colorful, but slightly more colorful than Neutral
	// palette.
	NeutralVariantPalette palettes.TonalPalette
	// ErrorPalette produces colors for error states. Usually reddish and
	// colorful.
	ErrorPalette palettes.TonalPalette
	// MaterialColor provides the material color specification implementation
	// for the given version (2021 or 2025)
	MaterialColor MaterialColorSpec
}

Scheme represents a dynamic color scheme constructed from a set of values representing the current UI state (dark/light theme, theme style, etc.), and provides a set of TonalPalettes that create colors fitting the theme style. Used by Color to resolve into actual colors.

func NewDynamicScheme

func NewDynamicScheme(
	sourceColorHct color.Hct,
	variant Variant,
	contrastLevel float64,
	dark bool,
	platform Platform,
	version Version,
	optPalettes ...*palettes.TonalPalette,
) *Scheme

NewDynamicScheme creates a new dynamic color scheme.

Parameters:

  • sourceColorHct: The source color of the theme as an HCT color
  • variant: The variant, or style, of the theme
  • contrastLevel: Value from -1 to 1. -1 represents minimum contrast, 0 represents standard (the design as specified), and 1 represents maximum contrast
  • dark: Whether the scheme is in dark mode or light mode
  • platform: The platform on which this scheme is intended to be used
  • version: The version of the design spec that this scheme is based on

- optPalettes (optional): Up to six *palettes.TonalPalette arguments in this order:

  1. primaryPalette
  2. secondaryPalette
  3. tertiaryPalette
  4. neutralPalette
  5. neutralVariantPalette
  6. errorPalette

Missing palettes are generated automatically. If errorPalette is not provided, a default reddish palette (hue 25.0, chroma 84.0) is used.

The function automatically selects the appropriate palette delegate and material color specification based on the version (2021 or 2025).

func (Scheme) SourceColorARGB

func (d Scheme) SourceColorARGB() color.ARGB

SourceColorARGB returns ARGB version of source color.

func (Scheme) ToColorMap

func (d Scheme) ToColorMap() map[string]*Color

ToColorMap creates a map of color name as key and *Color as value.

type SchemePalettesDelegate

type SchemePalettesDelegate interface {
	GetPrimaryPalette(
		variant Variant,
		sourceColorHct color.Hct,
		dark bool,
		platform Platform,
		contrastLevel float64,
	) *palettes.TonalPalette
	GetSecondaryPalette(
		variant Variant,
		sourceColorHct color.Hct,
		dark bool,
		platform Platform,
		contrastLevel float64,
	) *palettes.TonalPalette
	GetTertiaryPalette(
		variant Variant,
		sourceColorHct color.Hct,
		dark bool,
		platform Platform,
		contrastLevel float64,
	) *palettes.TonalPalette
	GetNeutralPalette(
		variant Variant,
		sourceColorHct color.Hct,
		dark bool,
		platform Platform,
		contrastLevel float64,
	) *palettes.TonalPalette
	GetNeutralVariantPalette(
		variant Variant,
		sourceColorHct color.Hct,
		dark bool,
		platform Platform,
		contrastLevel float64,
	) *palettes.TonalPalette
	GetErrorPalette(
		variant Variant,
		sourceColorHct color.Hct,
		dark bool,
		platform Platform,
		contrastLevel float64,
	) *palettes.TonalPalette
}

SchemePalettesDelegate is an interface for the palettes of a DynamicScheme

type TonalPaletteFunc

type TonalPaletteFunc func(s *Scheme) palettes.TonalPalette

TonalPaletteFunc returns a TonalPalette based on the provided Scheme. A TonalPalette is defined by a hue and chroma, allowing chroma to be preserved when contrast adjustments are made, instead of directly specifying hue/chroma.

type ToneDeltaPair

type ToneDeltaPair struct {
	RoleA, RoleB *Color
	Delta        float64
	Polarity     TonePolarity
	StayTogether bool
	Constraint   Constraint
}

ToneDeltaPair documents a constraint between two DynamicColors, in which their tones must have a certain distance from each other.

func NewToneDeltaPair

func NewToneDeltaPair(
	roleA, roleB *Color,
	delta float64,
	polarity TonePolarity,
	stayTogether bool,
	constraint ...Constraint,
) *ToneDeltaPair

NewToneDeltaPair creates a new ToneDeltaPair with default constraint = "exact".

type ToneDeltaPairFunc

type ToneDeltaPairFunc func(s *Scheme) *ToneDeltaPair

ToneDeltaPairFunc returns a pointer to a ToneDeltaPair for the given Scheme. A ToneDeltaPair enforces a tone difference constraint between two colors, where one must be the color being constructed.

type ToneFunc

type ToneFunc func(s *Scheme) float64

ToneFunc returns the tone (lightness) of the color for a given Scheme. If not explicitly provided, it defaults to the tone of the background, or 50 if there is no background.

func GetInitialToneFromBackground

func GetInitialToneFromBackground(background ColorFunc) ToneFunc

GetInitialToneFromBackground returns initial tone from given background ColorFunc. Returns 50 if background ColorFunc is nil.

type TonePolarity

type TonePolarity uint

TonePolarity describes the difference in tone between colors.

ENUM(darker, lighter, nearer, farther, relative_darker, relative_lighter)

const (
	// TonePolarityDarker is a TonePolarity of type Darker.
	TonePolarityDarker TonePolarity = 0
	// TonePolarityLighter is a TonePolarity of type Lighter.
	TonePolarityLighter TonePolarity = 1
	// TonePolarityNearer is a TonePolarity of type Nearer.
	TonePolarityNearer TonePolarity = 2
	// TonePolarityFarther is a TonePolarity of type Farther.
	TonePolarityFarther TonePolarity = 3
	// TonePolarityRelativeDarker is a TonePolarity of type Relative_darker.
	TonePolarityRelativeDarker TonePolarity = 4
	// TonePolarityRelativeLighter is a TonePolarity of type Relative_lighter.
	TonePolarityRelativeLighter TonePolarity = 5
)

func ParseTonePolarity

func ParseTonePolarity(name string) (TonePolarity, error)

ParseTonePolarity attempts to convert a string to a TonePolarity.

func (*TonePolarity) AppendText

func (x *TonePolarity) AppendText(b []byte) ([]byte, error)

AppendText appends the textual representation of itself to the end of b (allocating a larger slice if necessary) and returns the updated slice.

Implementations must not retain b, nor mutate any bytes within b[:len(b)].

func (TonePolarity) IsValid

func (x TonePolarity) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (TonePolarity) MarshalText

func (x TonePolarity) MarshalText() ([]byte, error)

MarshalText implements the text marshaller method.

func (TonePolarity) String

func (x TonePolarity) String() string

String implements the Stringer interface.

func (*TonePolarity) UnmarshalText

func (x *TonePolarity) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller method.

type Variant

type Variant uint

Variant indicates type of scheme to generate

ENUM(monochrome, neutral, tonal_spot, vibrant, expressive, fidelity, content, rainbow, fruit_salad)

const (
	// VariantMonochrome is a Variant of type Monochrome.
	VariantMonochrome Variant = 0
	// VariantNeutral is a Variant of type Neutral.
	VariantNeutral Variant = 1
	// VariantTonalSpot is a Variant of type Tonal_spot.
	VariantTonalSpot Variant = 2
	// VariantVibrant is a Variant of type Vibrant.
	VariantVibrant Variant = 3
	// VariantExpressive is a Variant of type Expressive.
	VariantExpressive Variant = 4
	// VariantFidelity is a Variant of type Fidelity.
	VariantFidelity Variant = 5
	// VariantContent is a Variant of type Content.
	VariantContent Variant = 6
	// VariantRainbow is a Variant of type Rainbow.
	VariantRainbow Variant = 7
	// VariantFruitSalad is a Variant of type Fruit_salad.
	VariantFruitSalad Variant = 8
)

func ParseVariant

func ParseVariant(name string) (Variant, error)

ParseVariant attempts to convert a string to a Variant.

func (*Variant) AppendText

func (x *Variant) AppendText(b []byte) ([]byte, error)

AppendText appends the textual representation of itself to the end of b (allocating a larger slice if necessary) and returns the updated slice.

Implementations must not retain b, nor mutate any bytes within b[:len(b)].

func (Variant) IsValid

func (x Variant) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (Variant) MarshalText

func (x Variant) MarshalText() ([]byte, error)

MarshalText implements the text marshaller method.

func (Variant) String

func (x Variant) String() string

String implements the Stringer interface.

func (*Variant) UnmarshalText

func (x *Variant) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller method.

type Version

type Version uint

Version indicates the material color specification year

ENUM(2021=2021, 2025=2025)

const (
	// Version2021 is a Version of type 2021.
	Version2021 Version = 2021
	// Version2025 is a Version of type 2025.
	Version2025 Version = 2025
)

func ParseVersion

func ParseVersion(name string) (Version, error)

ParseVersion attempts to convert a string to a Version.

func (*Version) AppendText

func (x *Version) AppendText(b []byte) ([]byte, error)

AppendText appends the textual representation of itself to the end of b (allocating a larger slice if necessary) and returns the updated slice.

Implementations must not retain b, nor mutate any bytes within b[:len(b)].

func (Version) IsValid

func (x Version) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (Version) MarshalText

func (x Version) MarshalText() ([]byte, error)

MarshalText implements the text marshaller method.

func (Version) String

func (x Version) String() string

String implements the Stringer interface.

func (*Version) UnmarshalText

func (x *Version) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller method.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL