Remove scrollView

This commit is contained in:
Piotr Siuszko 2024-02-28 19:15:18 +01:00
parent 46ddbcea14
commit 0a1c5494d6
2 changed files with 30 additions and 28 deletions

View File

@ -19,8 +19,8 @@ fn main() {
fn prepare(mut commands: Commands) { fn prepare(mut commands: Commands) {
commands.spawn(Camera2dBundle::default()); commands.spawn(Camera2dBundle::default());
commands.spawn(( commands
NodeBundle { .spawn(NodeBundle {
style: Style { style: Style {
width: Val::Percent(100.0), width: Val::Percent(100.0),
height: Val::Percent(100.0), height: Val::Percent(100.0),
@ -28,10 +28,23 @@ fn prepare(mut commands: Commands) {
justify_content: JustifyContent::Center, justify_content: JustifyContent::Center,
..default() ..default()
}, },
background_color: BackgroundColor(Color::BLUE),
..default()
})
.with_children(|p| {
p.spawn((
NodeBundle {
style: Style {
width: Val::Percent(80.0),
height: Val::Percent(50.0),
..default() ..default()
}, },
ScrollView, background_color: BackgroundColor(Color::YELLOW),
..default()
},
ScrollViewport::default(),
)); ));
});
} }
fn add_content(mut commands: Commands, q: Query<Entity, Added<ScrollViewContent>>) { fn add_content(mut commands: Commands, q: Query<Entity, Added<ScrollViewContent>>) {

View File

@ -8,8 +8,7 @@ pub struct ScrollViewPlugin;
impl Plugin for ScrollViewPlugin { impl Plugin for ScrollViewPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.register_type::<ScrollView>() app.register_type::<ScrollViewport>()
.register_type::<ScrollViewport>()
.register_type::<ScrollViewContent>() .register_type::<ScrollViewContent>()
.add_systems( .add_systems(
Update, Update,
@ -18,9 +17,6 @@ impl Plugin for ScrollViewPlugin {
} }
} }
#[derive(Component, Default, Debug, Reflect)]
pub struct ScrollView;
#[derive(Component, Debug, Reflect)] #[derive(Component, Debug, Reflect)]
pub struct ScrollViewport { pub struct ScrollViewport {
pub scroll_speed: f32, pub scroll_speed: f32,
@ -39,23 +35,17 @@ pub struct ScrollViewContent {
pub pos_y: f32, pub pos_y: f32,
} }
pub fn create_scroll_view(mut commands: Commands, q: Query<Entity, Added<ScrollView>>) { pub fn create_scroll_view(
for e in q.iter() { mut commands: Commands,
commands.entity(e).with_children(|p| { mut q: Query<(Entity, &mut Style), Added<ScrollViewport>>,
p.spawn(( ) {
NodeBundle { for (e, mut style) in q.iter_mut() {
style: Style { style.overflow = Overflow::clip();
overflow: Overflow::clip(), style.align_items = AlignItems::Start;
max_height: Val::Percent(100.0),
max_width: Val::Percent(100.0), commands
align_items: AlignItems::Start, .entity(e)
..default() .insert(Interaction::None)
},
..Default::default()
},
ScrollViewport::default(),
Interaction::None,
))
.with_children(|v| { .with_children(|v| {
v.spawn(( v.spawn((
NodeBundle { NodeBundle {
@ -68,7 +58,6 @@ pub fn create_scroll_view(mut commands: Commands, q: Query<Entity, Added<ScrollV
ScrollViewContent { pos_y: 0.0 }, ScrollViewContent { pos_y: 0.0 },
)); ));
}); });
});
} }
} }