Skip to content

Commit

Permalink
Added settings state and option to disable publish panel.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmackdev committed Aug 5, 2023
1 parent e5f88cd commit 76f6d1a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 10 deletions.
43 changes: 33 additions & 10 deletions pubsubman_gui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use tokio::sync::mpsc::{Receiver, Sender};

use crate::{
actions::{create_subscription, refresh_topics},
settings::Settings,
ui::{render_topic_name, MessagesView, PublishView},
};

Expand All @@ -20,6 +21,7 @@ pub struct App {
messages: HashMap<TopicName, Vec<PubsubMessage>>,
publish_views: HashMap<TopicName, PublishView>,
messages_views: HashMap<TopicName, MessagesView>,
settings: Settings,
front_tx: Sender<FrontendMessage>,
back_rx: Receiver<BackendMessage>,
}
Expand All @@ -43,6 +45,7 @@ impl App {
messages: HashMap::new(),
publish_views: HashMap::new(),
messages_views: HashMap::new(),
settings: Settings::default(),
front_tx,
back_rx,
}
Expand All @@ -66,14 +69,32 @@ impl App {
}
}

fn render_top_panel(&self, ctx: &egui::Context, frame: &mut eframe::Frame) {
fn render_top_panel(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {
egui::menu::bar(ui, |ui| {
ui.menu_button("File", |ui| {
if ui.button("Quit").clicked() {
frame.close();
}
});

ui.menu_button("View", |ui| {
ui.horizontal(|ui| {
let button_text = format!(
"{}Show Publish Message Panel",
if self.settings.view.show_publish_message_panel {
"✔ "
} else {
""
}
);

if ui.button(button_text).clicked() {
self.settings.view.show_publish_message_panel =
!self.settings.view.show_publish_message_panel;
}
});
});
});
});
}
Expand Down Expand Up @@ -139,16 +160,18 @@ impl App {
});
});

egui::TopBottomPanel::bottom("topic_view_bottom_panel")
.resizable(true)
.show(ctx, |ui| {
self.publish_views
.entry(selected_topic.clone())
.or_default()
.show(ui, &self.front_tx, selected_topic);
if self.settings.view.show_publish_message_panel {
egui::TopBottomPanel::bottom("topic_view_bottom_panel")
.resizable(true)
.show(ctx, |ui| {
self.publish_views
.entry(selected_topic.clone())
.or_default()
.show(ui, &self.front_tx, selected_topic);

ui.allocate_space(ui.available_size());
});
ui.allocate_space(ui.available_size());
});
}

egui::CentralPanel::default()
.frame(
Expand Down
1 change: 1 addition & 0 deletions pubsubman_gui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

mod actions;
mod app;
mod settings;
mod ui;
pub use app::App;
16 changes: 16 additions & 0 deletions pubsubman_gui/src/settings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#[derive(Default)]
pub struct Settings {
pub view: ViewSettings,
}

pub struct ViewSettings {
pub show_publish_message_panel: bool,
}

impl Default for ViewSettings {
fn default() -> Self {
Self {
show_publish_message_panel: true,
}
}
}

0 comments on commit 76f6d1a

Please sign in to comment.