Raxol.Style.Colors.Theme (Raxol v0.2.0)

View Source

Manages color themes for the Raxol application.

This module provides functionality for:

  • Creating and managing themes
  • Applying themes to the application
  • Accessing theme colors
  • Updating theme colors

Summary

Functions

Applies a theme to the application.

Creates a dark mode version of a theme.

Creates a high contrast version of a theme.

Creates a new theme from a given palette map and optional name.

Gets all UI colors from a theme.

Gets a UI color from a theme.

Creates a standard theme with default colors.

Updates UI colors in a theme.

Types

color()

@type color() :: %{r: integer(), g: integer(), b: integer(), a: float()}

theme()

@type theme() :: %Raxol.Style.Colors.Theme{
  dark_mode: boolean(),
  high_contrast: boolean(),
  name: String.t(),
  palette: %{required(String.t()) => color()},
  ui_mappings: %{required(atom()) => String.t()}
}

Functions

apply_theme(theme)

Applies a theme to the application.

Parameters

  • theme - The theme to apply

Returns

  • :ok on success
  • {:error, reason} on failure

create_dark_theme(theme)

Creates a dark mode version of a theme.

Parameters

  • theme - The theme to create a dark mode version of

Returns

  • A new theme with dark mode colors

create_high_contrast_theme(theme)

Creates a high contrast version of a theme.

Parameters

  • theme - The theme to create a high contrast version of

Returns

  • A new theme with high contrast colors

from_palette(palette, name \\ "Custom")

@spec from_palette(map(), String.t()) :: theme()

Creates a new theme from a given palette map and optional name.

Assumes the input palette map contains Color structs or maps convertible to Color structs.

Parameters

  • palette - A map representing the color palette (e.g., %{"primary" => %{r: 0, g: 119, b: 204, a: 1.0}, ...})
  • name (optional) - The name for the theme. Defaults to "Custom".

Returns

  • A new theme struct.

Examples

iex> nord_palette = Raxol.Style.Colors.Palette.nord()
iex> theme = Raxol.Style.Colors.Theme.from_palette(nord_palette, "Nord Theme")
iex> theme.name
"Nord Theme"
iex> theme.palette["polar_night_1"]
%{r: 46, g: 52, b: 64, a: 1.0}

get_all_ui_colors(theme)

Gets all UI colors from a theme.

Parameters

  • theme - The theme to get the colors from

Returns

  • A map of UI elements to their colors

get_ui_color(theme, element)

Gets a UI color from a theme.

Parameters

  • theme - The theme to get the color from
  • element - The UI element to get the color for

Returns

  • The color for the specified UI element

standard_theme()

Creates a standard theme with default colors.

Returns

  • A new theme with default colors

update_ui_colors(theme, colors)

Updates UI colors in a theme.

Parameters

  • theme - The theme to update
  • colors - A map of UI elements to their new colors

Returns

  • The updated theme