You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
959 B
Rust
44 lines
959 B
Rust
use bevy::prelude::*;
|
|
use bevy_mod_picking::prelude::*;
|
|
|
|
fn main() {
|
|
App::new()
|
|
.add_plugins((
|
|
DefaultPlugins,
|
|
DefaultPickingPlugins,
|
|
))
|
|
.add_systems(Startup, init_ui)
|
|
.run();
|
|
}
|
|
|
|
fn init_ui(
|
|
mut commands: Commands,
|
|
) {
|
|
commands.spawn(Camera3dBundle { ..default() });
|
|
|
|
commands.spawn((
|
|
NodeBundle {
|
|
style: Style {
|
|
width: Val::Px(100.0),
|
|
height: Val::Px(100.0),
|
|
top: Val::Px(0.0),
|
|
left: Val::Px(0.0),
|
|
position_type: PositionType::Absolute,
|
|
..default()
|
|
},
|
|
background_color: Color::WHITE.into(),
|
|
..default()
|
|
},
|
|
PickableBundle::default(),
|
|
On::<Pointer<Drag>>::target_component_mut::<Style>(|drag, style| {
|
|
match style.left {
|
|
Val::Px(curr) => style.left = Val::Px(curr + drag.delta.x),
|
|
_ => panic!("Drag UI only applies to Val::Px"),
|
|
}
|
|
match style.top {
|
|
Val::Px(curr) => style.top = Val::Px(curr + drag.delta.y),
|
|
_ => panic!("Drag UI only applies to Val::Px"),
|
|
}
|
|
}),
|
|
));
|
|
} |