aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <yvchraiqi@protonmail.com>2022-08-16 17:16:15 +0200
committermetamuffin <yvchraiqi@protonmail.com>2022-08-16 17:16:15 +0200
commit9a306095aa701f372242f3dcbb76a09b4694762d (patch)
treece16cf8191678b71405dbe8081d194282c7bfa31
parente247646c36fe2ba0133a3354204ca5b0e873b041 (diff)
downloadkarlender-9a306095aa701f372242f3dcbb76a09b4694762d.tar
karlender-9a306095aa701f372242f3dcbb76a09b4694762d.tar.bz2
karlender-9a306095aa701f372242f3dcbb76a09b4694762d.tar.zst
first editable
-rw-r--r--karlc/src/main.rs2
-rw-r--r--karlcommon/src/lib.rs1
-rw-r--r--karlcommon/src/misc.rs30
-rw-r--r--karlgui/src/main.rs102
4 files changed, 122 insertions, 13 deletions
diff --git a/karlc/src/main.rs b/karlc/src/main.rs
index b9ce981..ed09069 100644
--- a/karlc/src/main.rs
+++ b/karlc/src/main.rs
@@ -1,7 +1,7 @@
pub mod client;
pub mod pretty;
-use crate::pretty::fmt_condition;
+use crate::{pretty::fmt_condition, client::Client};
use chrono::{NaiveDateTime, Utc};
use clap::{Args, Parser, Subcommand};
use karlcommon::{socket_path, version, ClientboundPacket, Schedule, ServerboundPacket, Task};
diff --git a/karlcommon/src/lib.rs b/karlcommon/src/lib.rs
index f9cd9d4..bbe8b1e 100644
--- a/karlcommon/src/lib.rs
+++ b/karlcommon/src/lib.rs
@@ -1,5 +1,6 @@
pub mod protocol;
pub use protocol::*;
+pub mod misc;
use std::{
os::unix::prelude::MetadataExt,
diff --git a/karlcommon/src/misc.rs b/karlcommon/src/misc.rs
new file mode 100644
index 0000000..583ed27
--- /dev/null
+++ b/karlcommon/src/misc.rs
@@ -0,0 +1,30 @@
+use crate::Property;
+
+impl Property {
+ pub const VALUES: &'static [Property] = &[
+ Property::Year,
+ Property::Monthofyear,
+ Property::Weekofmonth,
+ Property::Dayofyear,
+ Property::Dayofmonth,
+ Property::Dayofweek,
+ Property::Hour,
+ Property::Minute,
+ Property::Second,
+ Property::Unix,
+ ];
+ pub fn to_str(self) -> &'static str {
+ match self {
+ Property::Year => "Year",
+ Property::Monthofyear => "Month of the year",
+ Property::Weekofmonth => "Week of the month",
+ Property::Dayofyear => "Day of the year",
+ Property::Dayofmonth => "Day of the month",
+ Property::Dayofweek => "Day of the week",
+ Property::Hour => "Hour",
+ Property::Minute => "Minute",
+ Property::Second => "Second",
+ Property::Unix => "Unix timestamp",
+ }
+ }
+}
diff --git a/karlgui/src/main.rs b/karlgui/src/main.rs
index f4f9696..b92d95b 100644
--- a/karlgui/src/main.rs
+++ b/karlgui/src/main.rs
@@ -2,8 +2,10 @@ pub mod client;
use crate::client::Client;
use eframe::CreationContext;
-use egui::{text::LayoutJob, CentralPanel, Color32, Response, TextFormat, Ui, Widget};
-use karlcommon::{socket_path, ClientboundPacket, Condition, Schedule, ServerboundPacket, Task};
+use egui::{text::LayoutJob, CentralPanel, Color32, DragValue, Response, TextFormat, Ui, Widget};
+use karlcommon::{
+ socket_path, ClientboundPacket, Condition, Property, Schedule, ServerboundPacket, Task,
+};
use log::{error, info};
use std::{
ops::{Deref, DerefMut, Range},
@@ -140,15 +142,10 @@ impl EditableWidget for Schedule {
duration,
condition,
} => {
- let mut j = LayoutJob::default();
- let f = TextFormat {
- italics: true,
- ..Default::default()
- };
- j.append("Dynamic with priority", 0.0, f.clone());
- j.append(&format!(" {} ", priority), 0.0, f.clone());
-
- ui.label(j);
+ ui.horizontal(|ui| {
+ ui.label("Dynamic with priority");
+ ui.label(&format!(" {} ", priority));
+ });
}
Schedule::Condition(c) => c.ui(ui, edit),
Schedule::Static(t) => t.ui(ui, edit),
@@ -158,7 +155,88 @@ impl EditableWidget for Schedule {
impl EditableWidget for Condition {
fn ui(&mut self, ui: &mut Ui, edit: bool) {
- ui.label("todo");
+ ui.group(|ui| match self {
+ Condition::Never => {
+ ui.label("never");
+ }
+ Condition::From(c) => {
+ ui.horizontal(|ui| {
+ ui.label("Starting from");
+ c.ui(ui, edit);
+ });
+ }
+ Condition::Or(cs) => {
+ ui.vertical(|ui| {
+ for (i, c) in cs.iter_mut().enumerate() {
+ ui.push_id(i, |ui| {
+ ui.horizontal(|ui| {
+ ui.label(if i != 0 { "or " } else { " " });
+ c.ui(ui, edit);
+ });
+ });
+ }
+ });
+ }
+ Condition::And(cs) => {
+ ui.vertical(|ui| {
+ for (i, c) in cs.iter_mut().enumerate() {
+ ui.push_id(i, |ui| {
+ ui.horizontal(|ui| {
+ ui.label(if i != 0 { "and" } else { "" });
+ c.ui(ui, edit);
+ });
+ });
+ }
+ });
+ }
+ Condition::Invert(c) => {
+ ui.horizontal(|ui| {
+ ui.label("not when");
+ c.ui(ui, edit);
+ });
+ }
+ Condition::Equal {
+ prop,
+ value,
+ modulus,
+ } => {
+ ui.horizontal(|ui| {
+ ui.label("when");
+ if edit {
+ egui::ComboBox::from_id_source(ui.id())
+ .selected_text(prop.to_str())
+ .show_ui(ui, |ui| {
+ for v in Property::VALUES {
+ ui.selectable_value(prop, *v, v.to_str());
+ }
+ });
+ } else {
+ ui.label(&format!("{:?}", prop));
+ }
+ ui.label("=");
+ if edit {
+ ui.add(DragValue::new(value));
+ } else {
+ ui.label(&format!("{}", value));
+ }
+ });
+ }
+ Condition::Range {
+ prop,
+ min,
+ max,
+ modulus,
+ } => {
+ ui.horizontal(|ui| {
+ ui.label("when ");
+ ui.label(&format!("{}", min));
+ ui.label("≤");
+ ui.label(&format!("{:?}", prop));
+ ui.label("<");
+ ui.label(&format!("{}", max))
+ });
+ }
+ });
}
}