Configurable colors
This commit is contained in:
parent
ca3c171698
commit
1b6f8ef282
3 changed files with 85 additions and 3 deletions
|
@ -1,18 +1,75 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct Colors {
|
||||||
|
pub background: u32,
|
||||||
|
pub timeline: u32,
|
||||||
|
pub background_text: u32
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
/// directory, where config is located
|
/// directory, where config is located
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub conf_path: PathBuf,
|
pub conf_path: PathBuf,
|
||||||
pub log_path: PathBuf
|
pub log_path: PathBuf,
|
||||||
|
pub colors: Colors,
|
||||||
|
pub event_colors: Vec<u32>,
|
||||||
|
pub text_colors: Vec<u32>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn new(conf_path: PathBuf) -> Self {
|
pub fn new(conf_path: PathBuf) -> Self {
|
||||||
let conf_dir: PathBuf = conf_path.parent().unwrap().into();
|
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<u32> = 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<u32> = 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 {
|
pub fn load(path: PathBuf) -> Self {
|
||||||
|
|
26
src/main.rs
26
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 aliveline::{color_id_from_name, config::Config, load_config, log::{Event, Log}};
|
||||||
use chrono::{Datelike, Timelike};
|
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};
|
use toml::value::{Date as TomlDate, Time};
|
||||||
|
|
||||||
slint::include_modules!();
|
slint::include_modules!();
|
||||||
|
@ -61,6 +61,26 @@ fn load_log(ui_weak: Weak<AppWindow>, log: Arc<Mutex<Log>>) {
|
||||||
ui.set_in_progress(in_progress);
|
ui.set_in_progress(in_progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn load_colors(ui_weak: Weak<AppWindow>, config: Arc<Config>) {
|
||||||
|
let ui = ui_weak.unwrap();
|
||||||
|
let pal = ui.global::<Palette>();
|
||||||
|
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<Color> = Rc::new(VecModel::from(
|
||||||
|
config.event_colors.iter()
|
||||||
|
.map(|value| Color::from_argb_encoded(*value)).collect::<Vec<Color>>()
|
||||||
|
)).into();
|
||||||
|
pal.set_event_colors(event_colors_rc);
|
||||||
|
let event_text_rc: ModelRc<Color> = Rc::new(VecModel::from(
|
||||||
|
config.text_colors.iter()
|
||||||
|
.map(|value| Color::from_argb_encoded(*value)).collect::<Vec<Color>>()
|
||||||
|
)).into();
|
||||||
|
pal.set_event_text(event_text_rc);
|
||||||
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let ui = AppWindow::new()?;
|
let ui = AppWindow::new()?;
|
||||||
|
|
||||||
|
@ -80,6 +100,10 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let log = writing_log.clone();
|
let log = writing_log.clone();
|
||||||
load_log(ui_weak, log);
|
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.invoke_update_record_offset(offset as i32);
|
||||||
|
|
||||||
ui.on_fetch_log({
|
ui.on_fetch_log({
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { TabWidget } from "std-widgets.slint";
|
||||||
import { RecordWidget } from "record.slint";
|
import { RecordWidget } from "record.slint";
|
||||||
import { ReviewWidget } from "review.slint";
|
import { ReviewWidget } from "review.slint";
|
||||||
import { TimelineEvent } from "timeline.slint";
|
import { TimelineEvent } from "timeline.slint";
|
||||||
|
export { Palette } from "theme.slint";
|
||||||
|
|
||||||
export component AppWindow inherits Window {
|
export component AppWindow inherits Window {
|
||||||
callback start-new-event <=> record.start-new-event;
|
callback start-new-event <=> record.start-new-event;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue