diff options
author | metamuffin <yvchraiqi@protonmail.com> | 2022-08-17 07:45:49 +0200 |
---|---|---|
committer | metamuffin <yvchraiqi@protonmail.com> | 2022-08-17 07:45:49 +0200 |
commit | aca12bc6d0194364d9e36c455fbcd2390e00d8be (patch) | |
tree | 5d449cfb50fe4ec4537a96e0c76f035f2f6961e7 /karlgui/src/helper.rs | |
parent | 32bfbe158ab695c9258c13e6f32a619b780d8930 (diff) | |
download | karlender-aca12bc6d0194364d9e36c455fbcd2390e00d8be.tar karlender-aca12bc6d0194364d9e36c455fbcd2390e00d8be.tar.bz2 karlender-aca12bc6d0194364d9e36c455fbcd2390e00d8be.tar.zst |
better edit menus
Diffstat (limited to 'karlgui/src/helper.rs')
-rw-r--r-- | karlgui/src/helper.rs | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/karlgui/src/helper.rs b/karlgui/src/helper.rs new file mode 100644 index 0000000..1ae29c8 --- /dev/null +++ b/karlgui/src/helper.rs @@ -0,0 +1,93 @@ +use egui::{DragValue, Ui}; +use karlcommon::Property; + +pub fn format_value(prop: Property, value: i64) -> String { + match prop { + Property::Year => format!("{value}"), + Property::Monthofyear => format!( + "{}", + match value { + 0 => "January", + 1 => "February", + 2 => "March", + 3 => "April", + 4 => "May", + 5 => "June", + 6 => "July", + 7 => "August", + 8 => "September", + 9 => "October", + 10 => "November", + 11 => "December", + _ => "(invalid)", + } + ), + Property::Weekofmonth => format!("{value}"), + Property::Dayofyear => format!("{value}"), + Property::Dayofmonth => format!("{value}"), + Property::Dayofweek => format!( + "{}", + match value { + 0 => "Monday", + 1 => "Thuesday", + 2 => "Wednesday", + 3 => "Thursday", + 4 => "Friday", + 5 => "Saturday", + 6 => "Sunday", + _ => "(invalid)", + } + ), + Property::Hour => format!("{value}h"), + Property::Minute => format!("{value}min"), + Property::Second => format!("{value}s"), + Property::Unix => format!("{value}s"), + } +} + +pub fn edit_value(ui: &mut Ui, prop: Property, value: &mut i64) { + match prop { + Property::Year => { + ui.add(DragValue::new(value)); + } + Property::Monthofyear => { + egui::ComboBox::from_id_source(ui.id()) + .selected_text(format_value(prop, *value)) + .show_ui(ui, |ui| { + for v in 0..12 { + ui.selectable_value(value, v, format_value(prop, v)); + } + }); + } + Property::Dayofweek => { + egui::ComboBox::from_id_source(ui.id()) + .selected_text(format_value(prop, *value)) + .show_ui(ui, |ui| { + for v in 0..7 { + ui.selectable_value(value, v, format_value(prop, v)); + } + }); + } + Property::Weekofmonth => { + ui.add(DragValue::new(value).clamp_range(0..=5)); + } + Property::Dayofyear => { + ui.add(DragValue::new(value).clamp_range(0..=366)); + } + Property::Dayofmonth => { + ui.add(DragValue::new(value).clamp_range(0..=31)); + } + Property::Hour => { + ui.add(DragValue::new(value).clamp_range(0..=23).suffix("h")); + } + Property::Minute => { + ui.add(DragValue::new(value).clamp_range(0..=59).suffix("m")); + } + Property::Second => { + ui.add(DragValue::new(value).clamp_range(0..=59).suffix("s")); + } + Property::Unix => { + ui.add(DragValue::new(value).suffix("s")); + } + } +} |