Skip to content

Commit c2fc06e

Browse files
committed
Add button for switching to load/home screen
Nice on web to switch demos.
1 parent dcf9124 commit c2fc06e

5 files changed

Lines changed: 36 additions & 7 deletions

File tree

crates/maps/src/app.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub enum ViewMode {
4444
Stacked,
4545
#[default]
4646
Aligned,
47+
LoadScreen,
4748
}
4849

4950
#[derive(Clone, Debug, Display, Default, PartialEq, EnumString, VariantNames)]

crates/maps/src/app_impl/central_panel.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,19 @@ impl AppState {
253253
}
254254
}
255255

256-
fn show_empty(&mut self, ui: &mut egui::Ui) {
256+
fn show_load_screen(&mut self, ui: &mut egui::Ui) {
257257
ui.with_layout(
258258
egui::Layout::centered_and_justified(egui::Direction::TopDown),
259259
|ui| {
260260
ui.horizontal_centered(|ui| {
261261
ui.vertical_centered(|ui| {
262262
let frac = if cfg!(target_arch = "wasm32") { 4. } else { 2. };
263263
ui.add_space((ui.available_height() / frac - 100.).max(SPACE));
264-
ui.heading("No maps loaded.");
264+
if self.data.maps.is_empty() {
265+
ui.heading("No maps loaded.");
266+
} else {
267+
ui.heading("Select a view in the top bar or load more maps.");
268+
}
265269
ui.add_space(2. * SPACE);
266270
self.load_meta_button(ui);
267271
ui.add_space(SPACE);
@@ -309,8 +313,7 @@ impl AppState {
309313
viewport_rect = ui.clip_rect();
310314

311315
if self.data.maps.is_empty() {
312-
self.show_empty(ui);
313-
return;
316+
self.options.view_mode = ViewMode::LoadScreen;
314317
}
315318

316319
match self.options.view_mode {
@@ -327,6 +330,9 @@ impl AppState {
327330
ViewMode::Aligned => {
328331
self.show_grid(ui);
329332
}
333+
ViewMode::LoadScreen => {
334+
self.show_load_screen(ui);
335+
}
330336
}
331337
});
332338

crates/maps/src/app_impl/load_delete.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::tiles::Pane;
1212
use maps_io_ros::{Meta, load_image};
1313
use maps_rendering::{ImagePyramid, TextureFilter};
1414

15-
use crate::app::{AppState, Error};
15+
use crate::app::{AppState, Error, ViewMode};
1616
use crate::app_impl::compat::migrate_old_egui_color;
1717
use maps_io_ros::MapPose;
1818
use maps_io_ros::value_interpretation;
@@ -74,6 +74,9 @@ impl AppState {
7474
self.data.draw_order.add(name.clone());
7575
info!("Loaded map: {name}");
7676
self.status.unsaved_changes = true;
77+
if self.options.view_mode == ViewMode::LoadScreen {
78+
self.options.view_mode = ViewMode::default();
79+
}
7780
}
7881

7982
pub(crate) fn load_map(&mut self, meta: Meta) -> Result<String, Error> {

crates/maps/src/app_impl/menu_panel.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use eframe::egui;
22
use log::error;
33

4-
use crate::app::AppState;
4+
use crate::app::{AppState, ViewMode};
55
use crate::app_impl::constants::SPACE;
66
use crate::app_impl::ui_helpers::display_path;
77
use crate::map_state::MapState;
@@ -118,7 +118,24 @@ impl AppState {
118118
}
119119

120120
fn menu_content(&mut self, ui: &mut egui::Ui) {
121-
ui.heading("Maps");
121+
egui::Sides::new().show(
122+
ui,
123+
|ui_left| {
124+
ui_left.heading("Maps");
125+
},
126+
|ui_right| {
127+
ui_right.visuals_mut().widgets.inactive.weak_bg_fill =
128+
ui_right.visuals().window_fill();
129+
if ui_right
130+
.button(egui::RichText::new("🏠").heading())
131+
.on_hover_text("Switch to load screen")
132+
.clicked()
133+
{
134+
self.options.view_mode = ViewMode::LoadScreen;
135+
}
136+
},
137+
);
138+
122139
ui.add_space(SPACE);
123140
ui.horizontal(|ui| {
124141
self.load_meta_button(ui);

crates/maps/src/wasm/demo.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ impl AppState {
128128
include_bytes!("../../data/doc/demo_scaled.png"),
129129
"Demo showcasing very large map images, with maps of the Cartographer Deutsches Museum dataset.",
130130
) {
131+
self.data.maps.clear();
131132
load_cartographer_demo(self);
132133
}
133134
}
@@ -140,6 +141,7 @@ impl AppState {
140141
include_bytes!("../../data/doc/demo_nav2_scaled.png"),
141142
"Demo showcasing a typical mobile robot warehouse scenario, with maps from the Nav2 demo.",
142143
) {
144+
self.data.maps.clear();
143145
load_nav2_demo(self);
144146
}
145147
}

0 commit comments

Comments
 (0)