diff --git a/examples/simple.rs b/examples/simple.rs index efa8128..295ddd5 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -13,7 +13,7 @@ fn main() { WorldInspectorPlugin::new(), )) .add_systems(Startup, prepare) - .add_systems(Update, add_content) + .add_systems(Update, (add_content, reset_scroll)) .run(); } @@ -32,6 +32,21 @@ fn prepare(mut commands: Commands) { ..default() }) .with_children(|p| { + p.spawn(ButtonBundle { + style: Style { + margin: UiRect::all(Val::Px(5.0)), + padding: UiRect::all(Val::Px(5.0)), + ..default() + }, + background_color: BackgroundColor(Color::GOLD), + ..default() + }) + .with_children(|p| { + p.spawn(TextBundle::from_section( + "Reset scroll", + TextStyle::default(), + )); + }); p.spawn(( NodeBundle { style: Style { @@ -47,6 +62,20 @@ fn prepare(mut commands: Commands) { }); } +fn reset_scroll( + q: Query<(&Button, &Interaction), Changed>, + mut scrolls_q: Query<&mut ScrollableContent>, +) { + for (_, interaction) in q.iter() { + if interaction == &Interaction::Pressed { + info!("TEST"); + for mut scroll in scrolls_q.iter_mut() { + scroll.pos_y = 0.0; + } + } + } +} + fn add_content(mut commands: Commands, q: Query>) { for e in q.iter() { commands.entity(e).with_children(|parent| {