Work on paylaod config, move config buttons to titlebar

This commit is contained in:
Michael Mikovsky
2025-12-04 09:55:22 -07:00
parent 11d9454f8c
commit 9cbd1020ca
5 changed files with 79 additions and 37 deletions
+12 -4
View File
@@ -3,7 +3,10 @@ mod windows;
use std::collections::HashMap; use std::collections::HashMap;
use crate::{app::windows::WindowWrapper, auth::Auth, config::Config, flowchart::FlowChart}; use crate::{
app::windows::WindowWrapper, auth::Auth, config::Config, flowchart::FlowChart,
payload_config::PayloadConfig,
};
pub use app::TemplateApp; pub use app::TemplateApp;
use egui_tiles::{TileId, Tree}; use egui_tiles::{TileId, Tree};
@@ -15,12 +18,14 @@ pub struct AppState {
pub flowchart: FlowChart, pub flowchart: FlowChart,
pub config: Config, pub config: Config,
pub payload_config: PayloadConfig,
} }
impl AppState { impl AppState {
pub fn labels(&mut self, tree: &mut Tree<WindowWrapper>, ui: &mut egui::Ui) { pub fn labels(&mut self, tree: &mut Tree<WindowWrapper>, ui: &mut egui::Ui) {
for (_, (key, name)) in (vec![ for (_, (key, name)) in (vec![
(AppWindow::Flowchart, "Flowchart"), (AppWindow::Flowchart, "Flowchart"),
(AppWindow::PayloadConfig, "Payload Config"),
(AppWindow::Config, "Config"), (AppWindow::Config, "Config"),
]) ])
.iter() .iter()
@@ -69,6 +74,7 @@ impl AppState {
pub enum AppWindow { pub enum AppWindow {
Flowchart, Flowchart,
Config, Config,
PayloadConfig,
} }
impl AppWindow { impl AppWindow {
@@ -76,15 +82,17 @@ impl AppWindow {
match self { match self {
AppWindow::Flowchart => state.flowchart.paint(ui), AppWindow::Flowchart => state.flowchart.paint(ui),
AppWindow::Config => state.config.update(&mut state.auth, ui), AppWindow::Config => state.config.update(&mut state.auth, ui),
AppWindow::PayloadConfig => state.payload_config.update(ui),
} }
} }
fn render_title_buttons(&self, state: &mut AppState, ui: &mut egui::Ui) { fn render_title_buttons(&self, state: &mut AppState, ui: &mut egui::Ui) {
match self { match self {
AppWindow::Flowchart => { AppWindow::Flowchart => {
if ui.button("Arrange").clicked() { state.flowchart.titlebar_buttons(ui);
state.flowchart.arrange(); }
} AppWindow::Config => {
state.config.titlebar_buttons(ui);
} }
_ => { _ => {
ui.label(""); ui.label("");
+42 -33
View File
@@ -58,17 +58,6 @@ impl Config {
drop(state_lock); drop(state_lock);
ui.horizontal(|ui| { ui.horizontal(|ui| {
if ui.button("Refresh").clicked() {
// self.tree_option.clear();
let mut state_lock = self.state.lock().unwrap();
(*state_lock).trees = None;
(*state_lock).tree_keys = None;
drop(state_lock);
tree_list_none = true;
key_list_none = true;
}
if tree_list_none && !is_requesting { if tree_list_none && !is_requesting {
self.state.lock().unwrap().is_requesting = true; self.state.lock().unwrap().is_requesting = true;
let state_clone = self.state.clone(); let state_clone = self.state.clone();
@@ -83,28 +72,9 @@ impl Config {
ui.spinner(); ui.spinner();
} }
let state_lock = self.state.lock().unwrap(); // let state_lock = self.state.lock().unwrap();
// This might have changed since the above api call // // This might have changed since the above api call
tree_list_none = state_lock.trees.is_none(); // tree_list_none = state_lock.trees.is_none();
if !tree_list_none {
let trees = state_lock.trees.as_ref().unwrap().clone();
drop(state_lock);
let before = &self.tree_option.clone();
egui::ComboBox::from_id_salt("Select Tree")
.selected_text(&self.tree_option)
.show_ui(ui, |ui| {
for tree in trees {
ui.selectable_value(&mut self.tree_option, tree.clone(), tree);
}
});
if before.ne(&self.tree_option) {
(*self.state.lock().unwrap()).tree_keys = None;
key_list_none = true;
}
}
if !self.tree_option.is_empty() && !tree_list_none { if !self.tree_option.is_empty() && !tree_list_none {
// ui.horizontal(|ui| { // ui.horizontal(|ui| {
@@ -179,4 +149,43 @@ impl Config {
// }); // });
} }
} }
pub fn titlebar_buttons(&mut self, ui: &mut egui::Ui) {
let state_lock = self.state.lock().unwrap();
let mut tree_list_none = state_lock.trees.is_none();
let mut key_list_none = state_lock.tree_keys.is_none();
let is_requesting = state_lock.is_requesting;
drop(state_lock);
if ui.button("Refresh").clicked() {
let mut state_lock = self.state.lock().unwrap();
(*state_lock).trees = None;
(*state_lock).tree_keys = None;
drop(state_lock);
tree_list_none = true;
key_list_none = true;
}
if !tree_list_none {
let state_lock = self.state.lock().unwrap();
let trees = state_lock.trees.as_ref().unwrap().clone();
drop(state_lock);
let before = &self.tree_option.clone();
egui::ComboBox::from_id_salt("Select Tree")
.selected_text(&self.tree_option)
.show_ui(ui, |ui| {
for tree in trees {
ui.selectable_value(&mut self.tree_option, tree.clone(), tree);
}
});
if before.ne(&self.tree_option) {
(*self.state.lock().unwrap()).tree_keys = None;
key_list_none = true;
}
}
}
} }
+6
View File
@@ -145,4 +145,10 @@ impl FlowChart {
self.scene_rect = inner_rect; self.scene_rect = inner_rect;
} }
} }
pub fn titlebar_buttons(&mut self, ui: &mut egui::Ui) {
if ui.button("Arrange").clicked() {
self.arrange();
}
}
} }
+1
View File
@@ -7,6 +7,7 @@ pub mod app;
mod auth; mod auth;
mod config; mod config;
mod flowchart; mod flowchart;
mod payload_config;
use std::time::Duration; use std::time::Duration;
const FORCE_REDRAW_DELAY: Duration = Duration::from_millis(300); const FORCE_REDRAW_DELAY: Duration = Duration::from_millis(300);
+18
View File
@@ -0,0 +1,18 @@
#[derive(serde::Deserialize, serde::Serialize)]
pub struct PayloadConfig {}
struct ServerConfigState {
// config: Vec<PayloadConfig>
}
impl PayloadConfig {
pub fn update(&mut self, ui: &mut egui::Ui) {
ui.heading("Test");
}
}
impl Default for PayloadConfig {
fn default() -> Self {
Self {}
}
}