Bevy tracking Latest version MIT/Apache 2.0 Documentation

Cuicui Layout

A dumb layout algorithm you can rely on, built for and with bevy.

The Cyberpunk 2077 showcase

For some reasons, the Cyberpunk main menu has become the 7GUI of bevy, so here is the Cyberpunk main menu using cuicui_layout_bevy_ui.

Code

```rust cmds.spawn((Camera2dBundle::default(), LayoutRootCamera)); let menubuttons = [ "CONTINUE", "NEW GAME", "LOAD GAME", "SETTINGS", "ADDITIONAL CONTENT", "CREDITS", "QUIT GAME", ]; let titlecard = serv.load::("logo.png"); let font = serv.load("adobe_sans.ttf"); let bg = serv.load("background.png"); let board = serv.load("board.png"); let button = serv.load("button.png");

layout! { &mut cmds, row(screenroot, "root", mainmargin 100., alignstart, image &bg) { column("menu", width px 300, fillmainaxis, image &board) { spawnui(titlecard, "Title card", height px 100, width %100); code(let cmds) { for n in &menubuttons { let name = format!("{n} button"); layout!(cmds, spawn_ui(*n, named name, image &button, height px 30);); } } } } } ```

Running examples

Use the cargo run --bin command to list possible examples, and run them.

We do this because it allows us to have different dependencies between examples.

Stability

This crate is in expansion, use at your own risk, it is extremely likely that a lot of things are going to break a lot.

Using cuicui_layout

  1. Chose which crate you want to use:
  2. Add the chosen crate as a dependency to your crate. cargo add cuicui_layout_bevy_ui
  3. Use the [layout!] macro to build a UI (text representation coming soon).
  4. That's it! You are now using cuicui_layout, congratulations! Make sure to check the [LayoutType] docs to learn the current capabilities of cuicui_layout.

Please note that cuicui_layout won't magically make sprite components work in UI nodes.

cuicui_layout crates

This repository contains several crates:

(maybe cuicui_layout_spec in the future)

Cargo features

Why cuicui layout

Why not Flexbox

You are writing text to get 2d visual results on screen. The translation from text to screen should be trivial, easy to do in your head. Otherwise you need visual feedback to get what you want. Bevy, even with hot reloading or [bevy-inspector-egui] will always have extremely slow visual feedback.

Flexbox has too many parameters and depends on implicit properties of UI elements, it is not possible to emulate it in your head.

cuicui's layout in contrast to Flexbox is easy to fit in your head. In fact, I will forecefully push cuicui's layout algorithm in your head in two short bullet points.

That's it. There are some edge cases, but cuicui will ~~yell at you~~ tell you nicely when you hit them and tell you how to handle them properly.

Flexbox FAQ

Q: Where is padding?
A: padding is equivalent to margin in cuicui_layout. margin and border doesn't make conceptual sense.

Q: How do I center a node?
A: Add an empty node at the start and end of the container, and use fill_parent

Q: What is the equivalent of flex_direction?
A: use row and column

Q: What are the equivalents of column-reverse and row-reverse?
A: None. Use Alignment::End and swap your elements! Note that the *-reverse flows in flexbox are very useful for internationalization. However, when making a game, it is not enough to just swap the elements! Artistic control is paramount and internationalization needs to be taken as a whole in the context of the UI.

Q: What is the equivalent of flex_wrap?
A: None, do you really need it?

Q: What is the equivalent of align_item, align_self, align_content, justify_content?
A: After 5 years of working with CSS, I still have no clue which one does what, and whether they really do anything, so I wont' adventure an asnwer.

Q: What is the equivalent of flex_grow, flex_shrink, flex_basis, gap?
A: Do you even know what they do?

Q: Why can't child container overflow their parents?
A: It's likely you didn't expect this, so we report it as an error.

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.