diff --git a/src/config.rs b/src/config.rs index 68afdf0..bc190ef 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,18 +1,75 @@ use std::path::PathBuf; use serde::Deserialize; +#[derive(Deserialize)] +pub struct Colors { + pub background: u32, + pub timeline: u32, + pub background_text: u32 +} + #[derive(Deserialize)] pub struct Config { /// directory, where config is located #[serde(skip)] pub conf_path: PathBuf, - pub log_path: PathBuf + pub log_path: PathBuf, + pub colors: Colors, + pub event_colors: Vec, + pub text_colors: Vec } impl Config { pub fn new(conf_path: PathBuf) -> Self { let conf_dir: PathBuf = conf_path.parent().unwrap().into(); - Config { conf_path: conf_dir, log_path: PathBuf::from("./logs") } + let colors = Colors { + background: 0xff_808080, + timeline: 0xff_a9a9a9, + background_text: 0xff_000000 + }; + let event_colors: Vec = vec![ + 0xff_97f9f9, + 0xff_a4def9, + 0xff_c1e0f7, + 0xff_cfbae1, + 0xff_c59fc9, + 0xff_4e3d42, + 0xff_c9d5b5, + 0xff_2d82b7, + 0xff_556f44, + 0xff_772e25, + 0xff_c44536, + 0xff_7c6a0a, + 0xff_babd8d, + 0xff_ffdac6, + 0xff_fa9500, + 0xff_eb6424 + ]; + let text_colors: Vec = vec![ + 0xff000000, + 0xff000000, + 0xff000000, + 0xff000000, + 0xff000000, + 0xffffffff, + 0xff000000, + 0xff000000, + 0xff000000, + 0xffffffff, + 0xff000000, + 0xff000000, + 0xff000000, + 0xff000000, + 0xff000000, + 0xff000000 + ]; + Config { + conf_path: conf_dir, + log_path: PathBuf::from("./logs"), + colors, + event_colors, + text_colors + } } pub fn load(path: PathBuf) -> Self { diff --git a/src/main.rs b/src/main.rs index 19cb68d..9b1c5a0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ use std::{error::Error, rc::Rc, sync::{Arc, Mutex}}; use aliveline::{color_id_from_name, config::Config, load_config, log::{Event, Log}}; use chrono::{Datelike, Timelike}; -use slint::{Model, ModelRc, SharedString, ToSharedString, VecModel, Weak}; +use slint::{Color, Model, ModelRc, SharedString, ToSharedString, VecModel, Weak}; use toml::value::{Date as TomlDate, Time}; slint::include_modules!(); @@ -61,6 +61,26 @@ fn load_log(ui_weak: Weak, log: Arc>) { ui.set_in_progress(in_progress); } +fn load_colors(ui_weak: Weak, config: Arc) { + let ui = ui_weak.unwrap(); + let pal = ui.global::(); + pal.set_background(Color::from_argb_encoded(config.colors.background)); + pal.set_timeline(Color::from_argb_encoded(config.colors.timeline)); + pal.set_background_text(Color::from_argb_encoded(config.colors.background_text)); + + // This looks like war crime + let event_colors_rc: ModelRc = Rc::new(VecModel::from( + config.event_colors.iter() + .map(|value| Color::from_argb_encoded(*value)).collect::>() + )).into(); + pal.set_event_colors(event_colors_rc); + let event_text_rc: ModelRc = Rc::new(VecModel::from( + config.text_colors.iter() + .map(|value| Color::from_argb_encoded(*value)).collect::>() + )).into(); + pal.set_event_text(event_text_rc); +} + fn main() -> Result<(), Box> { let ui = AppWindow::new()?; @@ -80,6 +100,10 @@ fn main() -> Result<(), Box> { let log = writing_log.clone(); load_log(ui_weak, log); + let ui_weak = ui.as_weak(); + let config_arc = config.clone(); + load_colors(ui_weak, config_arc); + ui.invoke_update_record_offset(offset as i32); ui.on_fetch_log({ diff --git a/ui/app-window.slint b/ui/app-window.slint index 7137014..7535149 100644 --- a/ui/app-window.slint +++ b/ui/app-window.slint @@ -2,6 +2,7 @@ import { TabWidget } from "std-widgets.slint"; import { RecordWidget } from "record.slint"; import { ReviewWidget } from "review.slint"; import { TimelineEvent } from "timeline.slint"; +export { Palette } from "theme.slint"; export component AppWindow inherits Window { callback start-new-event <=> record.start-new-event;