astrelis-ui 0.2.4

UI Framework designed for Astrelis Game Engine
Documentation

Astrelis UI - Taffy-based UI system with WGPU rendering

This crate provides a flexible UI system built on Taffy layout engine:

  • Declarative widget API
  • Flexbox and Grid layouts via Taffy
  • GPU-accelerated rendering
  • Event handling system
  • Composable widget tree

Quick Start

# use astrelis_ui::UiSystem;
# use astrelis_render::{Color, GraphicsContext};
# let graphics_context = GraphicsContext::new_owned_sync().expect("Failed to create graphics context");
let mut ui = UiSystem::new(graphics_context);

ui.build(|root| {
    root.container()
        .width(800.0)
        .height(600.0)
        .padding(20.0)
        .child(|container| {
            container.text("Hello, World!")
                .size(24.0)
                .color(Color::WHITE)
                .build();
            container.button("Click Me").build();
            container.container().build()
        })
        .build();
});

// In render loop:
// ui.update(delta_time);
// ui.handle_events(&mut event_batch);
// ui.render(&mut render_pass, viewport_size);

API Conventions

This crate follows consistent method naming conventions:

Mutation Methods

  • set_*() - Full replacement that may trigger complete rebuild/re-layout
    • Example: set_text() replaces text and triggers text shaping
  • update_*() - Incremental update optimized with dirty flags
    • Example: update_text() only marks TEXT_SHAPING dirty, skipping layout
  • add_*() - Append to a collection
    • Example: add_widget() appends to widget tree

Accessor Methods

  • get_*() - Returns Option<&T> for possibly-missing values
    • Example: get_widget(id) returns Option<&Widget>
  • *() (no prefix) - Returns &T, panics if unavailable (use when required)
    • Example: widget(id) returns &Widget or panics
  • try_*() - Fallible operation returning Result
    • Example: try_layout() returns Result<(), LayoutError>
  • has_*() - Boolean check for existence
    • Example: has_widget(id) returns bool

Computation Methods

  • compute_*() - Expensive computation (results often cached)
    • Example: compute_layout() runs Taffy layout solver
  • calculate_*() - Mathematical calculation
    • Example: calculate_bounds() computes widget bounds

Builder Methods

  • with_*(value) - Builder method returning Self for chaining
    • Example: with_padding(20.0) sets padding and returns builder
  • build() - Finalizes builder and consumes it
    • Example: widget.build() adds widget to tree