Raxol.UI.Theming.Theme (Raxol v0.2.0)

View Source

Defines and manages UI themes for the Raxol system.

This module provides:

  • Theme definition and registration
  • Default theme settings
  • Theme application to UI elements
  • Color scheme management

Summary

Functions

Applies a theme to an element tree.

Gets a color from a theme.

Gets a component style from a theme.

Gets the dark theme.

Gets the default theme.

Gets a theme by ID.

Gets a color value considering the theme and an optional variant.

Initializes the theme system.

Lists all registered themes.

Registers a theme for use in the application.

Types

t()

@type t() :: %Raxol.UI.Theming.Theme{
  colors: map(),
  component_styles: map(),
  description: String.t(),
  fonts: map(),
  id: atom(),
  name: String.t(),
  variants: term()
}

theme_variant()

@type theme_variant() :: %{palette: map(), component_styles: map()}

Functions

apply_theme(element, theme)

Applies a theme to an element tree.

Parameters

  • element - The element tree to apply the theme to
  • theme - The theme to apply

Returns

The element tree with theme applied

color(theme, color_name)

Gets a color from a theme.

Parameters

  • theme - The theme to get colors from
  • color_name - The name of the color to get

Returns

The color value, or a default color if not found

component_style(theme, component_type)

Gets a component style from a theme.

Parameters

  • theme - The theme to get styles from
  • component_type - The type of component to get styles for

Returns

A map of style properties for the component, or an empty map if not found

dark_theme()

Gets the dark theme.

Returns

The dark theme struct

default_theme()

Gets the default theme.

Returns

The default theme struct

get(theme_id)

Gets a theme by ID.

Parameters

  • theme_id - The ID of the theme to retrieve

Returns

The theme struct or nil if not found

get_color(theme, color_name, variant_id \\ nil)

@spec get_color(t(), atom(), atom() | nil) :: Raxol.Style.Colors.color_value() | nil

Gets a color value considering the theme and an optional variant.

Looks up the color in the variant's palette first, then falls back to the theme's base palette.

init()

Initializes the theme system.

list()

Lists all registered themes.

Returns

A list of theme structs

register(theme)

Registers a theme for use in the application.

Parameters

  • theme - The theme struct to register

Returns

:ok