Drag and drop proof of concept
parent
a787e0e6c3
commit
f03876bdce
@ -0,0 +1,44 @@
|
|||||||
|
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"),
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
));
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue