UI
Build menus, HUDs and tools with the NEO engine's UI: nodes laid out with flexbox and grid, text, images, buttons, focus and navigation, widgets and scrolling.
The engine's UI is made of ordinary entities. Each piece of interface is an entity with a Node component, nested with the same parent and child hierarchy as the rest of the world. Layout follows the web's flexbox and CSS grid rules, so if you've written CSS, most of it carries over.
UI is drawn on top of a camera's view, in screen space: it doesn't move with the world. It's part of the ui profile, which NEO's builds turn on by default, and it runs on every platform NEO supports, including the browser and phones.
A first interface#
use neo::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.run();
}
fn setup(mut commands: Commands) {
// UI is drawn over a camera's view; any 2D or 3D camera works
commands.spawn(Camera2d);
commands.spawn((
Node {
width: percent(100),
height: percent(100),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
..default()
},
children![(
Node { padding: px(16).all(), ..default() },
BackgroundColor(Color::srgb(0.1, 0.1, 0.15)),
children![Text::new("Paused")],
)],
));
}How it fits together#
| Piece | What it is | Page |
|---|---|---|
Node | A box: size, position, spacing and how its children are laid out. | Nodes and layout |
Display::Grid | Two-dimensional layouts with rows and columns. | Grid layout |
Text, TextSpan | Text inside the interface. | UI text |
ImageNode, BackgroundColor, BorderColor, BoxShadow | How a node looks. | Images and styling |
Button, Hovered, Pressed, pointer events | Reacting to the mouse and touch. | Interaction |
InputFocus, TabIndex, directional navigation | Keyboard and gamepad navigation. | Focus and navigation |
| Sliders, checkboxes, text inputs, menus | Ready-made widget behaviour. | Widgets |
Overflow, ScrollPosition, ScrollArea | Clipping and scrolling. | Scrolling and overflow |
In NEO games#
NEO's on-screen touch controls (in the input kit) for phones are built with these same UI nodes. The widgets in neo_ui_widgets are behaviour only, with no built-in look, so your game decides how everything is styled. The engine core also has a styled widget set, neo_feathers, used by some engine examples; it needs the neo_feathers cargo feature, which isn't on in NEO's default builds.