#bevy-ui #ui-component #component #bevy #ui

bevy_ui_bits

A mingy and opinionated collection of UI components for Bevy

3 releases (breaking)

0.3.0 Jul 12, 2023
0.2.0 Mar 7, 2023
0.1.0 Feb 21, 2023

#848 in Game dev

MIT/Apache

29KB
437 lines

BEVY UI BITS

crates.io license

A mingy and opinionated collection of UI components for Bevy

Usage

use bevy::prelude::*;
use bevy_ui_bits::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_startup_system(spawn_ui)
        .run();
}

fn spawn_ui(mut commands: Commands, asset_server: Res<AssetServer>) {
    commands.spawn(Camera2dBundle::default());

    let font = &asset_server.load("fonts/FiraMono-Medium.ttf");

    // Root is the encompassing component for a given UI tree
    let root = Root::congregated();

    // Container is the quintessential layout component
    let mut main_container = Container::height(400.0);

    // EmbossedText represents text with a background relief
    let mut title = EmbossedText::large("My Game", font);

    // UiButton wraps over a ButtonBundle with opinionated defaults
    let mut play = UiButton::new("Start", font);

    let by = SimpleText::small("By me", font);

    // Make changes to the properties with a fluent interface
    main_container.justify_between();
    title.color(Color::MIDNIGHT_BLUE);
    play.selected_color(Color::MIDNIGHT_BLUE);

    // Use a nested structure to spawn the UI tree
    root.spawn(&mut commands, |parent| {
        main_container.spawn(parent, |parent| {
            title.spawn(parent);
            play.spawn(parent);
            by.spawn(parent);
        });
    });
}

Examples

Basic main menu UI that supports both mouse and keyboard input

main_menu

Try it out with:

cargo run --example main_menu --features="bevy/default"

Simple HUD that features a dynamic text component

hud

Try it out with:

cargo run --example hud --features="bevy/default"

Despawn UI recursively with the RootMarker

despawn

Try it out with:

cargo run --example despawn --features="bevy/default"

Bevy Compatibility

bevy bevy_ui_bits
0.11 0.3
0.10 0.2
0.9 0.1

License

This project is dual-licensed under either:

at your option.

With the exception of the Fira Mono Font, which has its own license.

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.

Dependencies

~38–72MB
~1M SLoC