Skip to content

Commit

Permalink
Start adding support for multiple screens
Browse files Browse the repository at this point in the history
  • Loading branch information
maddymakesgames committed Mar 28, 2024
1 parent 3dbfe4a commit 8a81c4e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gui/src/editor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub mod stats;
use crate::{editor::level_sets::LevelSetsPanel, tabbed::TabbedContentWidget, PopupWindow};

pub struct EditorScreen {
file_name: String,
pub file_name: String,
save: SaveData,
safety_off: bool,
selected_panel: usize,
Expand Down
31 changes: 27 additions & 4 deletions gui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use eframe::{
};
use tokio::{runtime::Runtime, sync::Mutex};

use crate::main_menu::MainMenu;
use crate::{main_menu::MainMenu, tabbed::TabbedContentWidget};

#[cfg(not(target_family = "wasm"))]
fn main() {
Expand Down Expand Up @@ -69,7 +69,8 @@ fn main() {

// Global state struct for the editor
struct SaveEditor {
screen: ScreenState,
selected_screen: usize,
screens: Vec<ScreenState>,
runtime: Runtime,
popups: Arc<Mutex<Vec<PopupWindow>>>,
}
Expand Down Expand Up @@ -106,7 +107,8 @@ impl SaveEditor {
cc.egui_ctx.set_style(style);

SaveEditor {
screen: ScreenState::Startup,
selected_screen: 0,
screens: vec![ScreenState::Startup],
runtime,
popups: Arc::new(Mutex::new(Vec::new())),
}
Expand All @@ -117,9 +119,22 @@ impl App for SaveEditor {
fn update(&mut self, ctx: &eframe::egui::Context, _frame: &mut eframe::Frame) {
// Show the main window contents
CentralPanel::default().show(ctx, |ui| {
self.screen.update(ui, &self.runtime, &self.popups)
TabbedContentWidget::show(
ui,
&mut self.selected_screen,
self.screens
.iter()
.map(ScreenState::name)
.map(str::to_owned)
.collect::<Vec<_>>(),
|selected, ui| self.screens[selected].update(ui, &self.runtime, &self.popups),
);
});

if matches!(self.screens.last().unwrap(), ScreenState::Editor(_)) {
self.screens.push(ScreenState::Startup);
}

let mut popup_guard = self.popups.blocking_lock();
let mut to_remove = None;
// Loop over any open popups and display them
Expand Down Expand Up @@ -171,6 +186,14 @@ impl ScreenState {
}
}
}

fn name(&self) -> &str {
match self {
ScreenState::Startup => "new tab",
ScreenState::Menu(_) => "new tab",
ScreenState::Editor(e) => &e.file_name,
}
}
}

// Provide a function for easily spawning futures on both native and web platforms
Expand Down

0 comments on commit 8a81c4e

Please sign in to comment.