Skip to main content

Crate wde_ui

Crate wde_ui 

Source
Expand description

WaterDropEngine’s wde-ui crate: an ECS-driven game UI, laid out with taffy.

A UI is a hierarchy of entities with a UiNode, whose UiStyle follows the CSS flexbox / grid / block model. Nodes are drawn as rounded rectangles on top of the scene with a UiBackground, UiBorderColor and UiCornerRadius, and react to the pointer with a UiInteraction. A UiText node is sized to its text, shaped with cosmic-text and drawn with glyphon.

§Example

ⓘ
commands.spawn((
    UiNode(UiStyle {
        width: Val::Percent(100.0),
        height: Val::Px(48.0),
        padding: UiRect::all(Val::Px(8.0)),
        ..default()
    }),
    UiBackground(Color::from_srgba(0.1, 0.1, 0.1, 0.8)),
    children![(
        UiNode(UiStyle { width: Val::Px(32.0), height: Val::Px(32.0), ..default() }),
        UiBackground(Color::WHITE),
        UiInteraction::default()
    )]
));

Each frame in PostUpdate (UiSystems), the hierarchy is laid out against the window and the visible nodes are uploaded to the GPU, then drawn by the UiRenderPass.

Modules§

interaction
Pointer hit-testing against the laid out UI nodes.
node
Components describing UI nodes: their layout style and how they are drawn.
style
Layout style of UI nodes, following the CSS box model. Converted to taffy’s style when laid out.
text
Text nodes: shaped with cosmic-text for layout, rasterized and drawn with glyphon.

Structs§

UiPlugin
UiRenderPass
Draws the UI on the swapchain, after the scene is resolved and before egui.
UiSystems
Lays out the UI and builds its draw list, in PostUpdate.