aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <yvchraiqi@protonmail.com>2022-08-17 17:08:06 +0200
committermetamuffin <yvchraiqi@protonmail.com>2022-08-17 17:08:06 +0200
commit9c7ab317d544a61df9f8f2c9aa80a0b1322d5100 (patch)
tree35bcf3f67c35fd966992389661497c2c0bb8a161
parenta31293af0938cc288e46d685bfa88d246767d2ad (diff)
downloadkarlender-9c7ab317d544a61df9f8f2c9aa80a0b1322d5100.tar
karlender-9c7ab317d544a61df9f8f2c9aa80a0b1322d5100.tar.bz2
karlender-9c7ab317d544a61df9f8f2c9aa80a0b1322d5100.tar.zst
a
-rw-r--r--karlgui/src/views/calendar.rs140
1 files changed, 67 insertions, 73 deletions
diff --git a/karlgui/src/views/calendar.rs b/karlgui/src/views/calendar.rs
index ecb70dd..0530def 100644
--- a/karlgui/src/views/calendar.rs
+++ b/karlgui/src/views/calendar.rs
@@ -1,6 +1,6 @@
use crate::{helper::weekday_to_str, Globals};
use chrono::{Datelike, Duration, NaiveDateTime, Timelike};
-use egui::{Color32, Label, Rect, ScrollArea, Sense, Stroke, Ui, Vec2};
+use egui::{Color32, Label, Layout, Rect, ScrollArea, Sense, Stroke, Ui, Vec2};
use egui_extras::{Size, StripBuilder};
use std::{collections::BTreeMap, ops::Range};
@@ -22,86 +22,80 @@ impl Calendar {
Some((id, g.get_instances_range(*id, start_dt, end_dt).to_owned()?))
}));
- let height = 2000.0;
+ let height = 1500.0;
ScrollArea::vertical().show(ui, |ui| {
- StripBuilder::new(ui)
- .size(Size::exact(50.0))
- .sizes(Size::remainder(), 7)
- .horizontal(|mut ui| {
- ui.cell(|ui| {
- for h in 0..24 {
- ui.add_sized(
- Vec2::new(50.0, height / 24.0),
- Label::new(&format!("{h:02}:00")),
- );
- }
- });
- for d in 0..7 {
- ui.cell(|ui| {
- let time = start_dt + Duration::days(d as i64);
- let time_end = time + Duration::days(1) - Duration::seconds(1);
- let instances_here = instances
- .iter()
- .map(|(id, rs)| {
- (
- id,
- rs.iter()
- .filter(|r| r.overlaps(time..time_end))
- .collect::<Vec<_>>(),
- )
- })
- .filter(|(_, l)| l.len() != 0);
+ ui.horizontal(|ui| {
+ ui.vertical(|ui| {
+ for h in 0..24 {
+ ui.add_sized(
+ Vec2::new(50.0, height / 24.0),
+ Label::new(&format!("{h:02}:00")),
+ );
+ }
+ });
+ for d in 0..7 {
+ ScrollArea::horizontal().show(ui, |ui| {
+ let time = start_dt + Duration::days(d as i64);
+ let time_end = time + Duration::days(1) - Duration::seconds(1);
+ let instances_here = instances
+ .iter()
+ .map(|(id, rs)| {
+ (
+ id,
+ rs.iter()
+ .filter(|r| r.overlaps(time..time_end))
+ .collect::<Vec<_>>(),
+ )
+ })
+ .filter(|(_, l)| l.len() != 0);
- ui.vertical(|ui| {
- ui.heading(weekday_to_str(
- time.date().weekday().num_days_from_monday().into(),
- ));
- ui.horizontal(|ui| {
- for (id, rs) in instances_here {
- let task = g.tasks.get(id).unwrap();
+ ui.vertical(|ui| {
+ ui.heading(weekday_to_str(
+ time.date().weekday().num_days_from_monday().into(),
+ ));
+ ui.horizontal(|ui| {
+ for (id, rs) in instances_here {
+ let task = g.tasks.get(id).unwrap();
- let (rect, response) = ui.allocate_exact_size(
- Vec2::new(10.0, height),
- Sense::hover(),
+ let (rect, response) = ui.allocate_exact_size(
+ Vec2::new(10.0, height),
+ Sense::hover(),
+ );
+
+ for r in &rs {
+ let r = r.start.unwrap_or(time)..r.end.unwrap_or(time_end);
+ let rect_start = (r.start.hour() as f32
+ + (r.start.minute() as f32 / 60.0))
+ / 24.0
+ * height;
+ let rect_end = (r.end.hour() as f32
+ + (r.end.minute() as f32 / 60.0))
+ / 24.0
+ * height;
+ ui.painter().rect(
+ Rect::from_two_pos(
+ rect.min + Vec2::new(0.0, rect_start),
+ rect.min + Vec2::new(10.0, rect_end),
+ ),
+ 0.0,
+ Color32::KHAKI,
+ Stroke::new(0.0, Color32::WHITE),
);
+ }
- for r in &rs {
- let r =
- r.start.unwrap_or(time)..r.end.unwrap_or(time_end);
- let rect_start = (r.start.hour() as f32
- + (r.start.minute() as f32 / 60.0))
- / 24.0
- * height;
- let rect_end = (r.end.hour() as f32
- + (r.end.minute() as f32 / 60.0))
- / 24.0
- * height;
- ui.painter().rect(
- Rect::from_two_pos(
- rect.min + Vec2::new(0.0, rect_start),
- rect.min + Vec2::new(10.0, rect_end),
- ),
- 0.0,
- Color32::KHAKI,
- Stroke::new(0.0, Color32::WHITE),
- );
+ response.on_hover_ui_at_pointer(|ui| {
+ ui.heading(&task.name);
+ if let Some(d) = &task.description {
+ ui.label(d);
}
-
- response.on_hover_ui_at_pointer(|ui| {
- ui.heading(&task.name);
- if let Some(d) = &task.description {
- ui.label(d);
- }
- });
- }
- })
- });
- // });
- // });
+ });
+ }
+ })
});
- }
- });
+ });
+ }
+ });
});
// TableBuilder::new(ui)