diff --git a/src/main.rs b/src/main.rs index 1182687e23093ae4bd215fb9353d26ac008094ee..218319d5f1350f27aa49e55746a76ef01c3a9df4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,7 @@ use tracing_subscriber::{EnvFilter, Layer, layer::SubscriberExt, util::Subscribe use error::ErrInstrument; use mavlink::ReflectionContext; -use ui::ComposableView; +use ui::App; /// ReflectionContext singleton, used to get access to the Mavlink message definitions static MAVLINK_PROFILE: LazyLock<ReflectionContext> = LazyLock::new(ReflectionContext::new); @@ -48,6 +48,6 @@ fn main() -> Result<(), eframe::Error> { eframe::run_native( APP_NAME, // This is the app id, used for example by Wayland native_options, - Box::new(|ctx| Ok(Box::new(ComposableView::new(APP_NAME, ctx)))), + Box::new(|ctx| Ok(Box::new(App::new(APP_NAME, ctx)))), ) } diff --git a/src/ui.rs b/src/ui.rs index f2254fcd1c30bc64fe82e86e7df35f993167ab69..050d0cc5a07620a8ddb59d247f85b3bd707f6e93 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -1,4 +1,4 @@ -mod composable_view; +mod app; mod panes; mod persistency; mod shortcuts; @@ -6,4 +6,4 @@ mod utils; mod widget_gallery; mod widgets; -pub use composable_view::ComposableView; +pub use app::App; diff --git a/src/ui/composable_view.rs b/src/ui/app.rs similarity index 97% rename from src/ui/composable_view.rs rename to src/ui/app.rs index a97e1fde431c136ff59503e85261220e206651d2..05706322e45253c89352f5302b1de8ff527f203a 100644 --- a/src/ui/composable_view.rs +++ b/src/ui/app.rs @@ -26,11 +26,11 @@ use std::{ }; use tracing::{debug, error, trace}; -pub struct ComposableView { +pub struct App { /// Persistent state of the app - state: ComposableViewState, + state: AppState, layout_manager: LayoutManager, - behavior: ComposableBehavior, + behavior: AppBehavior, maximized_pane: Option<TileId>, // == Message handling == message_broker: MessageBroker, @@ -42,7 +42,7 @@ pub struct ComposableView { } // An app must implement the `App` trait to define how the ui is built -impl eframe::App for ComposableView { +impl eframe::App for App { // The update function is called each time the UI needs repainting! fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { self.process_messages(); @@ -254,7 +254,7 @@ impl eframe::App for ComposableView { } } -impl ComposableView { +impl App { pub fn new(app_name: &str, ctx: &CreationContext) -> Self { let mut layout_manager = if let Some(storage) = ctx.storage { LayoutManager::new(app_name, storage) @@ -262,7 +262,7 @@ impl ComposableView { LayoutManager::default() }; - let mut state = ComposableViewState::default(); + let mut state = AppState::default(); // Load the selected layout if valid and existing if let Some(layout) = layout_manager.current_layout().cloned() { @@ -281,7 +281,7 @@ impl ComposableView { ctx.egui_ctx.clone(), ), widget_gallery: WidgetGallery::default(), - behavior: ComposableBehavior::default(), + behavior: AppBehavior::default(), maximized_pane: None, message_bundle: MessageBundle::default(), sources_window: SourceWindow::default(), @@ -333,11 +333,11 @@ impl ComposableView { } #[derive(Serialize, Deserialize, Clone, PartialEq)] -pub struct ComposableViewState { +pub struct AppState { pub panes_tree: Tree<Pane>, } -impl Default for ComposableViewState { +impl Default for AppState { fn default() -> Self { let mut tiles = Tiles::default(); let root = tiles.insert_pane(Pane::default()); @@ -347,10 +347,10 @@ impl Default for ComposableViewState { } } -impl ComposableViewState { +impl AppState { pub fn from_file(path: &PathBuf) -> anyhow::Result<Self> { fs::read_to_string(path) - .and_then(|json| serde_json::from_str::<ComposableViewState>(&json).map_err(Into::into)) + .and_then(|json| serde_json::from_str::<AppState>(&json).map_err(Into::into)) .map_err(|e| anyhow::anyhow!("Error deserializing layout: {}", e)) } @@ -547,13 +547,13 @@ impl SourceWindow { } } -/// Behavior for the tree of panes in the composable view +/// Behavior for the tree of panes in the app #[derive(Default)] -pub struct ComposableBehavior { +pub struct AppBehavior { pub action: Option<PaneAction>, } -impl Behavior<Pane> for ComposableBehavior { +impl Behavior<Pane> for AppBehavior { fn pane_ui( &mut self, ui: &mut egui::Ui, diff --git a/src/ui/panes.rs b/src/ui/panes.rs index febd8a5c7941504f0740ece2d8d43a66691d0359..17993c8fb276752f191453ac83478dabc0251211 100644 --- a/src/ui/panes.rs +++ b/src/ui/panes.rs @@ -9,7 +9,7 @@ use strum_macros::{self, EnumIter, EnumMessage}; use crate::mavlink::TimedMessage; -use super::composable_view::PaneResponse; +use super::app::PaneResponse; #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] pub struct Pane { diff --git a/src/ui/panes/default.rs b/src/ui/panes/default.rs index 0507d4d0fe5db6b36d8988ebe0b729fa6591cfe2..c3f7979e5ec83ea72df13087940f2fec997af02b 100644 --- a/src/ui/panes/default.rs +++ b/src/ui/panes/default.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; use tracing::debug; use crate::ui::{ - composable_view::{PaneAction, PaneResponse}, + app::{PaneAction, PaneResponse}, utils::{SizingMemo, vertically_centered}, }; diff --git a/src/ui/panes/messages_viewer.rs b/src/ui/panes/messages_viewer.rs index f1f63a974adcfe047f4834878b55cbebfde1b751..23a1f04516c444dbd4bb7dfe1b1a0c6c43a9c277 100644 --- a/src/ui/panes/messages_viewer.rs +++ b/src/ui/panes/messages_viewer.rs @@ -1,7 +1,7 @@ use egui::Label; use serde::{Deserialize, Serialize}; -use crate::ui::composable_view::PaneResponse; +use crate::ui::app::PaneResponse; use super::PaneBehavior; diff --git a/src/ui/panes/plot.rs b/src/ui/panes/plot.rs index 9433ed57aaf69194b6b05b78afa4138fac3037c1..bfd2ca859f753b7d997b4a571cd3c76e86a4628c 100644 --- a/src/ui/panes/plot.rs +++ b/src/ui/panes/plot.rs @@ -3,7 +3,7 @@ mod source_window; use super::PaneBehavior; use crate::{ mavlink::{MessageData, ROCKET_FLIGHT_TM_DATA, TimedMessage, extract_from_message}, - ui::composable_view::PaneResponse, + ui::app::PaneResponse, }; use egui::{Color32, Vec2b}; use egui_plot::{Legend, Line, PlotPoints}; diff --git a/src/ui/persistency/layout_manager.rs b/src/ui/persistency/layout_manager.rs index c1a0eec604b3ec15caf164e7307c1dee50972fcd..5b8ec96327cabca09117f07617a5663f9b102e44 100644 --- a/src/ui/persistency/layout_manager.rs +++ b/src/ui/persistency/layout_manager.rs @@ -9,14 +9,14 @@ use tracing::{info, trace, warn}; use crate::error::ErrInstrument; -use super::super::composable_view::ComposableViewState; +use super::super::app::AppState; static LAYOUTS_DIR: &str = "layouts"; static SELECTED_LAYOUT_KEY: &str = "selected_layout"; #[derive(Default)] pub struct LayoutManager { - layouts: BTreeMap<PathBuf, ComposableViewState>, + layouts: BTreeMap<PathBuf, AppState>, layouts_path: PathBuf, current_layout: Option<PathBuf>, } @@ -45,7 +45,7 @@ impl LayoutManager { &self.layouts_path } - pub fn layouts(&self) -> &BTreeMap<PathBuf, ComposableViewState> { + pub fn layouts(&self) -> &BTreeMap<PathBuf, AppState> { &self.layouts } @@ -65,7 +65,7 @@ impl LayoutManager { self.layouts = files .flatten() .map(|path| path.path()) - .flat_map(|path| match ComposableViewState::from_file(&path) { + .flat_map(|path| match AppState::from_file(&path) { Ok(layout) => { let path: PathBuf = path .file_stem() @@ -82,12 +82,12 @@ impl LayoutManager { } } - pub fn get_layout(&self, name: impl Into<PathBuf>) -> Option<&ComposableViewState> { + pub fn get_layout(&self, name: impl Into<PathBuf>) -> Option<&AppState> { self.layouts.get(&name.into()) } #[profiling::function] - pub fn save_layout(&mut self, name: &str, state: &ComposableViewState) -> anyhow::Result<()> { + pub fn save_layout(&mut self, name: &str, state: &AppState) -> anyhow::Result<()> { let path = self.layouts_path.join(name).with_extension("json"); state.to_file(&path)?; self.reload_layouts(); @@ -98,7 +98,7 @@ impl LayoutManager { pub fn load_layout( &mut self, path: impl AsRef<Path>, - state: &mut ComposableViewState, + state: &mut AppState, ) -> anyhow::Result<()> { let layout = self .layouts @@ -117,7 +117,7 @@ impl LayoutManager { Ok(()) } - // pub fn display_selected_layout(&mut self, state: &mut ComposableViewState) { + // pub fn display_selected_layout(&mut self, state: &mut AppState) { // if let Some(selection) = self.selection.as_ref() { // if let Some(selected_layout) = self.layouts.get(selection) { // *state = selected_layout.clone(); @@ -126,7 +126,7 @@ impl LayoutManager { // } // } - // pub fn save_current_layout(&mut self, state: &ComposableViewState, name: &String) { + // pub fn save_current_layout(&mut self, state: &AppState, name: &String) { // let layouts_path = &self.layouts_path; // let path = layouts_path.join(name).with_extension("json"); // state.to_file(&path); diff --git a/src/ui/persistency/layout_manager_window.rs b/src/ui/persistency/layout_manager_window.rs index 0cd38bfa094d34b0757bf942027ae6c7f19afc1e..d4be72e36d8dfdabdd2d6c06dbfb189eed2d2c4a 100644 --- a/src/ui/persistency/layout_manager_window.rs +++ b/src/ui/persistency/layout_manager_window.rs @@ -8,7 +8,7 @@ use egui_extras::{Column, Size, StripBuilder, TableBuilder}; use egui_file::FileDialog; use tracing::{debug, error}; -use crate::{error::ErrInstrument, ui::composable_view::ComposableViewState}; +use crate::{error::ErrInstrument, ui::app::AppState}; use super::LayoutManager; @@ -39,7 +39,7 @@ impl LayoutManagerWindow { &mut self, ctx: &Context, layout_manager: &mut LayoutManager, - state: &mut ComposableViewState, + state: &mut AppState, ) { let LayoutManagerWindow { visible: window_visible, @@ -92,7 +92,7 @@ impl LayoutManagerWindow { fn show_layouts_table( ui: &mut Ui, layout_manager: &mut LayoutManager, - state: &mut ComposableViewState, + state: &mut AppState, selection: &mut Option<PathBuf>, changed: bool, ) { @@ -173,7 +173,7 @@ fn show_layouts_table( fn show_action_buttons( builder: StripBuilder, layout_manager: &mut LayoutManager, - state: &mut ComposableViewState, + state: &mut AppState, file_dialog: &mut Option<FileDialog>, text_input: &mut String, selection: &mut Option<PathBuf>, @@ -188,7 +188,7 @@ fn show_action_buttons( Button::new("Load empty"), ); if open_empty_resp.clicked() { - *state = ComposableViewState::default(); + *state = AppState::default(); selection.take(); } diff --git a/src/ui/widget_gallery.rs b/src/ui/widget_gallery.rs index a5288191848c04212c0845c403ad12b1c8d1ea31..ad8796d55159d2cf83b10f73a0db4692bedf6506 100644 --- a/src/ui/widget_gallery.rs +++ b/src/ui/widget_gallery.rs @@ -3,7 +3,7 @@ use egui_tiles::TileId; use strum::{EnumMessage, IntoEnumIterator}; use super::{ - composable_view::PaneAction, + app::PaneAction, panes::{Pane, PaneKind}, };