[Refactor] Move hour_name_path to the svg_clock module

This commit is contained in:
Gergely Polonkai 2022-05-23 04:41:09 +02:00
parent 66e9c3d3f3
commit 7e8f62b811
No known key found for this signature in database
GPG Key ID: 2D2885533B869ED4
2 changed files with 27 additions and 22 deletions

View File

@ -20,7 +20,9 @@ use svg::Document;
mod svg_clock;
use svg_clock::{svg_to_usvg, HOUR_NAMES, HOUR_NAME_FONT_SIZE, IMAGE_WIDTH, OUTER_R, RING_WIDTH};
use svg_clock::{
hour_name_path, svg_to_usvg, HOUR_NAMES, HOUR_NAME_FONT_SIZE, IMAGE_WIDTH, OUTER_R, RING_WIDTH,
};
sctk::default_environment!(SeasonalClock, desktop);
@ -67,26 +69,6 @@ fn time_to_degrees(timestamp: i32, // should be time/timestamp
seconds_to_degrees(timestamp)
}
fn hour_name_path() -> Path {
let radius = OUTER_R - RING_WIDTH / 2.0;
let delta_x = radius * (15.0_f32.to_radians() / 2.0).sin();
let delta_y = radius * (1.0 - (15.0_f32.to_radians() / 2.0).cos());
let x1 = (IMAGE_WIDTH as f32) / 2.0 - delta_x;
let y1 = ((IMAGE_WIDTH as f32) / 2.0 - radius) + delta_y;
let path_data = PathData::new().move_to((x1, y1)).elliptical_arc_by((
radius,
radius,
15,
0,
1,
2.0 * delta_x,
0,
));
Path::new().set("id", "hour-name-path").set("d", path_data)
}
fn hour_marker(hour: i32, is_current_hour: bool, utc_hour_font_size: f32) -> Group {
let season = match hour {
0..=5 => Season::Winter,

View File

@ -1,4 +1,7 @@
use svg::Document;
use svg::{
node::element::{path::Data as PathData, Path},
Document,
};
use usvg::Tree;
pub const HOUR_NAMES: [&str; 24] = [
@ -20,3 +23,23 @@ pub fn svg_to_usvg(document: Document) -> Tree {
Tree::from_str(&doc_str, &opt.to_ref()).unwrap()
}
pub fn hour_name_path() -> Path {
let radius = OUTER_R - RING_WIDTH / 2.0;
let delta_x = radius * (15.0_f32.to_radians() / 2.0).sin();
let delta_y = radius * (1.0 - (15.0_f32.to_radians() / 2.0).cos());
let x1 = (IMAGE_WIDTH as f32) / 2.0 - delta_x;
let y1 = ((IMAGE_WIDTH as f32) / 2.0 - radius) + delta_y;
let path_data = PathData::new().move_to((x1, y1)).elliptical_arc_by((
radius,
radius,
15,
0,
1,
2.0 * delta_x,
0,
));
Path::new().set("id", "hour-name-path").set("d", path_data)
}