aboutsummaryrefslogtreecommitdiff
path: root/karlgui/src/helper.rs
diff options
context:
space:
mode:
Diffstat (limited to 'karlgui/src/helper.rs')
-rw-r--r--karlgui/src/helper.rs93
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"));
+ }
+ }
+}