sync
This commit is contained in:
parent
749326a502
commit
01d14f5f4e
@ -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::<Vec<_>>().iter()
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -61,15 +63,8 @@ impl SimpleComponent for NewPageModel {
|
||||
root: &Self::Root,
|
||||
sender: relm4::ComponentSender<Self>,
|
||||
) -> relm4::ComponentParts<Self> {
|
||||
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 }
|
||||
|
||||
@ -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<String>, Option<Box<dyn Fn(&str) -> 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<Widget>{
|
||||
(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::<Vec<_>>().as_ref());
|
||||
let model = StringList::new(
|
||||
selects
|
||||
.iter()
|
||||
.map(|s| s.as_str())
|
||||
.collect::<Vec<_>>()
|
||||
.as_ref(),
|
||||
);
|
||||
w.set_model(Some(&model));
|
||||
w.upcast::<Widget>()
|
||||
}
|
||||
SettingType::Action => {
|
||||
adw::EntryRow::builder().title(&self.title).build().upcast::<Widget>()
|
||||
}
|
||||
SettingType::Action => adw::EntryRow::builder()
|
||||
.title(&self.title)
|
||||
.build()
|
||||
.upcast::<Widget>(),
|
||||
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::<Widget>()
|
||||
}
|
||||
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::<Widget>()
|
||||
}
|
||||
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::<Widget>()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<String, String>
|
||||
}
|
||||
|
||||
pub fn default_common_items() {
|
||||
impl CommonConfig{
|
||||
pub fn to_settings(&self) -> Vec<SettingItem>{
|
||||
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
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user