[Refactor] Move hour_name_path to the svg_clock module
This commit is contained in:
parent
66e9c3d3f3
commit
7e8f62b811
24
src/main.rs
24
src/main.rs
@ -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,
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user