aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <yvchraiqi@protonmail.com>2022-08-18 18:01:25 +0200
committermetamuffin <yvchraiqi@protonmail.com>2022-08-18 18:01:25 +0200
commitfd5294bf2775330a48e8f049395b17498b9264b3 (patch)
tree1eac393e2aca23fc4a13b3a8d7f9abe8a8e0975e
parent3776e4acb8f18aac57ef489b7deb9e223d67611b (diff)
downloadkarlender-fd5294bf2775330a48e8f049395b17498b9264b3.tar
karlender-fd5294bf2775330a48e8f049395b17498b9264b3.tar.bz2
karlender-fd5294bf2775330a48e8f049395b17498b9264b3.tar.zst
height controls
-rw-r--r--karld/Cargo.toml2
-rw-r--r--karlgui/src/client.rs14
-rw-r--r--karlgui/src/globals.rs6
-rw-r--r--karlgui/src/helper.rs7
-rw-r--r--karlgui/src/main.rs19
-rw-r--r--karlgui/src/views/calendar.rs77
6 files changed, 81 insertions, 44 deletions
diff --git a/karld/Cargo.toml b/karld/Cargo.toml
index e5f79bd..2cfe55b 100644
--- a/karld/Cargo.toml
+++ b/karld/Cargo.toml
@@ -18,7 +18,7 @@ lazy_static = "1.4.0"
tungstenite = { version = "0.17.3", optional = true }
[features]
-default = ["unix"]
+default = []
full = ["unix", "stdio", "tcp", "websocket"]
websocket = ["dep:tungstenite"]
unix = []
diff --git a/karlgui/src/client.rs b/karlgui/src/client.rs
index b027cdc..731c6ff 100644
--- a/karlgui/src/client.rs
+++ b/karlgui/src/client.rs
@@ -1,9 +1,10 @@
use crossbeam_channel::Receiver;
-use karlcommon::{version, ClientboundPacket, ServerboundPacket};
+use karlcommon::{interfaces::unix_path, version, ClientboundPacket, ServerboundPacket};
use log::{debug, error};
use std::{
io::{BufRead, BufReader, Write},
os::unix::net::UnixStream,
+ process::exit,
thread,
};
@@ -14,7 +15,16 @@ pub struct Client {
}
impl Client {
- pub fn new(socket: UnixStream) -> Self {
+ pub fn new() -> Self {
+ let socket = match UnixStream::connect(unix_path()) {
+ Ok(s) => s,
+ Err(e) => {
+ error!("failed to connect to socket: {}", e);
+ error!("make sure that karld is running");
+ exit(1)
+ }
+ };
+
let (sender, receiver) = crossbeam_channel::unbounded();
let mut reader = BufReader::new(socket.try_clone().unwrap());
thread::spawn(move || loop {
diff --git a/karlgui/src/globals.rs b/karlgui/src/globals.rs
index f757f2e..cfbf57f 100644
--- a/karlgui/src/globals.rs
+++ b/karlgui/src/globals.rs
@@ -3,13 +3,13 @@ use chrono::NaiveDateTime;
use karlcommon::{ClientboundPacket, ServerboundPacket, Task};
use log::warn;
use std::{
- collections::{HashMap, VecDeque},
+ collections::{BTreeMap, HashMap, VecDeque},
ops::Range,
};
pub struct Globals {
pub client: Client,
- pub tasks: HashMap<u64, Task>,
+ pub tasks: BTreeMap<u64, Task>,
pub awaiting_instance_requests: VecDeque<(u64, Range<NaiveDateTime>)>,
pub instance_cache:
@@ -29,7 +29,7 @@ impl Globals {
while let Ok(p) = self.client.receiver.try_recv() {
match p {
ClientboundPacket::TaskList(t) => {
- self.tasks = HashMap::from_iter(t.into_iter().map(|e| (e.id, e)));
+ self.tasks = BTreeMap::from_iter(t.into_iter().map(|e| (e.id, e)));
}
ClientboundPacket::Sync => {
self.client.busy = false;
diff --git a/karlgui/src/helper.rs b/karlgui/src/helper.rs
index 4f8f4f4..0192173 100644
--- a/karlgui/src/helper.rs
+++ b/karlgui/src/helper.rs
@@ -97,3 +97,10 @@ pub fn month_to_str(value: i64) -> &'static str {
_ => "(invalid)",
}
}
+pub fn ordering_suffix(value: u32) -> &'static str {
+ match value {
+ 1 => "st",
+ 2 => "nd",
+ _ => "th",
+ }
+}
diff --git a/karlgui/src/main.rs b/karlgui/src/main.rs
index 6044496..d6bdc61 100644
--- a/karlgui/src/main.rs
+++ b/karlgui/src/main.rs
@@ -6,13 +6,13 @@ pub mod views;
use crate::{client::Client, globals::Globals};
use eframe::CreationContext;
use egui::CentralPanel;
-use karlcommon::{interfaces::unix_path, ServerboundPacket};
-use log::{error, info};
-use std::{os::unix::net::UnixStream, process::exit};
+use karlcommon::ServerboundPacket;
+use log::info;
use views::{calendar::Calendar, edit::ShowAndEdit};
fn main() {
env_logger::init();
+ info!("starting native app");
eframe::run_native(
"karlender",
eframe::NativeOptions::default(),
@@ -37,19 +37,10 @@ enum Tab {
impl App {
pub fn new(cc: &CreationContext) -> Self {
+ info!("app creation");
cc.egui_ctx.set_visuals(egui::Visuals::dark());
-
- let socket = match UnixStream::connect(unix_path()) {
- Ok(s) => s,
- Err(e) => {
- error!("failed to connect to socket: {}", e);
- exit(1)
- }
- };
-
- let mut client = Client::new(socket);
+ let mut client = Client::new();
info!("connected");
-
client.send(ServerboundPacket::ListTasks);
App {
current_tab: Tab::CalendarWeek,
diff --git a/karlgui/src/views/calendar.rs b/karlgui/src/views/calendar.rs
index 6bec067..2eca0cc 100644
--- a/karlgui/src/views/calendar.rs
+++ b/karlgui/src/views/calendar.rs
@@ -1,17 +1,29 @@
-use crate::{helper::weekday_to_str, Globals};
+use crate::{
+ helper::{month_to_str, ordering_suffix, weekday_to_str},
+ Globals,
+};
use chrono::{Datelike, Duration, NaiveDateTime, Timelike};
-use egui::{Color32, Rect, Sense, Stroke, Ui, Vec2};
+use egui::{Color32, Rect, Sense, Slider, Stroke, Ui, Vec2};
use egui_extras::{Size, TableBuilder};
use std::{collections::BTreeMap, ops::Range};
-#[derive(Default)]
pub struct Calendar {
- // offset: NaiveDate,
+ offset: i64,
+ height: f32,
+}
+
+impl Default for Calendar {
+ fn default() -> Self {
+ Self {
+ offset: 0,
+ height: 1500.0,
+ }
+ }
}
impl Calendar {
pub fn ui(&mut self, ui: &mut Ui, g: &mut Globals) {
- let start_date = chrono::Utc::now().date_naive(); //self.offset;
+ let start_date = chrono::Utc::now().date_naive() + chrono::Duration::days(self.offset);
let end_date = start_date + chrono::Duration::days(7);
let start_dt = start_date.and_hms(0, 0, 0);
let end_dt = end_date.and_hms(0, 0, 0);
@@ -22,7 +34,17 @@ impl Calendar {
Some((id, g.get_instances_range(*id, start_dt, end_dt).to_owned()?))
}));
- let height = 1500.0;
+ ui.add(
+ Slider::new(&mut self.height, 500.0..=5000.0)
+ .logarithmic(true)
+ .text("Line spacing"),
+ );
+ ui.add(
+ Slider::new(&mut self.offset, -28..=28)
+ .logarithmic(true)
+ .clamp_to_range(false)
+ .text("Offset by days"),
+ );
TableBuilder::new(ui)
.column(Size::exact(50.0))
@@ -31,24 +53,25 @@ impl Calendar {
tr.col(|_| {});
for d in 0..7 {
tr.col(|ui| {
- ui.heading(weekday_to_str(
- (start_dt + Duration::days(d as i64))
- .date()
- .weekday()
- .num_days_from_monday()
- .into(),
+ let d = (start_dt + Duration::days(d as i64)).date();
+ ui.heading(&format!(
+ "{} the {}{} {}",
+ weekday_to_str(d.weekday().num_days_from_monday().into()),
+ d.day(),
+ ordering_suffix(d.day()),
+ &month_to_str(d.month0() as i64)[..3]
));
});
}
})
.body(|mut tb| {
- tb.row(height, |mut tr| {
+ tb.row(self.height, |mut tr| {
tr.col(|ui| {
let (response, p) =
- ui.allocate_painter(Vec2::new(50.0, height), Sense::hover());
+ ui.allocate_painter(Vec2::new(50.0, self.height), Sense::hover());
for h in 0..24 {
p.text(
- response.rect.min + Vec2::new(0.0, h as f32 / 24.0 * height),
+ response.rect.min + Vec2::new(0.0, h as f32 / 24.0 * self.height),
egui::Align2::LEFT_TOP,
format!("{h:02}:00"),
egui::FontId::monospace(15.0),
@@ -76,7 +99,7 @@ impl Calendar {
let task = g.tasks.get(id).unwrap();
let (rect, response) = ui.allocate_exact_size(
- Vec2::new(10.0, height),
+ Vec2::new(10.0, self.height),
Sense::hover(),
);
@@ -85,11 +108,11 @@ impl Calendar {
let rect_start = (r.start.hour() as f32
+ (r.start.minute() as f32 / 60.0))
/ 24.0
- * height;
+ * self.height;
let rect_end = (r.end.hour() as f32
+ (r.end.minute() as f32 / 60.0))
/ 24.0
- * height;
+ * self.height;
let rect = Rect::from_two_pos(
rect.min + Vec2::new(0.0, rect_start),
rect.min + Vec2::new(10.0, rect_end),
@@ -109,15 +132,21 @@ impl Calendar {
});
}
}
- ui.painter().rect(
- rect,
- 0.0,
- Color32::KHAKI,
- Stroke::new(0.0, Color32::WHITE),
- );
+ ui.painter().rect_filled(rect, 5.0, Color32::KHAKI);
}
}
});
+
+ let mut p1 = ui.max_rect().left_top();
+ let mut p2 = ui.max_rect().right_top();
+ for _ in 0..24 {
+ ui.painter().line_segment(
+ [p1, p2],
+ Stroke::new(1.0, Color32::from_gray(50).additive()),
+ );
+ p1.y += self.height / 24.0;
+ p2.y += self.height / 24.0;
+ }
});
}
});