From 0a1c5494d6f31b93e2b5b8551a3be461a57496ca Mon Sep 17 00:00:00 2001 From: Piotr Siuszko Date: Wed, 28 Feb 2024 19:15:18 +0100 Subject: [PATCH] Remove scrollView --- examples/simple.rs | 23 ++++++++++++++++++----- src/lib.rs | 35 ++++++++++++----------------------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/examples/simple.rs b/examples/simple.rs index dc840ce..232c290 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -19,8 +19,8 @@ fn main() { fn prepare(mut commands: Commands) { commands.spawn(Camera2dBundle::default()); - commands.spawn(( - NodeBundle { + commands + .spawn(NodeBundle { style: Style { width: Val::Percent(100.0), height: Val::Percent(100.0), @@ -28,10 +28,23 @@ fn prepare(mut commands: Commands) { justify_content: JustifyContent::Center, ..default() }, + background_color: BackgroundColor(Color::BLUE), ..default() - }, - ScrollView, - )); + }) + .with_children(|p| { + p.spawn(( + NodeBundle { + style: Style { + width: Val::Percent(80.0), + height: Val::Percent(50.0), + ..default() + }, + background_color: BackgroundColor(Color::YELLOW), + ..default() + }, + ScrollViewport::default(), + )); + }); } fn add_content(mut commands: Commands, q: Query>) { diff --git a/src/lib.rs b/src/lib.rs index 1b2e7c7..59791e9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,8 +8,7 @@ pub struct ScrollViewPlugin; impl Plugin for ScrollViewPlugin { fn build(&self, app: &mut App) { - app.register_type::() - .register_type::() + app.register_type::() .register_type::() .add_systems( Update, @@ -18,9 +17,6 @@ impl Plugin for ScrollViewPlugin { } } -#[derive(Component, Default, Debug, Reflect)] -pub struct ScrollView; - #[derive(Component, Debug, Reflect)] pub struct ScrollViewport { pub scroll_speed: f32, @@ -39,23 +35,17 @@ pub struct ScrollViewContent { pub pos_y: f32, } -pub fn create_scroll_view(mut commands: Commands, q: Query>) { - for e in q.iter() { - commands.entity(e).with_children(|p| { - p.spawn(( - NodeBundle { - style: Style { - overflow: Overflow::clip(), - max_height: Val::Percent(100.0), - max_width: Val::Percent(100.0), - align_items: AlignItems::Start, - ..default() - }, - ..Default::default() - }, - ScrollViewport::default(), - Interaction::None, - )) +pub fn create_scroll_view( + mut commands: Commands, + mut q: Query<(Entity, &mut Style), Added>, +) { + for (e, mut style) in q.iter_mut() { + style.overflow = Overflow::clip(); + style.align_items = AlignItems::Start; + + commands + .entity(e) + .insert(Interaction::None) .with_children(|v| { v.spawn(( NodeBundle { @@ -68,7 +58,6 @@ pub fn create_scroll_view(mut commands: Commands, q: Query