Update scrollViewContent margin, not ScrollView
This commit is contained in:
parent
e548a5317f
commit
7430156394
|
|
@ -1,4 +1,4 @@
|
|||
use bevy::{prelude::*};
|
||||
use bevy::prelude::*;
|
||||
use bevy_inspector_egui::quick::WorldInspectorPlugin;
|
||||
use bevy_simple_scroll_view::*;
|
||||
|
||||
|
|
@ -38,8 +38,7 @@ fn add_content(mut commands: Commands, q: Query<Entity, Added<ScrollViewContent>
|
|||
for e in q.iter() {
|
||||
commands.entity(e).with_children(|parent| {
|
||||
for _ in 0..10 {
|
||||
parent.spawn(
|
||||
NodeBundle {
|
||||
parent.spawn(NodeBundle {
|
||||
style: Style {
|
||||
width: Val::Px(200.0),
|
||||
height: Val::Px(200.0),
|
||||
|
|
@ -51,8 +50,7 @@ fn add_content(mut commands: Commands, q: Query<Entity, Added<ScrollViewContent>
|
|||
border_color: BORDER_COLOR_ACTIVE.into(),
|
||||
background_color: BACKGROUND_COLOR.into(),
|
||||
..default()
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
12
src/lib.rs
12
src/lib.rs
|
|
@ -59,12 +59,17 @@ pub fn create_scroll_view(mut commands: Commands, q: Query<Entity, Added<ScrollV
|
|||
|
||||
fn input_mouse_pressed_move(
|
||||
mut motion_evr: EventReader<MouseMotion>,
|
||||
mut q: Query<(Entity, &mut Style, &Interaction), With<ScrollViewport>>,
|
||||
mut q: Query<(&Children, &Interaction), With<ScrollViewport>>,
|
||||
mut content_q: Query<&mut Style, With<ScrollViewContent>>,
|
||||
) {
|
||||
for evt in motion_evr.read() {
|
||||
info!("{:?}", evt);
|
||||
for (_e, mut style, &interaction) in q.iter_mut() {
|
||||
if interaction == Interaction::Pressed {
|
||||
for (children, &interaction) in q.iter_mut() {
|
||||
if interaction != Interaction::Pressed {
|
||||
continue;
|
||||
}
|
||||
for &child in children.iter() {
|
||||
if let Ok(mut style) = content_q.get_mut(child) {
|
||||
style.top = match style.top {
|
||||
Val::Px(px) => Val::Px(px + evt.delta.y),
|
||||
_ => Val::Px(0.0),
|
||||
|
|
@ -72,6 +77,7 @@ fn input_mouse_pressed_move(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn scroll_events(
|
||||
|
|
|
|||
Loading…
Reference in New Issue