### Create a Clickable Button with Bevy Lunex Source: https://docs.rs/bevy_lunex/latest/bevy_lunex This example shows how to spawn a UI root, define button layout and hover states, and attach interactivity using Bevy observers. ```rust // Create UI commands.spawn(( // Initialize the UI root for 2D UiLayoutRoot::new_2d(), // Make the UI synchronized with camera viewport size UiFetchFromCamera::<0>, )).with_children(|ui| { // Spawn a button in the middle of the screen ui.spawn(( Name::new("My Button"), // Specify the position and size of the button UiLayout::window().pos(Rl((50.0, 50.0))).size((200.0, 50.0)).pack(), // When hovered, it will request the cursor icon to be changed OnHoverSetCursor::new(SystemCursorIcon::Pointer), )).with_children(|ui| { // Spawn a child node but with a background ui.spawn(( // You can define layouts for multiple states UiLayout::new(vec![ // The default state, just fill the parent (UiBase::id(), UiLayout::window().full()), // The hover state, grow to 105% of the parent from center (UiHover::id(), UiLayout::window().anchor(Anchor::Center).size(Rl(105.0))) ]), // Enable the hover state and give it some properties UiHover::new().forward_speed(20.0).backward_speed(4.0), // You can specify colors for multiple states UiColor::new(vec![ (UiBase::id(), Color::BEVYPUNK_RED.with_alpha(0.15)), (UiHover::id(), Color::BEVYPUNK_YELLOW.with_alpha(1.0)) ]), // You can attach any form of rendering to the node, be it sprite, mesh or something custom Sprite { image: asset_server.load("images/button.png"), // Here we enable sprite slicing image_mode: SpriteImageMode::Sliced(TextureSlicer { border: BorderRect::all(32.0), ..Default::default() }), ..Default::default() }, // Make sure it does not cover the bounding zone of parent Pickable::IGNORE, )).with_children(|ui| { // Spawn a text child node ui.spawn(( // For text we always use window layout to position it. The size is computed at runtime from text bounds UiLayout::window().pos((Rh(40.0), Rl(50.0))).anchor(Anchor::CenterLeft).pack(), UiColor::new(vec![ (UiBase::id(), Color::BEVYPUNK_RED), (UiHover::id(), Color::BEVYPUNK_YELLOW.with_alpha(1.0)) ]), UiHover::new().forward_speed(20.0).backward_speed(4.0), // Here we specify the text height proportional to the parent node UiTextSize::from(Rh(60.0)), // You can attach text like this Text2d::new("Click me!"), TextFont { font: asset_server.load("fonts/semibold.ttf").into(), font_size: FontSize::Px(64.0), ..Default::default() }, // Make sure it does not cover the bounding zone of parent Pickable::IGNORE, )); }); }) // Utility observers that enable the hover state on trigger .observe(hover_set::, true>) .observe(hover_set::, false>) // Interactivity is done through observers, you can query anything here .observe(|_: On>| { println!("I was clicked!"); }); }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.