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 std::cell::{Cell, RefCell};
use std::rc::Rc;
use adw::glib::gobject_ffi::GValue;
use adw::glib::GString;
#[derive(Debug)]
pub enum Msg {}
@ -12,7 +14,7 @@ pub enum Msg {}
pub enum OutputMsg {}
pub enum SettingType {
Select(Vec<String>, Option<Box<dyn Fn(&str)>>),
Select(Vec<&'static str>, Option<Box<dyn Fn(usize)>>),
Action,
Entry(
Option<String>,
@ -37,18 +39,11 @@ impl SettingItem {
SettingType::Select(selects, selected) => {
let w = adw::ComboRow::builder().title(&self.title).build();
if let Some(selected) = selected.take() {
w.connect_selected_item_notify(move |s| {
// println!("{}", text);
// selected.set(text.to_string());
w.connect_selected_notify(move |s| {
selected(s.selected() as usize);
});
}
let model = StringList::new(
selects
.iter()
.map(|s| s.as_str())
.collect::<Vec<_>>()
.as_ref(),
);
let model = StringList::new(selects.as_ref());
w.set_model(Some(&model));
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*$"
)
.unwrap();
static ref RADAR_TYPES: Vec<&'static str> = vec!["X", "S", "C"];
}
#[derive(Clone, Debug, Default, PartialOrd, PartialEq)]
@ -71,8 +73,8 @@ macro_rules! to_setting {
impl RadarConfig {
pub fn to_settings(config: Rc<RefCell<RadarConfig>>) -> Vec<SettingItem> {
let mut settings = Vec::new();
let a = vec!["a".to_string()];
let b = vec!["b".to_string()];
let a = vec!["a"];
let b = vec!["b"];
to_setting!(
settings,
config,
@ -86,12 +88,12 @@ impl RadarConfig {
}
),
(
SettingType::Entry,
SettingType::Select,
"Type",
[None; None],
move |x: &str, config: Rc<RefCell<RadarConfig>>| {
[RADAR_TYPES.clone()],
|x: usize, config: Rc<RefCell<RadarConfig>>| {
let mut config = config.borrow_mut();
config._type = x.to_string();
config._type = (&RADAR_TYPES[x]).to_string();
}
),
(