Last fixes
This commit is contained in:
parent
2f23d23b02
commit
6d1fb83636
|
|
@ -11,12 +11,12 @@ license = "MIT OR Apache-2.0"
|
|||
description = "Simple to use plugin implementing ScrollView into Bevy engine."
|
||||
|
||||
[dependencies.bevy]
|
||||
version = "0.15.0-rc.3"
|
||||
version = "0.15"
|
||||
default-features = false
|
||||
features = ["bevy_ui", "bevy_asset", "bevy_text"]
|
||||
|
||||
[dev-dependencies.bevy]
|
||||
version = "0.15.0-rc.3"
|
||||
version = "0.15"
|
||||
default-features = true
|
||||
|
||||
[features]
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ fn main() {
|
|||
}
|
||||
|
||||
fn prepare(mut commands: Commands) {
|
||||
commands.spawn(Camera2d::default());
|
||||
commands.spawn(Camera2d);
|
||||
commands
|
||||
.spawn((
|
||||
BackgroundColor(CLR_1),
|
||||
|
|
@ -47,7 +47,7 @@ fn prepare(mut commands: Commands) {
|
|||
BackgroundColor(CLR_2),
|
||||
BorderColor(CLR_4),
|
||||
Button,
|
||||
btn_action.clone(),
|
||||
btn_action,
|
||||
))
|
||||
.with_children(|p| {
|
||||
p.spawn((
|
||||
|
|
@ -110,13 +110,14 @@ fn prepare(mut commands: Commands) {
|
|||
}
|
||||
|
||||
#[derive(Component, PartialEq, Debug, Clone, Copy)]
|
||||
#[require(Button)]
|
||||
enum ScrollButton {
|
||||
MoveToTop,
|
||||
MoveToBottom,
|
||||
}
|
||||
|
||||
fn reset_scroll(
|
||||
q: Query<(&Interaction, &ScrollButton), (Changed<Interaction>, With<Button>)>,
|
||||
q: Query<(&Interaction, &ScrollButton), Changed<Interaction>>,
|
||||
mut scrolls_q: Query<&mut ScrollableContent>,
|
||||
) {
|
||||
let Ok(mut scroll) = scrolls_q.get_single_mut() else {
|
||||
|
|
|
|||
30
src/lib.rs
30
src/lib.rs
|
|
@ -8,7 +8,7 @@ use bevy::{
|
|||
/// A `Plugin` providing the systems and components required to make a ScrollView work.
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// ```no_run
|
||||
/// use bevy::prelude::*;
|
||||
/// use bevy_simple_scroll_view::*;
|
||||
///
|
||||
|
|
@ -39,7 +39,7 @@ impl Plugin for ScrollViewPlugin {
|
|||
|
||||
/// Root component of scroll, it should have clipped style.
|
||||
#[derive(Component, Debug, Reflect)]
|
||||
#[require(Interaction)]
|
||||
#[require(Interaction, Node)]
|
||||
pub struct ScrollView {
|
||||
/// Field which control speed of the scrolling.
|
||||
/// Could be negative number to implement invert scroll
|
||||
|
|
@ -57,12 +57,23 @@ impl Default for ScrollView {
|
|||
/// Component containing offset value of the scroll container to the parent.
|
||||
/// It is possible to update the field `pos_y` manually to move scrollview to desired location.
|
||||
#[derive(Component, Debug, Reflect, Default)]
|
||||
#[require(Node(scroll_view_node))]
|
||||
pub struct ScrollableContent {
|
||||
/// Scroll container offset to the `ScrollView`.
|
||||
pub pos_y: f32,
|
||||
pub max_scroll: f32,
|
||||
}
|
||||
|
||||
pub fn scroll_view_node() -> Node {
|
||||
Node {
|
||||
overflow: Overflow::clip(),
|
||||
align_items: AlignItems::Start,
|
||||
align_self: AlignSelf::Stretch,
|
||||
flex_direction: FlexDirection::Row,
|
||||
..default()
|
||||
}
|
||||
}
|
||||
|
||||
impl ScrollableContent {
|
||||
pub fn scroll_to_top(&mut self) {
|
||||
self.pos_y = 0.0;
|
||||
|
|
@ -77,11 +88,18 @@ impl ScrollableContent {
|
|||
}
|
||||
|
||||
pub fn create_scroll_view(mut q: Query<&mut Node, Added<ScrollView>>) {
|
||||
let Node {
|
||||
overflow,
|
||||
align_items,
|
||||
align_self,
|
||||
flex_direction,
|
||||
..
|
||||
} = scroll_view_node();
|
||||
for mut style in q.iter_mut() {
|
||||
style.overflow = Overflow::clip();
|
||||
style.align_items = AlignItems::Start;
|
||||
style.align_self = AlignSelf::Stretch;
|
||||
style.flex_direction = FlexDirection::Row;
|
||||
style.overflow = overflow;
|
||||
style.align_items = align_items;
|
||||
style.align_self = align_self;
|
||||
style.flex_direction = flex_direction;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue