use bevy::{ecs::spawn::SpawnIter, prelude::*};
use bevy_scrollbar::{DragSpeed, ScrollSpeed, Scrollable, ScrollbarPlugin, ThumbColor};
fn main() {
App::new()
.add_plugins((DefaultPlugins, ScrollbarPlugin))
.add_systems(Startup, setup)
.run();
}
fn setup(mut commands: Commands) {
commands.spawn(Camera2d);
let mut container = commands.spawn(Node {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..default()
});
let container_id = container.id();
container.with_child((
Node {
width: Val::Percent(80.0),
height: Val::Percent(80.0),
border: UiRect::all(Val::Px(5.0)),
flex_wrap: FlexWrap::Wrap,
..default()
},
BorderColor::all(Color::BLACK),
Children::spawn(SpawnIter((0..100).map(|i| {
(
Node {
width: Val::Percent(20.0),
height: Val::Percent(20.0),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..default()
},
Children::spawn_one(Text::new(format!("Scroll {i}!"))),
)
}))),
ScrollSpeed(2.0),
Scrollable::spawn_one((
ChildOf(container_id),
Node {
width: Val::Percent(1.5),
height: Val::Percent(80.0),
margin: UiRect::left(Val::Px(5.0)),
border: UiRect::all(Val::Px(5.0)),
border_radius: BorderRadius::all(Val::Px(10.0)),
..default()
},
BorderColor::all(Color::BLACK),
ThumbColor(Color::srgb(0.0, 0.0, 1.0)),
DragSpeed(4.0),
)),
));
}