diff --git a/src/components/new_project.rs b/src/components/new_project.rs index ceaf8cc..0d9fa94 100644 --- a/src/components/new_project.rs +++ b/src/components/new_project.rs @@ -8,9 +8,11 @@ use gtk::ResponseType::No; use gtk::Widget; use relm4::factory::FactoryVecDeque; use crate::components::setting_item::{SettingItem, SettingType}; +use crate::config::CommonConfig; #[derive(Debug)] pub struct NewPageModel { + common_setting: CommonConfig } #[relm4::component(pub)] @@ -48,7 +50,7 @@ impl SimpleComponent for NewPageModel { set_title: "Common", add=&adw::PreferencesGroup{ #[iterate] - add:widgets.iter() + add: model.common_setting.to_settings().iter_mut().map(|v| v.to_widget()).collect::>().iter() } } }, @@ -61,15 +63,8 @@ impl SimpleComponent for NewPageModel { root: &Self::Root, sender: relm4::ComponentSender, ) -> relm4::ComponentParts { - let mut common_settings = Vec::new(); - common_settings.push(SettingItem::new("Name".to_string(), SettingType::Entry(None, None))); - common_settings.push(SettingItem::new("Name".to_string(), SettingType::Entry(None, None))); - common_settings.push(SettingItem::new("Name".to_string(), SettingType::Entry(None, None))); - let widgets:Vec<_> = common_settings.iter_mut().map(|setting: &mut SettingItem| { - setting.to_widget() - }).collect(); - - let model = NewPageModel {}; + let config = CommonConfig::default(); + let model = NewPageModel { common_setting: config }; let widgets = view_output!(); ComponentParts { model, widgets } diff --git a/src/components/setting_item/mod.rs b/src/components/setting_item/mod.rs index 0844bef..96e71c7 100644 --- a/src/components/setting_item/mod.rs +++ b/src/components/setting_item/mod.rs @@ -1,8 +1,8 @@ -use std::rc::Rc; use adw::prelude::*; use gtk::prelude::*; use gtk::{StringList, Widget}; use relm4::{factory::FactoryView, gtk, prelude::*, FactorySender}; +use std::rc::Rc; #[derive(Debug)] pub enum Msg {} @@ -15,7 +15,7 @@ pub enum SettingType { Action, Entry(Option, Option bool>>), Switch(bool), - Spin((f64, f64,f64,f64)) + Spin(f64, f64, f64, f64), } pub struct SettingItem { @@ -27,25 +27,32 @@ impl SettingItem { pub fn new(title: String, _type: SettingType) -> Self { Self { title, _type } } - pub fn to_widget(&mut self) -> impl IsA{ - (match &mut self._type { + pub fn to_widget(&mut self) -> Widget { + (match &mut self._type { SettingType::Select(selects) => { let w = adw::ComboRow::builder().title(&self.title).build(); - let model = StringList::new(selects.iter().map(|s| s.as_str()).collect::>().as_ref()); + let model = StringList::new( + selects + .iter() + .map(|s| s.as_str()) + .collect::>() + .as_ref(), + ); w.set_model(Some(&model)); w.upcast::() } - SettingType::Action => { - adw::EntryRow::builder().title(&self.title).build().upcast::() - } + SettingType::Action => adw::EntryRow::builder() + .title(&self.title) + .build() + .upcast::(), SettingType::Entry(text, f) => { let w = adw::EntryRow::new(); w.set_title(&self.title); let f = f.take(); - if let Some(f) = f{ + if let Some(f) = f { println!("test"); - w.connect_text_notify(move |s|{ - let text =s.text(); + w.connect_text_notify(move |s| { + let text = s.text(); if !f(&text) { s.set_text(""); } @@ -62,14 +69,18 @@ impl SettingItem { w.set_active(*t); w.upcast::() } - SettingType::Spin((min, max,clamb, value)) => { - let w = adw::SpinRow::new(Some(gtk::Adjustment::), *clamb,0); - w.set_numeric(true); - // w.set_range(*min, *max); - w.set_value(*value); - w.set_title(&self.title); - w.upcast::() - } + SettingType::Spin(min, max, clamb, value) => { + let w = adw::SpinRow::new( + Some(>k::Adjustment::new(*value, *min, *max, *clamb, 0.0, 0.0)), + *clamb, + 0, + ); + w.set_numeric(true); + // w.set_range(*min, *max); + w.set_value(*value); + w.set_title(&self.title); + w.upcast::() + } }) } -} \ No newline at end of file +} diff --git a/src/config.rs b/src/config.rs index b107544..2590d5e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use crate::components::{SettingItem, SettingType}; -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub struct CommonConfig{ pub name: String, pub version: String, @@ -28,5 +28,29 @@ pub struct AlgorithmConfig { info: HashMap } -pub fn default_common_items() { +impl CommonConfig{ + pub fn to_settings(&self) -> Vec{ + let mut settings = Vec::new(); + settings.push(SettingItem::new("Name".to_string(), SettingType::Entry(Some(self.name.clone()), None))); + settings.push(SettingItem::new("Version".to_string(), SettingType::Entry(Some(self.version.clone()), None))); + settings.push(SettingItem::new("Radar Num".to_string(), SettingType::Spin(0.0, 0.0, 100.0, 1.0))); + for radar in self.radars.iter(){ + settings.push(SettingItem::new("Name".to_string(), SettingType::Entry(Some(radar.name.clone()), None))); + settings.push(SettingItem::new("Type".to_string(), SettingType::Entry(Some(radar._type.clone()), None))); + settings.push(SettingItem::new("Location".to_string(), SettingType::Entry(Some(format!("{},{},{}", radar.loc[0], radar.loc[1], radar.loc[2])), None))); + settings.push(SettingItem::new("Azimuth Beam Width".to_string(), SettingType::Entry(Some(radar.az_beam_width.to_string()), None))); + settings.push(SettingItem::new("Elevation Beam Width".to_string(), SettingType::Entry(Some(radar.el_beam_width.to_string()), None))); + settings.push(SettingItem::new("Azimuth Method".to_string(), SettingType::Select(vec!["1".to_string(), "2".to_string(), "3".to_string()]))); + settings.push(SettingItem::new("Elevation Method".to_string(), SettingType::Select(vec!["1".to_string(), "2".to_string(), "3".to_string()]))); + settings.push(SettingItem::new("Range Limit".to_string(), SettingType::Entry(Some(radar.r_limit.to_string()), None))); + } + for algorithm in self.algorithms.iter(){ + settings.push(SettingItem::new("Name".to_string(), SettingType::Entry(Some(algorithm.name.clone()), None))); + settings.push(SettingItem::new("Version".to_string(), SettingType::Entry(Some(algorithm.version.clone()), None))); + for (k, v) in algorithm.info.iter(){ + settings.push(SettingItem::new(k.clone(), SettingType::Entry(Some(v.clone()), None))); + } + } + settings + } } \ No newline at end of file