From 21f33590773bc0b5086cd569de8eee1b1fa833cb Mon Sep 17 00:00:00 2001 From: demenik Date: Tue, 9 Dec 2025 13:29:18 +0100 Subject: [PATCH] feat: Add context menu UI element --- src/features/ui/ui/popups.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/features/ui/ui/popups.rs b/src/features/ui/ui/popups.rs index dedc8af..34a7bde 100644 --- a/src/features/ui/ui/popups.rs +++ b/src/features/ui/ui/popups.rs @@ -15,7 +15,7 @@ pub fn spawn_popup( title: impl Into, mut node: Node, child: impl FnOnce(&mut RelatedSpawnerCommands), -) -> impl Bundle { +) { node.flex_direction = FlexDirection::Column; node.row_gap = px(10); 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), +) { + 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( mut commands: Commands, root_query: Query>,