From f9180f81d3cccda938486ad7ba0e97c022bde1d9 Mon Sep 17 00:00:00 2001 From: alemidev Date: Tue, 14 Jun 2022 03:02:00 +0200 Subject: [PATCH] feat: moved new source in side panel, small tweaks --- src/app/gui/panel.rs | 2 +- src/app/gui/source.rs | 7 +++--- src/app/mod.rs | 52 +++++++++++++++++++++++++------------------ 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/src/app/gui/panel.rs b/src/app/gui/panel.rs index a133895..310acb4 100644 --- a/src/app/gui/panel.rs +++ b/src/app/gui/panel.rs @@ -12,7 +12,7 @@ use crate::app::{ pub fn panel_edit_inline_ui(ui: &mut Ui, panel: &mut Panel) { TextEdit::singleline(&mut panel.name) .hint_text("name") - .desired_width(50.0) + .desired_width(100.0) .show(ui); } diff --git a/src/app/gui/source.rs b/src/app/gui/source.rs index 802925c..60ec0a5 100644 --- a/src/app/gui/source.rs +++ b/src/app/gui/source.rs @@ -2,6 +2,7 @@ use eframe::egui::{Ui, TextEdit, ComboBox, Slider, DragValue}; use crate::app::data::source::{Panel, Source}; +#[allow(dead_code)] pub fn source_edit_inline_ui(ui: &mut Ui, source: &mut Source, panels: &Vec) { TextEdit::singleline(&mut source.name) .hint_text("name") @@ -49,11 +50,11 @@ pub fn source_edit_ui(ui: &mut Ui, source: &mut Source, panels: &Vec, wid ui.horizontal(|ui| { let text_width : f32 ; if width > 400.0 { - ui.add(Slider::new(&mut source.interval, 1..=60)); + ui.add(Slider::new(&mut source.interval, 1..=120)); text_width = width - 330.0 } else { - ui.add(DragValue::new(&mut source.interval).clamp_range(1..=60)); - text_width = width - 220.0 + ui.add(DragValue::new(&mut source.interval).clamp_range(1..=120)); + text_width = width - 225.0 } TextEdit::singleline(&mut source.query_x) .desired_width(text_width / 2.0) diff --git a/src/app/mod.rs b/src/app/mod.rs index 5612e85..ecf7d40 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -4,8 +4,8 @@ pub mod util; pub mod worker; use eframe::egui::{ - global_dark_light_mode_switch, CentralPanel, Context, Layout, ScrollArea, SidePanel, - TopBottomPanel, collapsing_header::CollapsingState, + collapsing_header::CollapsingState, global_dark_light_mode_switch, CentralPanel, Context, + Layout, ScrollArea, SidePanel, TopBottomPanel, }; use eframe::emath::Align; use std::sync::Arc; @@ -14,7 +14,7 @@ use tracing::error; use self::data::source::{Panel, Source}; use self::data::ApplicationState; use self::gui::panel::{panel_body_ui, panel_edit_inline_ui, panel_title_ui}; -use self::gui::source::{source_edit_inline_ui, source_edit_ui}; +use self::gui::source::source_edit_ui; use self::util::human_size; use self::worker::native_save; @@ -23,6 +23,7 @@ pub struct App { input_source: Source, input_panel: Panel, edit: bool, + padding: bool, } impl App { @@ -32,6 +33,7 @@ impl App { input_panel: Panel::default(), input_source: Source::default(), edit: false, + padding: false, } } } @@ -58,18 +60,6 @@ impl eframe::App for App { }; } ui.separator(); - ui.label("+ source"); - source_edit_inline_ui( - ui, - &mut self.input_source, - &self.data.panels.read().expect("Panels RwLock poisoned"), - ); - if ui.button("add").clicked() { - if let Err(e) = self.data.add_source(&self.input_source) { - error!(target: "ui", "Error adding souce : {:?}", e); - } - } - ui.separator(); } ui.with_layout(Layout::top_down(Align::RIGHT), |ui| { ui.horizontal(|ui| { @@ -130,18 +120,36 @@ impl eframe::App for App { .width_range(240.0..=800.0) .default_width(500.0) .show(ctx, |ui| { - let mut sources = self.data.sources.write().expect("Sources RwLock poisoned"); let panels = self.data.panels.read().expect("Panels RwLock poisoned"); ScrollArea::vertical().show(ui, |ui| { let width = ui.available_width(); - for source in &mut *sources { - source_edit_ui(ui, source, &panels, width); + { + let mut sources = self.data.sources.write().expect("Sources RwLock poisoned"); + for source in &mut *sources { + source_edit_ui(ui, source, &panels, width); + } } - // TODO make this not necessary - ui.collapsing("extra space", |ui| { + ui.add_space(20.0); + ui.separator(); + ui.horizontal(|ui| { + ui.heading("new source"); + ui.with_layout(Layout::top_down(Align::RIGHT), |ui| { + ui.horizontal(|ui| { + if ui.button("add").clicked() { + if let Err(e) = self.data.add_source(&self.input_source) { + error!(target: "ui", "Error adding souce : {:?}", e); + } else { + self.input_source.id += 1; + } + } + ui.toggle_value(&mut self.padding, "#"); + }); + }); + }); + source_edit_ui(ui, &mut self.input_source, &panels, width); + if self.padding { ui.add_space(300.0); - ui.separator(); - }) + } }); }); }