diff --git a/examples/simple.rs b/examples/simple.rs index 789b3a7..49d3454 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -1,4 +1,4 @@ -use bevy::{input::mouse::MouseMotion, prelude::*, ui::Interaction}; +use bevy::{prelude::*}; use bevy_inspector_egui::quick::WorldInspectorPlugin; use bevy_simple_scroll_view::*; @@ -39,7 +39,7 @@ fn add_content(mut commands: Commands, q: Query commands.entity(e).with_children(|parent| { for _ in 0..10 { parent.spawn( - (NodeBundle { + NodeBundle { style: Style { width: Val::Px(200.0), height: Val::Px(200.0), @@ -51,25 +51,9 @@ fn add_content(mut commands: Commands, q: Query border_color: BORDER_COLOR_ACTIVE.into(), background_color: BACKGROUND_COLOR.into(), ..default() - }), + }, ); } }); } } - -fn input_mouse_scroll( - mut motion_evr: EventReader, - mut q: Query<(Entity, &mut Style, &Interaction), With>, -) { - for evt in motion_evr.read() { - for (e, mut style, &interaction) in q.iter_mut() { - if interaction == Interaction::Hovered { - style.top = match style.top { - Val::Px(px) => Val::Px(px + evt.delta.y), - _ => Val::Px(0.0), - } - } - } - } -} diff --git a/src/lib.rs b/src/lib.rs index 148ea0a..76aa7a9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,7 @@ impl Plugin for ScrollViewPlugin { app.register_type::() .register_type::() .register_type::() - .add_systems(Update, (create_scroll_view, input_mouse_scroll)); + .add_systems(Update, (create_scroll_view, input_mouse_pressed_move)); } } @@ -33,6 +33,7 @@ pub fn create_scroll_view(mut commands: Commands, q: Query, mut q: Query<(Entity, &mut Style, &Interaction), With>, ) { for evt in motion_evr.read() { - for (e, mut style, &interaction) in q.iter_mut() { - if interaction == Interaction::Hovered { + info!("{:?}", evt); + for (_e, mut style, &interaction) in q.iter_mut() { + if interaction == Interaction::Pressed { style.top = match style.top { Val::Px(px) => Val::Px(px + evt.delta.y), _ => Val::Px(0.0),