Raxol.Core.Renderer.View.Utils.ViewUtils (Raxol v0.5.0)

View Source

Provides utility functions for common view operations in the Raxol view system.

Summary

Functions

Applies foreground and background colors to text.

Applies styles to a string of text.

Calculates the dimensions of a view based on its content and constraints.

Converts a color name to its ANSI color code.

Merges two views, with the second view's properties taking precedence.

Normalizes spacing values for padding and margin. Accepts various input formats and converts them to a standardized format.

Functions

apply_colors(text, list)

Applies foreground and background colors to text.

Examples

apply_colors("Hello", fg: :red, bg: :blue)
apply_colors("World", fg: {255, 0, 0}, bg: {0, 0, 255})

apply_styles(text, styles)

Applies styles to a string of text.

Options

  • :bold - Makes text bold
  • :underline - Underlines text
  • :italic - Makes text italic
  • :strikethrough - Adds strikethrough to text

calculate_dimensions(view, available_size)

Calculates the dimensions of a view based on its content and constraints.

color_to_code(color)

Converts a color name to its ANSI color code.

merge_views(base_view, override_view)

Merges two views, with the second view's properties taking precedence.

normalize_spacing(spacing)

Normalizes spacing values for padding and margin. Accepts various input formats and converts them to a standardized format.

Examples

normalize_spacing(5)           # {5, 5, 5, 5}
normalize_spacing({10, 20})    # {10, 20, 10, 20}
normalize_spacing({1, 2, 3, 4}) # {1, 2, 3, 4}