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); /// Sync a generic resource to the UI /// /// Mostly useful for quick n' dirty getting data to the user pub fn sync_resource_to_ui( mut q: Query<&mut Text, With>>, r: Res, ) { 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>, 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);