You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.4 KiB
Rust
53 lines
1.4 KiB
Rust
use super::*;
|
|
|
|
pub(crate) struct BaseUiPlugin;
|
|
|
|
impl Plugin for BaseUiPlugin {
|
|
fn build(&self, app: &mut App) {
|
|
// TODO
|
|
}
|
|
}
|
|
|
|
/// Marker component for handling Resource -> Ui Sync
|
|
#[derive(Component, Default, Debug)]
|
|
pub struct SyncResource<R: Resource + Default + Display>(R);
|
|
|
|
/// Sync a generic resource to the UI
|
|
///
|
|
/// Mostly useful for quick n' dirty getting data to the user
|
|
pub fn sync_resource_to_ui<R: Resource + Default + Display>(
|
|
mut q: Query<&mut Text, With<SyncResource<R>>>,
|
|
r: Res<R>,
|
|
) {
|
|
q.iter_mut().for_each(|mut t| {
|
|
t.0 = format!("{}", *r);
|
|
});
|
|
}
|
|
|
|
/// Updates the scroll position of scrollable nodes in response to mouse input
|
|
pub fn scroll(trigger: Trigger<Pointer<Scroll>>, mut scrollers: Query<&mut ScrollPosition>) {
|
|
let Pointer {
|
|
event: Scroll { unit, x, y, .. },
|
|
..
|
|
} = trigger.event();
|
|
|
|
let (dx, dy) = match unit {
|
|
MouseScrollUnit::Line => (x * 16.0, y * 16.0),
|
|
MouseScrollUnit::Pixel => (x * 1., y * 1.),
|
|
};
|
|
|
|
if let Ok(mut pos) = scrollers.get_mut(trigger.target()) {
|
|
pos.offset_x -= dx;
|
|
pos.offset_y -= dy;
|
|
}
|
|
}
|
|
|
|
#[derive(Component, Debug)]
|
|
#[relationship(relationship_target = NavParent)]
|
|
pub(crate) struct NavChild(Entity);
|
|
|
|
#[derive(Component, Debug)]
|
|
#[relationship_target(relationship = NavChild)]
|
|
pub(crate) struct NavParent(Vec<Entity>);
|
|
|