From 3b5e023da326fb8d84a912d863a5621fcaece777 Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Mon, 10 Nov 2025 15:50:20 +0100 Subject: [PATCH] Settings config and black bg --- src/main.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2cc2618..715838d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,11 +36,11 @@ use cv_core::FeatureMatch; use std::error::Error; use std::fs::File; use std::io::BufReader; -use std::path::Path; +use std::path::{Path, PathBuf}; // use egui_dropdown::DropDownBox; -const CONFIG_FILE_PATH: &str = "./config.json"; +// const CONFIG_FILE_PATH: &str = "./config.json"; const DRAGGING_THRESHOLD: u32 = 30; // allow for a slight cursor movement to still detect a click fn main() { @@ -58,6 +58,7 @@ type StreamMap = HashMap>; struct GuiModel { // A handle to the laser API used for spawning streams and detecting DACs. + config_file_path: PathBuf, laser_api: Arc, // All of the live stream handles. laser_streams: StreamMap, @@ -304,8 +305,8 @@ fn save_config_file>(path: P, config: SavedConfig) -> std::result // Some hardcoded config. Not spending time on reading/writing config atm. -fn get_dac_configs() -> DacConfigMap{ - match read_config_from_file(CONFIG_FILE_PATH) { +fn get_dac_configs(config_path: &PathBuf) -> DacConfigMap{ + match read_config_from_file(config_path) { Err(err) => { eprintln!("Could not load config {}", err); return HashMap::new() @@ -317,6 +318,7 @@ fn get_dac_configs() -> DacConfigMap{ fn model(app: &App) -> GuiModel { let args: Vec = std::env::args().collect(); let zmq_url = &args[1]; + let config_file_path = PathBuf::from(&args[2]); // Create a window to receive keyboard events. let w_id_lasersettings = app @@ -415,7 +417,10 @@ fn model(app: &App) -> GuiModel { let current_layers = RenderableLayers::new(); //Vec::new(); + let per_laser_config = get_dac_configs(&config_file_path); + GuiModel { + config_file_path, laser_api, laser_settings, laser_model, @@ -427,7 +432,7 @@ fn model(app: &App) -> GuiModel { last_update: Instant::now(), lost_alpha: 1., connected: true, - per_laser_config: get_dac_configs(), + per_laser_config, selected_stream: None, canvas_scale: 25., canvas_translate: Vec2::new(-300.,100.), @@ -606,7 +611,7 @@ fn update(_app: &App, model: &mut GuiModel, update: Update) { ui.horizontal(|ui| { ui.heading("Laser Points"); if ui.button("💾").clicked() { - save_config_file(CONFIG_FILE_PATH, per_laser_config.into()); + save_config_file(&model.config_file_path, per_laser_config.into()); } }); @@ -1051,7 +1056,8 @@ fn view_laser_preview(app: &App, model: &GuiModel, frame: Frame) { let draw = app.draw(); - draw.background().color(srgba(0.3,0.3,0.3,1.)); + // draw.background().color(srgba(0.3,0.3,0.3,1.)); + draw.background().color(srgba(0.,0.,0., 1.)); let win = app.window_rect();