Skip to content

Commit

Permalink
Refactor GUI components and create separate header
Browse files Browse the repository at this point in the history
and body modules
  • Loading branch information
IhsenBouallegue committed Nov 17, 2023
1 parent c176bc7 commit 4a814c6
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 35 deletions.
40 changes: 5 additions & 35 deletions src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ mod top_bar;
pub mod windows; // TODO: make this private (it is public because it has ARCHIVE)

use crate::data_source::*;
use crate::gui::components::body::create_body;
use crate::gui::components::header::create_header;
use crate::settings::AppSettings;
use crate::simulation::*;
use crate::state::*;
Expand Down Expand Up @@ -418,45 +420,13 @@ impl Sam {
}

// Top panel containing text indicators and flight mode buttons
if ctx.screen_rect().width() > 1000.0 {
egui::TopBottomPanel::top("topbar").min_height(60.0).max_height(60.0).show(ctx, |ui| {
ui.set_enabled(!self.archive_window_open);
ui.horizontal_centered(|ui| {
self.top_bar(ui, false);
});
});
} else {
egui::TopBottomPanel::top("topbar").min_height(20.0).max_height(300.0).show(ctx, |ui| {
ui.set_enabled(!self.archive_window_open);
CollapsingHeader::new("Status & Controls").default_open(false).show(ui, |ui| {
self.top_bar(ui, true);
ui.add_space(10.0);
});
});
}
create_header(self, ctx);

// Bottom status bar
create_bottom_status_bar(self, ctx);

// Everything else. This has to be called after all the other panels
// are created.
egui::CentralPanel::default().show(ctx, |ui| {
ui.set_width(ui.available_width());
ui.set_height(ui.available_height());
ui.set_enabled(!self.archive_window_open);

match self.tab {
GuiTab::Launch => {}
GuiTab::Plot => self.plot_tab.main_ui(ui, self.data_source.as_mut()),
GuiTab::Configure => {
let changed = self.configure_tab.main_ui(ui, self.data_source.as_mut(), &mut self.settings);
if changed {
self.data_source.apply_settings(&self.settings);
self.plot_tab.apply_settings(&self.settings);
}
}
}
});
// Everything else. This has to be called after all the other panels are created.
create_body(self, ctx);

// If we have live data coming in, we need to tell egui to repaint.
// If we don't, we shouldn't.
Expand Down
24 changes: 24 additions & 0 deletions src/gui/components/body.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use crate::gui::tabs::GuiTab;
use crate::gui::Sam;

use egui::Context;

pub fn create_body(sam: &mut Sam, ctx: &Context) {
egui::CentralPanel::default().show(ctx, |ui| {
ui.set_width(ui.available_width());
ui.set_height(ui.available_height());
ui.set_enabled(!sam.archive_window_open);

match sam.tab {
GuiTab::Launch => {}
GuiTab::Plot => sam.plot_tab.main_ui(ui, sam.data_source.as_mut()),
GuiTab::Configure => {
let changed = sam.configure_tab.main_ui(ui, sam.data_source.as_mut(), &mut sam.settings);
if changed {
sam.data_source.apply_settings(&sam.settings);
sam.plot_tab.apply_settings(&sam.settings);
}
}
}
});
}
22 changes: 22 additions & 0 deletions src/gui/components/header.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use crate::gui::Sam;

use egui::{CollapsingHeader, Context};

pub fn create_header(sam: &mut Sam, ctx: &Context) {
if ctx.screen_rect().width() > 1000.0 {
egui::TopBottomPanel::top("topbar").min_height(60.0).max_height(60.0).show(ctx, |ui| {
ui.set_enabled(!sam.archive_window_open);
ui.horizontal_centered(|ui| {
sam.top_bar(ui, false);
});
});
} else {
egui::TopBottomPanel::top("topbar").min_height(20.0).max_height(300.0).show(ctx, |ui| {
ui.set_enabled(!sam.archive_window_open);
CollapsingHeader::new("Status & Controls").default_open(false).show(ui, |ui| {
sam.top_bar(ui, true);
ui.add_space(10.0);
});
});
}
}
2 changes: 2 additions & 0 deletions src/gui/components/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
pub mod body;
pub mod bottom_status_bar;
pub mod header;
pub mod top_menu_bar;

0 comments on commit 4a814c6

Please sign in to comment.