Crates.io | bevy_hammer_ui |
lib.rs | bevy_hammer_ui |
version | 0.16.0 |
source | src |
created_at | 2024-12-16 20:03:05.127684+00 |
updated_at | 2025-05-10 15:44:39.457758+00 |
description | Barebones ui widget plugin built for Bevy |
homepage | |
repository | |
max_upload_size | |
id | 1485424 |
size | 136,284 |
A barebones UI framework for bevy, using UiBuilder pattern to retain Command context.
Inspired by SickleUi (basically the most important 2 files from sickle ui)
let root_node = commands
.spawn(Node ::default())
.style()
//style stuff
.id();
let container_node = commands
.ui_builder(root_node)
.container(Node ::default(), |inner| {
inner
.spawn(Node ::default())
.style()
.width(Val::Px(50.0));
})
.style()
.width(Val::Px(100.0))
.id();
impl UiContainerExt for UiBuilder<'_, Entity> {
fn container(
&mut self,
bundle: impl Bundle,
spawn_children: impl FnOnce(&mut UiBuilder<Entity>),
) -> UiBuilder<Entity> {
let mut new_builder = self.spawn(bundle);
spawn_children(&mut new_builder);
new_builder
}
}
struct SetUiStyleWidth(Val);
impl EntityCommand for SetUiStyleWidth {
fn apply(self, entity: Entity, world: &mut World) {
let Some(mut style_comp) = world.get_mut::<Node>(entity) else {
return;
};
style_comp.width = self.0;
}
}
pub trait SetUiStyleWidthExt<'a> {
fn width(&'a mut self, val: Val) -> &mut UiStyle<'a>;
}
impl<'a> SetUiStyleWidthExt<'a> for UiStyle<'a> {
fn width(&'a mut self, val: Val) -> &mut UiStyle<'a> {
self.entity_commands().queue(SetUiStyleWidth(val));
self
}
}