Skip to main content

Crate horizon_lattice_style

Crate horizon_lattice_style 

Source
Expand description

CSS-like styling system for Horizon Lattice.

This crate provides a comprehensive styling system inspired by CSS, featuring:

  • Selectors: Type, class, ID, pseudo-class, and combinator selectors
  • Cascading: Style priority and specificity-based resolution
  • CSS Parsing: Load styles from external .css files
  • Hot Reload: Automatically reload stylesheets during development
  • Type-safe DSL: Build styles programmatically with Rust

§Example: Programmatic Styling

use horizon_lattice_style::prelude::*;

// Create a selector for buttons with primary class
let selector = Selector::type_selector("Button")
    .descendant(SelectorPart::class_only("primary"));

// Style values
let padding = EdgeValues::uniform(LengthValue::px(16.0));
let border = EdgeValues::uniform(LengthValue::px(1.0));

// Check selector properties
assert!(!selector.parts.is_empty());

§Example: Selectors

use horizon_lattice_style::prelude::*;

// Type selector
let button = Selector::type_selector("Button");

// Class selector
let primary = Selector::class("primary");

// ID selector
let submit = Selector::id("submit");

// Complex selector with pseudo-class
let hover_button = Selector::type_selector("Button")
    .descendant(
        SelectorPart::class_only("primary")
            .with_pseudo(PseudoClass::Hover)
    );

assert_eq!(hover_button.to_string(), "Button .primary:hover");

§Example: Loading Stylesheets (requires filesystem)

use horizon_lattice_style::prelude::*;

// Load a stylesheet from a file
let stylesheet = StyleSheet::from_file("styles/app.css", StylePriority::Application)
    .expect("Failed to load stylesheet");

// Create a style engine with the light theme
let mut engine = StyleEngine::new(Theme::light());
engine.add_stylesheet(stylesheet);

Modules§

icon_theme
Icon theme system for Horizon Lattice.
parser
CSS parsing module.
prelude
Prelude module with commonly used types.
resolve
Style resolution engine.
rules
Style rules and stylesheets.
selector
CSS selector types and matching.
style
Style properties and computed styles.
theme
Theme system with built-in themes.
types
Core style value types.
widget
Widget styling integration.

Enums§

Error
Errors that can occur in the styling system.

Type Aliases§

Result
Result type alias for style operations.