bytestring-net / bevy_lunex

Blazingly fast path based retained layout engine for Bevy entities, built around vanilla Bevy ECS.
https://bytestring-net.github.io/bevy_lunex/
Apache License 2.0
592 stars 24 forks source link
bevy bevy-lunex framework layout lunex rust ui

image

#

Blazingly fast path based retained layout engine for Bevy entities, built around vanilla Bevy ECS. It gives you the ability to make your own custom UI using regular ECS like every other part of your app.

image

image

Try out the live WASM demo on Itch.io or GitHub Pages (Limited performance & stutter due to running on a single thread). For best experience compile the project natively. You can find source code here.

Syntax Example

This is an example of a clickable Button created from scratch using predefined components. As you can see, ECS modularity is the focus here. The library will also greatly benefit from upcoming BSN (Bevy Scene Notation) addition that Cart is working on.

commands.spawn((

    // #=== UI DEFINITION ===#

    // This specifies the name and hierarchy of the node
    UiLink::<MainUi>::path("Menu/Button"),

    // Here you can define the layout using the provided units (per state like Base, Hover, Selected, etc.)
    UiLayout::window().pos(Rl((50.0, 50.0))).size((Rh(45.0), Rl(60.0))).pack::<Base>(),

    // #=== CUSTOMIZATION ===#

    // Give it a background image
    UiImage2dBundle { texture: assets.load("images/button.png"), ..default() },

    // Make the background image resizable
    ImageScaleMode::Sliced(TextureSlicer { border: BorderRect::square(32.0), ..default() }),

    // This is required to control our hover animation
    UiAnimator::<Hover>::new().forward_speed(5.0).backward_speed(1.0),

    // This will set the base color to red
    UiColor<Base>::new(Color::RED),

    // This will set hover color to yellow
    UiColor<Hover>::new(Color::YELLOW),

    // #=== INTERACTIVITY ===#

    // This is required for hit detection (make it clickable)
    PickableBundle::default(),

    // This will change cursor icon on mouse hover
    OnHoverSetCursor::new(CursorIcon::Pointer),

    // If we click on this, it will emmit UiClick event we can listen to
    UiClickEmitter::SELF,
));

Documentation

There is a Lunex book for detailed explanations about the concepts used in Lunex. You can find it here: Bevy Lunex book.

For production ready example/template check out Bevypunk source code.

Versions

Bevy Bevy Lunex
^ 0.14 0.2.0 - 0.2.4
0.13.2 0.1.0
0.12.1 0.0.10 - 0.0.11
0.12.0 0.0.7 - 0.0.9
0.11.2 0.0.1 - 0.0.6

Any version below 0.0.X is EXPERIMENTAL and is not intended for practical use

Contributing

Any contribution submitted by you will be dual licensed as mentioned below, without any additional terms or conditions. If you have the need to discuss this, please contact me.

Licensing

Released under both APACHE and MIT licenses. Pick one that suits you the most!