A novel path-based approach to UI built on top of existing Bevy features

Overview

Bevy Lunex

A novel path-based approach to UI built on top of existing Bevy features.

image A recreation of Cyberpunk 2077 menu in Bevy using Lunex

Table of Contents

Description

Bevy_Lunex is an UI framework expanding on top of existing Bevy ECS features. It's purpose is to allow the developer to precisely define the behavior of widgets when window is being resized. It's focus is on simlicity and the speed with how fast you can achieve AAA level UI. It achieves this by adding layout capabilites to vanilla entities so you can use them as UI elements. It uses a path-based hierarchy to manage UI widgets. Pointers to these widgets are then passed to entities as components.

#ROOT
  |-> Main menu
  |    |-> Wallpaper
  |    |    |-> Background
  |    |-> Board widget
  |    |    |-> Logo
  |    |    |    |-> Logo Shadow
  |    |    |-> Button List
  |    |    |    |-> Continue
  |    |    |    |-> New Game
  |    |    |    |-> Load_Game
  |    |    |    |-> Settings
  |    |    |    |-> Credits
  |    |    |    |-> Additional Content
  |    |    |    |-> Quit Game

Usage

First create a hierarchy struct that will hold all the recursive logic.

let mut system = Hierarchy::new();

To create a new widget in root directory you pass in the hierarchy, specify widget properties and the function returns a pointer.

let widget_pointer = Widget::new(&mut system, "widget", Layout::Relative {
    relative_1: Vec2 { x: 0.0, y: 0.0 },
    relative_2: Vec2 { x: 100.0, y: 100.0 },
    ..Default::default()
}.wrap()).unwrap();

Once you have the pointer created you can pass the pointer to an entity as component to create interactive UI element. Here we add image to the widget.

commands.spawn ((
    widget_pointer,
    ImageInfo {
        width: 1920.0,
        height: 1080.0,
    },
    SpriteBundle {
        texture: asset_server.load("image.png"),
        sprite: Sprite {
            anchor: Anchor::TopLeft,
            ..default()
        },
        ..default()
    }
));

To add logic to your UI elements, you use classic bevy system and query for your widgets. This function for example updates the position of an entity with image to match the calculated layout.

pub fn image_update(mut systems: Query<&mut Hierarchy>, mut query: Query<(&mut Widget, &ImageInfo, &mut Transform)>) {

    let mut system = systems.get_single_mut().unwrap();

    for (widget, imageinfo, mut transform) in &mut query {

        let dimensions = (system.width, system.height);
        let pos = widget.fetch_position(&mut system, "").unwrap(); //The widget will locate itself inside the hierarchy

        transform.translation.x = pos.point_1.x - dimensions.0/2.0;
        transform.translation.y = pos.point_2.y - dimensions.1/2.0;
        transform.scale.x = pos.width/imageinfo.width;
        transform.scale.y = pos.height/imageinfo.height;
    }
}

There are multiple layout options to choose from. With their combination and smart mixing user is able to define precisely how the layout should behave.

image

License

License

You might also like...
Minecraft-esque voxel engine prototype made with the bevy game engine. Pending bevy 0.6 release to undergo a full rewrite.
Minecraft-esque voxel engine prototype made with the bevy game engine. Pending bevy 0.6 release to undergo a full rewrite.

vx_bevy A voxel engine prototype made using the Bevy game engine. Goals and features Very basic worldgen Animated chunk loading (ala cube world) Optim

bevy-hikari is an implementation of voxel cone tracing global illumination with anisotropic mip-mapping in Bevy
bevy-hikari is an implementation of voxel cone tracing global illumination with anisotropic mip-mapping in Bevy

Bevy Voxel Cone Tracing bevy-hikari is an implementation of voxel cone tracing global illumination with anisotropic mip-mapping in Bevy. Bevy Version

A simple extension for `bevy-editor-pls` to support tilemap editing right inside the bevy app.

What is this This is a simple tilemap editor plugin, that hooks right into bevy_editor_pls to work with bevy_ecs_tilemap. It works completely within i

Bevy Simple Portals is a Bevy game engine plugin aimed to create portals.
Bevy Simple Portals is a Bevy game engine plugin aimed to create portals.

Portals for Bevy Bevy Simple Portals is a Bevy game engine plugin aimed to create portals. Those portals are (for now) purely visual and can be used t

Minecraft using Bevy and Bevy-Meshem

minecraft_bevy Minecraft_bevy was built to showcase bevy_meshem. After a week of developing it has: Chunk loading / unloading each chunk's mesh is bei

An alternative ggez implementation on top of miniquad.
An alternative ggez implementation on top of miniquad.

Good Web Game good-web-game is a wasm32-unknown-unknown implementation of a ggez subset on top of miniquad. Originally built to run Zemeroth on the we

Bevy is a refreshingly simple data-driven game engine built in Rust

What is Bevy? Bevy is a refreshingly simple data-driven game engine built in Rust. It is free and open-source forever! WARNING Bevy is still in the ve

Work-in-Progress, opinionated game framework built on Bevy.

Bones A work-in-progress, opinionated game meta-engine built on Bevy. Under development for future use in the Jumpy game, and possibly other FishFolk

📺 An implementation of the retro bouncing DVD logo screensaver animation built with bevy and rust
📺 An implementation of the retro bouncing DVD logo screensaver animation built with bevy and rust

📺 Bevy bouncing DVD logo This project is a simple demonstration of using the Bevy game engine and the Rust programming language to create a bouncing

Owner
Bytestring
Bytestring
Bevy plugin for an AssetServer that can load embedded resources, or use other AssetServers based on the path.

Bevy-Embasset Embed your asset folder inside your binary. bevy-embasset adds support for loading assets embedded into the binary. Furthermore, it can

Johnny Tidemand Vestergaard 9 Aug 4, 2022
A visual novel engine that draws inspiration from RenPy and is meant to be a more performant replacement with feature parity.

VN Engine A visual novel engine that draws inspiration from RenPy and is meant to be a more performant replacement with feature parity. The engine is

Alexandros Panagiotakis 2 Sep 9, 2022
A visual novel engine that draws inspiration from RenPy and is meant to be a more performant replacement with feature parity.

VN Engine A visual novel engine that draws inspiration from RenPy and is meant to be a more performant replacement with feature parity. The engine is

Alexandros Panagiotakis 2 Sep 9, 2022
A 2d top-down shooter written in Bevy, capable of handling 100K enemies

Bevy 2D Shooter This is a 2d top-down shooter written in Rust using the Bevy game engine. It's capable of handling 100K enemies and uses a kd-tree to

Bones-ai 41 Jul 21, 2024
Scion is a tiny 2D game library built on top of wgpu, winit and legion.

Scion is a 2D game library made in rust. Please note that this project is in its first milestones and is subject to change according to convience need

Jérémy Thulliez 143 Dec 25, 2022
3d transformation gizmo built on top of the egui library.

egui-gizmo 3d transformation gizmo built on top of the egui library. Try it out in a web demo Usage let gizmo = Gizmo::new("My gizmo") .view_matri

Urho Laukkarinen 69 Dec 10, 2022
General purpose client/server networking library written in Rust, built on top of the QUIC protocol which is implemented by quinn

Overview "This library stinks!" ... "Unless you like durian" durian is a client-server networking library built on top of the QUIC protocol which is i

Michael 92 Dec 31, 2022
A velocity-based falling sand simulation built with Rust and Bevy

⏳ Bevy Falling Sand A velocity-based falling sand simulation built with Rust and Bevy! This simluation uses bevy_rapier to generate colliders that reg

Tomato 7 Oct 30, 2023
The study of a simple path tracer implementation (image raytracing in shorts)

The study of a simple path tracer implementation (generate a raytraced image, in shorts).

Leonardo Vieira 1 Apr 2, 2022
2D and 3D physics engine based on Extended Position Based Dynamics for Bevy.

Bevy XPBD Bevy XPBD is a 2D and 3D physics engine based on Extended Position Based Dynamics (XPBD) for the Bevy game engine. Design Below are some of

Joona Aalto 203 Jul 6, 2023