A light-weight Anchor-Offset based 2D sprite rendering system for the bevy engine.

Overview

Bevy AoUI

Crates.io Docs

A light-weight anchor-offset based 2D sprite layout system for the bevy engine.

Bevy AoUI provides a light-weight rectangular anchor-offset based 2D sprite layout, UI layout and skeletal animation system.

Similar to the philosophy of Rust, AoUI provides low level control through the anchor-offset system and high level ergonomics through its layout system.

Getting Started

Before you start you should check out bevy_aoui_widgets's examples if you like shapes or DSL.

First add the AoUI Plugin:

app.add_plugins(AoUIPlugin)

Create a sprite:

commands.spawn(AoUISpriteBundle {
    sprite: Sprite { 
        color: Color::RED,
        ..Default::default()
    },
    transform: Transform2D { 
        center: Some(Anchor::Center),
        anchor: Anchor::TopCenter,
        offset: Vec2::new(20.0, 0.0),
        rotation: 1.21,
        scale: Vec2::new(4.0, 1.0),
        ..Default::default()
    },
    dimension: Dimension::pixels(Vec2::new(50.0, 50.0)),
    texture: assets.load("sprite.png"),
    ..Default::default()
});

Create some text:

commands.spawn(AoUITextBundle {
    text: Text::from_section(
        "Hello, World!!", 
        style(Color::WHITE)
    ),
    font: assets.load::<Font>("OpenSans.ttf"),
    transform: Transform2D { 
        center: Some(Anchor::Center),
        anchor: Anchor::TopCenter,
        offset: Vec2::new(20.0, 0.0),
        rotation: 1.21,
        scale: Vec2::new(4.0, 1.0),
        ..Default::default()
    },
    dimension: Dimension::COPIED.with_em(SetEM::Pixels(24.0)),
    ..Default::default()
});

If you don't like the verbosity, check out the DSL in bevy_aoui_widgets:

button! ((commands, assets) {
    dimension: size2!([12 em, 2 em]),
    font_size: em(2),
    hitbox: Rect(1),
    cursor: CursorIcon::Hand,
    child: rectangle!{
        dimension: size2!([100%, 100%]),
        fill: color!(blue500),
    },
    child: textbox!{
        text: "Click Me!",
        color: color!(gold),
        z: 0.1
    },
    extra: handler!{LeftClick => fn click_handler() {
        println!("Hello!")
    }},
});

Core Concepts

AoUI offers a refreshingly different paradigm from traditional CSS based UI layout.

AoUI Sprites contains these core components:

  • anchor
  • center
  • offset
  • rotation
  • scale
  • dimension

Each sprite is conceptualized as a rectangle with a dimension and 9 anchors: BottomLeft, CenterRight, Center, etc.

Custom anchors can be used but not in some layouts.

Sprites are connected to parent sprites via one of the parent's anchors and can be offset by a Vec2. When the offset is set to (0, 0), the anchors of the parent and child sprites overlap.

In the case of parentless sprites, they are anchored to the window's rectangle.

When applying rotation and scale, sprites can use a center that operates independently from the anchor.

Container

Anchor-Offset is well-suited for isolated UI components, but when it comes to arranging multiple UI elements in a specific order, you'll find the Container useful.

The Container is a layout system that only depands on insertion order and works with Bevy's Children component.

Check out the book for more information.

Advantages of AoUI

There are many awesome UI libraries in the bevy ecosystem that you should definitely use over AoUI in many use cases. However, AoUI offers some unique advantages:

  • Full ECS support with easy feature composition.

AoUI is built fully embracing bevy's ecosystem. You can mix and match our modularized components and add, remove or edit any system you want to change.

  • Relative size system.

Full support for web like size units: em, rem, %, etc.

  • First class rotation and scaling support.

You are can rotate and scale any sprite from any position on it with ease.

  • Simple but versatile layout system.

Simple layouts that work out of the box with minimal configuration.

  • High level abstractions with low level control.

You can mix and match anchoring and layouts to best suit your needs.

FAQ

What about the widgets?

bevy_aoui is a layout system, not a widget library. Implementations of most AoUI widgets will live outside of the main crate, like in bevy_aoui_widgets.

bevy_aoui_widgets is a lot more experimental and subject to more changes than bevy_aoui. Checkout our examples for simple widget implementations.

AoUI is commited to not have a standard look and not interacting with the render pipeline as much as possible, therefore the standard widgets might not be an out-of-the-box solution for you.

Where about the performance?

bevy_aoui is an ergonomic focused crate with some performance tradeoffs, each sprite has to go through multiple steps of rotation and scaling compared to traditional rendering. Currently performance optimization features like no_rotation are removed for API consistancy, this might change in the future if the api become more stablized.

Performance related pull requests and suggestions are welcome.

Showcase

  • Skeletal Animation

Spiral

  • Rich Text with the paragraph layout.

Paragraph

  • The compact and span layout.

Layouts

  • Single line text input.

Edit1 Edit2

Bevy Versions

bevy bevy_aoui bevy_aoui_widgets
0.12 0.1 0.1

TODOs

  • Scissor rect, very important for scrolling support.
  • Official TextureAtlasSprite widget.
  • Rich text implementation. (String to entities as children of the Paragraph layout.)
  • Atlas/skeletal animation asset importer.
You might also like...
Hanabi — a particle system plugin for the Bevy game engine.

Hanabi — a particle system plugin for the Bevy game engine

An atomic save/load system for Bevy Game Engine.

☢️ Bevy Atomic Save An atomic save/load system for Bevy. Features Save and load a World into a RON file on disk Control which entities should particip

🎆 CPU-driven, batch-rendered particle system for the Bevy game engine.
🎆 CPU-driven, batch-rendered particle system for the Bevy game engine.

Bevy Firework 🎆 Bevy firework is a particle system plugin where particles are simulated on the CPU and use GPU batching for rendering. This allows ea

A physics lib for the bevy game engine based on physme

physimple Physimple aims to be the simplest(and capable) physics engine(currently for bevy) WARNING Beware for breaking changes with each update for n

Action-based animation system for Bevy.

bevy_action_animation Action-based animation system for Bevy. Introduction This plugin provides users of the Bevy game engine with an action/trigger-b

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

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

grr and rust-gpu pbr rendering
grr and rust-gpu pbr rendering

grr-gltf Barebone gltf viewer using grr and rust-gpu. Currently only supports a single gltf model! Assets These files need to be downloaded and placed

Owner
Mincong Lu
Rust enthusiast, hobbyist game dev.
Mincong Lu
Manage light-weight sandbox environments for development

Cubicle development container manager Cubicle is a program to manage containers or sandbox environments. It is intended for isolating development envi

Diego Ongaro 8 Nov 29, 2022
A sprite-sheet animation plugin for bevy

Benimator A sprite sheet animation plugin for bevy Features A SpriteSheetAnimation component to automatically update the indices of the TextureAtlasSp

Jonathan Cornaz 140 Dec 27, 2022
Explicitly set sprite layers for sprites in Bevy games.

extol_sprite_layer lets you specify the drawing order for sprites in your Bevy game using a separate component rather than via the z-coordinate of you

Ash 5 May 2, 2023
Proof-of-concept of getting OpenXR rendering support for Bevy game engine using gfx-rs abstractions

Introduction Proof-of-concept of getting OpenXR rendering support for Bevy game engine using gfx-rs abstractions. (hand interaction with boxes missing

Mika 52 Nov 14, 2022
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

Lucas Arriesse 125 Dec 31, 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
A tilemap rendering crate for bevy which is more ECS friendly.

bevy_ecs_tilemap A tilemap rendering plugin for bevy which is more ECS friendly by having an entity per tile. Features A tile per entity Fast renderin

John 414 Dec 30, 2022
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

Sélène Amanita 11 May 28, 2023
Self Study on developing a game engine using wgpu as the rendering API. Learning as I go.

Fabled Engine Any issues, enhancement, features, or bugs report are always welcome in Issues. The obj branch is where frequent development and up to d

Khalid 20 Jan 5, 2023
Vulkan and Rust rendering~game engine which creation is covered with YouTube videos

Vulkan and Rust rendering~game engine which creation is covered with YouTube videos

小鳥 11 Dec 4, 2022