bevy-ui
Skill16 starsChanged 3 months agoMITView on GitHub
Use when building Bevy 0.19 UI with `Node`, `Button`, `children![]`, `TextFont`/`FontSource`/`FontSize`, `InputFocus`, `AccessibleLabel`, `BackgroundColor`, `BorderColor`, or `BorderRadius`, or when `Changed<Interaction>` behaves unexpectedly.
In this repository33 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- bevy-a11ySkill
- bevy-animationSkill
- bevy-assetsSkill
- bevy-audioSkill
- bevy-camerasSkill
- bevy-captureSkill
- bevy-cargo-featuresSkill
- bevy-core-conceptsSkill
- bevy-custom-assetsSkill
- bevy-diagnostics-profilingSkill
- bevy-ecs-componentsSkill
- bevy-ecs-queriesSkill
- bevy-ecs-systemsSkill
- bevy-fluentSkill
- bevy-input-actionsSkill
- bevy-migration-0-17-to-0-18Skill
- bevy-migration-0-18-to-0-19Skill
- bevy-pbr-materialsSkill
- bevy-physicsSkill
- bevy-portingSkill
- bevy-renderingSkill
- bevy-save-loadSkill
- bevySkill
- bevy-testingSkill
- bevy-vfxSkill
- bevy-voxel-dataSkill
- bevy-voxel-pipelineSkill
- bevy-voxel-runtimeSkill
- bevy-wasm-webgpuSkill
- similarity-rsSkill
The file
Files
Bevy 0.19 — UI
When to use this skill
- Spawn
Node-based panels, buttons, labels, overlays, or menus. - Handle
Interaction::{None, Hovered, Pressed}and visual states. - Style text after the 0.19 Parley migration.
- Manage pointer-acquired
InputFocusor accessible names. - Build static trees with
children![]or dynamic trees withwith_children.
Canonical pattern
use bevy::{
input_focus::{FocusCause, InputFocus},
prelude::*,
};
fn main() {
App::new()
.add_plugins(DefaultPlugins) // includes InputFocusPlugin in 0.19
.add_systems(Startup, setup)
.add_systems(Update, style_button)
.run();
}
fn setup(mut commands: Commands, assets: Res<AssetServer>) {
commands.spawn(Camera2d);
commands.spawn((
Node {
width: percent(100),
height: percent(100),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
..default()
},
children![(
Button,
AccessibleLabel::new("Start game"),
Node {
width: px(180),
height: px(64),
border: UiRect::all(px(3)),
border_radius: BorderRadius::MAX,
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
..default()
},
BackgroundColor(Color::srgb(0.12, 0.12, 0.15)),
BorderColor::all(Color::WHITE),
children![(
Text::new("Start game"),
TextFont {
font: assets.load("fonts/FiraSans-Bold.ttf").into(),
font_size: FontSize::Px(32.0),
..default()
},
TextColor(Color::WHITE),
)],
)],
));
}
fn style_button(
mut focus: ResMut<InputFocus>,
mut buttons: Query<
(Entity, &Interaction, &mut BackgroundColor),
(Changed<Interaction>, With<Button>),
>,
) {
for (entity, interaction, mut background) in &mut buttons {
*background = match interaction {
Interaction::Pressed => {
focus.set(entity, FocusCause::Pressed);
BackgroundColor(Color::srgb(0.15, 0.55, 0.25))
}
Interaction::Hovered => BackgroundColor(Color::srgb(0.22, 0.22, 0.28)),
Interaction::None => BackgroundColor(Color::srgb(0.12, 0.12, 0.15)),
};
}
}Topics
| Topic | Reference |
Node, Val, flex/grid layout | Layout |
FontSource, FontSize, TextLayout | Text |
Button, Interaction, Changed | Interaction |
| Colors, borders, and radii | Colors and borders |
| Palette constants | Palettes |
InputFocus, semantics, accessible labels | Accessibility |
| Static and dynamic children | Children |
| Cross-cutting traps | Gotchas |
Gotchas
- A newly inserted component satisfies
Changed<T>. The interaction system normally visits a new button on its firstUpdate; useRef<T>::is_added()when insertion and later mutation must be distinguished. - Pointer hover and input focus are different. Do not move or clear keyboard / assistive-technology focus merely because the cursor entered or left.
TextFont.fontisFontSource; convert aHandle<Font>with.into().font_sizeisFontSize, such asFontSize::Px(32.0).InputFocusfields are private. Useget,set(entity, FocusCause), andclear.DefaultPluginsinitializes it.- A visible text child gives a
Buttonan inferred name, but useAccessibleLabelwhen the visual text is absent, decorative, or ambiguous.
See also
bevy-a11y— full game accessibility implementation.bevy-fluent— localized UI text.bevy-cameras— UI cameras and render targets.bevy-ecs-queries— change detection.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

