diff --git a/rgis-ui/src/lib.rs b/rgis-ui/src/lib.rs index 04e6e81..7485126 100644 --- a/rgis-ui/src/lib.rs +++ b/rgis-ui/src/lib.rs @@ -22,6 +22,7 @@ mod operation_window; mod side_panel; mod systems; mod top_panel; +mod welcome_window; mod widgets; trait Window: egui::Widget + SystemParam + Send + Sync { @@ -29,6 +30,9 @@ trait Window: egui::Widget + SystemParam + Send + Sync { fn title(&self) -> &str; fn default_width(&self) -> f32; + fn default_anchor(&self) -> (egui::Align2, [f32; 2]) { + (egui::Align2::LEFT_TOP, [0., 0.]) + } } pub struct Plugin; @@ -79,4 +83,8 @@ impl IsWindowOpen { fn closed() -> Self { Self(false, marker::PhantomData) } + + fn open() -> Self { + Self(true, marker::PhantomData) + } } diff --git a/rgis-ui/src/systems.rs b/rgis-ui/src/systems.rs index c594893..0d84373 100644 --- a/rgis-ui/src/systems.rs +++ b/rgis-ui/src/systems.rs @@ -376,7 +376,12 @@ pub fn configure(app: &mut App) { ); app.insert_resource(crate::IsWindowOpen::::closed()); + app.insert_resource(crate::IsWindowOpen::::open()); app.add_systems(Update, render_window::); + app.add_systems( + Update, + render_window::, + ); } fn render_window( @@ -386,11 +391,13 @@ fn render_window( ) { if is_window_open.0 { let mut egui_ctx = egui_ctx_query.single_mut(); + let (anchor_align, anchor_offset) = window.default_anchor(); egui::Window::new(window.title()) .default_width(window.default_width()) .open(&mut is_window_open.0) .resizable(false) + .anchor(anchor_align, anchor_offset) .show(egui_ctx.get_mut(), |ui| { ui.add(window); }); diff --git a/rgis-ui/src/welcome_window.rs b/rgis-ui/src/welcome_window.rs new file mode 100644 index 0000000..f1cff60 --- /dev/null +++ b/rgis-ui/src/welcome_window.rs @@ -0,0 +1,33 @@ +use bevy::ecs::system::SystemParam; +use bevy_egui::egui; +use std::marker; + +#[derive(SystemParam)] +pub(crate) struct WelcomeWindow<'w, 's> { + _phantom: marker::PhantomData<(&'w (), &'s ())>, +} + +impl<'w, 's> egui::Widget for WelcomeWindow<'w, 's> { + fn ui(self, ui: &mut egui::Ui) -> egui::Response { + ui.vertical_centered_justified(|ui| { + ui.label("Welcome to rgis!"); + }) + .response + } +} + +impl crate::Window for WelcomeWindow<'_, '_> { + type Item<'w, 's> = WelcomeWindow<'w, 's>; + + fn title(&self) -> &str { + "Welcome" + } + + fn default_width(&self) -> f32 { + 300.0 + } + + fn default_anchor(&self) -> (egui::Align2, [f32; 2]) { + (egui::Align2::CENTER_CENTER, [0., 0.]) + } +}