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_inspector_egui::quick::WorldInspectorPlugin;
|
||||||
use bevy_simple_scroll_view::*;
|
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() {
|
for e in q.iter() {
|
||||||
commands.entity(e).with_children(|parent| {
|
commands.entity(e).with_children(|parent| {
|
||||||
for _ in 0..10 {
|
for _ in 0..10 {
|
||||||
parent.spawn(
|
parent.spawn(NodeBundle {
|
||||||
NodeBundle {
|
|
||||||
style: Style {
|
style: Style {
|
||||||
width: Val::Px(200.0),
|
width: Val::Px(200.0),
|
||||||
height: 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(),
|
border_color: BORDER_COLOR_ACTIVE.into(),
|
||||||
background_color: BACKGROUND_COLOR.into(),
|
background_color: BACKGROUND_COLOR.into(),
|
||||||
..default()
|
..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(
|
fn input_mouse_pressed_move(
|
||||||
mut motion_evr: EventReader<MouseMotion>,
|
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() {
|
for evt in motion_evr.read() {
|
||||||
info!("{:?}", evt);
|
info!("{:?}", evt);
|
||||||
for (_e, mut style, &interaction) in q.iter_mut() {
|
for (children, &interaction) in q.iter_mut() {
|
||||||
if interaction == Interaction::Pressed {
|
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 {
|
style.top = match style.top {
|
||||||
Val::Px(px) => Val::Px(px + evt.delta.y),
|
Val::Px(px) => Val::Px(px + evt.delta.y),
|
||||||
_ => Val::Px(0.0),
|
_ => Val::Px(0.0),
|
||||||
|
|
@ -73,6 +78,7 @@ fn input_mouse_pressed_move(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn scroll_events(
|
fn scroll_events(
|
||||||
mut scroll_evr: EventReader<MouseWheel>,
|
mut scroll_evr: EventReader<MouseWheel>,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue