Crate cuicui_layout_bevy_ui

Source
Expand description

Make cuicui_layout useable with bevy’s UI library (bevy_ui).

Import this crate’s UiDsl and use cuicui_dsl::dsl! with it to have a fully working UI library.

It contains:

Note that unlike cuicui_layout_bevy_ui, this uses a Y axis down coordinate space, (like bevy_sprite)

Therefore, if you happen to convert your layouts from bevy_ui to bevy_sprite (or vis-versa) what was on top will be at the bottom and vis-versa.

§Example

use bevy::prelude::*;
use cuicui_layout::{dsl, LayoutRootCamera, Rule};
// dsl! will use this crate's extensions to DslBundle
// if you import this      vvvvvvvvvvvv
use cuicui_layout_bevy_ui::UiDsl as Dsl;
use cuicui_layout::dsl_functions::{px, pct};

cmds.spawn((Camera2dBundle::default(), LayoutRootCamera));

let title_card = serv.load::<Image>("logo.png");
let menu_buttons = [ "CONTINUE", "NEW GAME" ];
let bg = serv.load("background.png");
let board = serv.load("board.png");
let button = serv.load("button.png");

dsl! {
    &mut cmds.spawn_empty(),
    // Notice the `image` argument                     vvvvvvvvvv
    Root(row screen_root main_margin(100.) align_start image(&bg)) {
        Menu(column width(px(310)) main_margin(40.) fill_main_axis image(&board)) {
            TitleCard(ui(title_card) height(px(100)) width(pct(100)))
            code(let cmds) {
                for n in &menu_buttons {
                    let name = format!("{n} button");
                    dsl!(cmds, Entity(ui(*n) named(name) image(&button) height(px(30))))
                }
            }
        }
    }
};

Re-exports§

pub use dsl::UiDsl;

Modules§

content_sized
Systems to update a cuicui_layout::Node’s size based on an image’s and text’s size, rather that fixed at spawn time.
dsl
Bundles wrapping bevy::ui::node_bundles with additional cuicui_layout components.

Structs§

Plugin
Plugin managing position and size of UI elements using cuicui_layout components.

Functions§

set_added_camera_root
System setting the size of newly added ScreenRoot nodes.
set_layout_style
Set the Style’s {min_,max_,}size.{width,height} and position.{left,right} according to LayoutRect’s computed from cuicui_layout.
update_ui_camera_root
System updating the ScreenRoot cuicui_layout::Node with the LayoutRootCamera’s viewport size, whenever it changes.