1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
pub mod client;
pub mod globals;
pub mod helper;
pub mod views;
use crate::{client::Client, globals::Globals};
use eframe::CreationContext;
use egui::CentralPanel;
use karlcommon::ServerboundPacket;
use log::info;
use views::{calendar::Calendar, edit::ShowAndEdit};
fn main() {
env_logger::init_from_env("LOG");
info!("starting native app");
eframe::run_native(
"karlender",
eframe::NativeOptions::default(),
Box::new(move |cc| Box::new(App::new(cc))),
)
}
struct App {
g: Globals,
current_tab: Tab,
show_and_edit: ShowAndEdit,
calendar: Calendar,
}
#[derive(PartialEq)]
enum Tab {
ShowAndEdit,
CalendarWeek,
}
impl App {
pub fn new(cc: &CreationContext) -> Self {
info!("app creation");
cc.egui_ctx.set_visuals(egui::Visuals::dark());
let mut client = Client::new();
info!("connected");
client.send(ServerboundPacket::ListTasks);
App {
current_tab: Tab::CalendarWeek,
g: Globals::new(client),
show_and_edit: Default::default(),
calendar: Default::default(),
}
}
}
impl eframe::App for App {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
self.g.update_network();
CentralPanel::default().show(ctx, |ui| {
ui.add_enabled_ui(!self.g.client.busy, |ui| {
ui.horizontal(|ui| {
ui.selectable_value(&mut self.current_tab, Tab::ShowAndEdit, "Tasks");
ui.selectable_value(&mut self.current_tab, Tab::CalendarWeek, "Calendar: Week");
});
ui.separator();
match self.current_tab {
Tab::ShowAndEdit => self.show_and_edit.ui(ui, &mut self.g),
Tab::CalendarWeek => self.calendar.ui(ui, &mut self.g),
}
});
});
}
}
|