This commit is contained in:
Tsuki 2024-02-26 18:38:17 +08:00
parent 680425d212
commit ee271a8c26
2 changed files with 14 additions and 17 deletions

View File

@ -4,6 +4,8 @@ use gtk::{StringList, Widget};
use relm4::{factory::FactoryView, gtk, prelude::*, FactorySender, RelmObjectExt}; use relm4::{factory::FactoryView, gtk, prelude::*, FactorySender, RelmObjectExt};
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use std::rc::Rc; use std::rc::Rc;
use adw::glib::gobject_ffi::GValue;
use adw::glib::GString;
#[derive(Debug)] #[derive(Debug)]
pub enum Msg {} pub enum Msg {}
@ -12,7 +14,7 @@ pub enum Msg {}
pub enum OutputMsg {} pub enum OutputMsg {}
pub enum SettingType { pub enum SettingType {
Select(Vec<String>, Option<Box<dyn Fn(&str)>>), Select(Vec<&'static str>, Option<Box<dyn Fn(usize)>>),
Action, Action,
Entry( Entry(
Option<String>, Option<String>,
@ -37,18 +39,11 @@ impl SettingItem {
SettingType::Select(selects, selected) => { SettingType::Select(selects, selected) => {
let w = adw::ComboRow::builder().title(&self.title).build(); let w = adw::ComboRow::builder().title(&self.title).build();
if let Some(selected) = selected.take() { if let Some(selected) = selected.take() {
w.connect_selected_item_notify(move |s| { w.connect_selected_notify(move |s| {
// println!("{}", text); selected(s.selected() as usize);
// selected.set(text.to_string());
}); });
} }
let model = StringList::new( let model = StringList::new(selects.as_ref());
selects
.iter()
.map(|s| s.as_str())
.collect::<Vec<_>>()
.as_ref(),
);
w.set_model(Some(&model)); w.set_model(Some(&model));
w.upcast::<Widget>() w.upcast::<Widget>()
} }

View File

@ -12,6 +12,8 @@ lazy_static! {
r"^\s*(0|[1-9]\d*)(\.\d+)?\s*,\s*(0|[1-9]\d*)(\.\d+)?\s*,\s*(0|[1-9]\d*)(\.\d+)?\s*$" r"^\s*(0|[1-9]\d*)(\.\d+)?\s*,\s*(0|[1-9]\d*)(\.\d+)?\s*,\s*(0|[1-9]\d*)(\.\d+)?\s*$"
) )
.unwrap(); .unwrap();
static ref RADAR_TYPES: Vec<&'static str> = vec!["X", "S", "C"];
} }
#[derive(Clone, Debug, Default, PartialOrd, PartialEq)] #[derive(Clone, Debug, Default, PartialOrd, PartialEq)]
@ -71,8 +73,8 @@ macro_rules! to_setting {
impl RadarConfig { impl RadarConfig {
pub fn to_settings(config: Rc<RefCell<RadarConfig>>) -> Vec<SettingItem> { pub fn to_settings(config: Rc<RefCell<RadarConfig>>) -> Vec<SettingItem> {
let mut settings = Vec::new(); let mut settings = Vec::new();
let a = vec!["a".to_string()]; let a = vec!["a"];
let b = vec!["b".to_string()]; let b = vec!["b"];
to_setting!( to_setting!(
settings, settings,
config, config,
@ -86,12 +88,12 @@ impl RadarConfig {
} }
), ),
( (
SettingType::Entry, SettingType::Select,
"Type", "Type",
[None; None], [RADAR_TYPES.clone()],
move |x: &str, config: Rc<RefCell<RadarConfig>>| { |x: usize, config: Rc<RefCell<RadarConfig>>| {
let mut config = config.borrow_mut(); let mut config = config.borrow_mut();
config._type = x.to_string(); config._type = (&RADAR_TYPES[x]).to_string();
} }
), ),
( (