feat: Add context menu UI element

This commit is contained in:
demenik
2025-12-09 13:29:18 +01:00
parent d9a1c9c2a7
commit 21f3359077

View File

@@ -15,7 +15,7 @@ pub fn spawn_popup(
title: impl Into<String>, title: impl Into<String>,
mut node: Node, mut node: Node,
child: impl FnOnce(&mut RelatedSpawnerCommands<ChildOf>), child: impl FnOnce(&mut RelatedSpawnerCommands<ChildOf>),
) -> impl Bundle { ) {
node.flex_direction = FlexDirection::Column; node.flex_direction = FlexDirection::Column;
node.row_gap = px(10); node.row_gap = px(10);
node.padding = UiRect::all(px(20)); node.padding = UiRect::all(px(20));
@@ -68,6 +68,31 @@ pub fn spawn_popup(
}); });
} }
pub fn spawn_context_menu(
commands: &mut Commands,
root: impl Component,
position: Vec2,
child: impl FnOnce(&mut RelatedSpawnerCommands<ChildOf>),
) {
commands
.spawn((
PopupRoot,
root,
Node {
position_type: PositionType::Absolute,
left: px(position.x),
top: px(position.y),
padding: UiRect::all(px(5)),
..Node::vstack(px(5))
},
ZIndex(100),
BackgroundColor(Color::srgb(0.1, 0.1, 0.1)),
BorderRadius::all(px(5)),
GlobalTransform::default(),
))
.with_children(child);
}
pub fn handle_popup_close( pub fn handle_popup_close(
mut commands: Commands, mut commands: Commands,
root_query: Query<Entity, With<PopupRoot>>, root_query: Query<Entity, With<PopupRoot>>,