[Refactor] Move the config structs to a new module

This commit is contained in:
Gergely Polonkai 2022-05-23 18:04:37 +02:00
parent 48ace5dc01
commit b45a2bd8ee
No known key found for this signature in database
GPG Key ID: 2D2885533B869ED4
2 changed files with 15 additions and 13 deletions

13
src/config.rs Normal file
View File

@ -0,0 +1,13 @@
use serde::Deserialize;
#[derive(Deserialize, Copy, Clone)]
pub struct Config {
pub latitude: f64,
pub longitude: f64,
}
#[derive(Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct CompleteConfig {
pub seasonal_clock: Config,
}

View File

@ -9,14 +9,15 @@ use chrono::Timelike;
use sctk::reexports::client::protocol::{wl_shm, wl_surface};
use sctk::shm::AutoMemPool;
use sctk::window::{Event as WEvent, FallbackFrame};
use serde::Deserialize;
use svg::node::element::path::Data as PathData;
use svg::node::element::{Circle, Group, Line, Rectangle, Style, Text};
use svg::node::Text as TextNode;
use svg::Document;
mod config;
mod svg_clock;
use config::{CompleteConfig, Config};
use svg_clock::{
cache_hour_name_paths, get_moon_path, get_range_path, hour_marker, seconds_to_degrees,
svg_to_usvg, HOUR_NAMES, HOUR_NAME_FONT_SIZE, IMAGE_WIDTH, OUTER_R, RING_WIDTH,
@ -25,18 +26,6 @@ use svg_clock::{
sctk::default_environment!(SeasonalClock, desktop);
#[derive(Deserialize, Copy, Clone)]
struct Config {
latitude: f64,
longitude: f64,
}
#[derive(Deserialize)]
#[serde(rename_all = "kebab-case")]
struct CompleteConfig {
seasonal_clock: Config,
}
fn gen_svg(config: &Option<Config>, hour_name_path_cache: &[(PathData, PathData); 24]) -> Document {
let local_timestamp = Local::now();
let utc_hour = local_timestamp.with_timezone(&Utc).time().hour();