feat: moved new source in side panel, small tweaks

This commit is contained in:
əlemi 2022-06-14 03:02:00 +02:00
parent 66253fe900
commit 14e57447f4
Signed by: alemi
GPG key ID: A4895B84D311642C
3 changed files with 35 additions and 26 deletions

View file

@ -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);
}

View file

@ -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<Panel>) {
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<Panel>, 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)

View file

@ -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();
})
}
});
});
}