From f567362c293207bbdf462590bc7c11595f2e5e33 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Mon, 23 May 2022 13:48:45 +0200 Subject: [PATCH] [Refactor] Convert utc_hour_font_size to a constant --- src/main.rs | 11 ++++------- src/svg_clock.rs | 1 + 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6861daa..3342ca6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,7 @@ mod svg_clock; use svg_clock::{ cache_hour_name_paths, svg_to_usvg, HOUR_NAMES, HOUR_NAME_FONT_SIZE, IMAGE_WIDTH, OUTER_R, - RING_WIDTH, + RING_WIDTH, UTC_HOUR_FONT_SIZE, }; sctk::default_environment!(SeasonalClock, desktop); @@ -72,7 +72,6 @@ fn hour_marker( hour: i32, hour_name_path_data: &PathData, is_current_hour: bool, - utc_hour_font_size: f32, ) -> Group { let season = match hour { 0..=5 => Season::Winter, @@ -94,7 +93,7 @@ fn hour_marker( let x1 = IMAGE_WIDTH as f32 / 2.0 - delta_x; let y1 = (IMAGE_WIDTH as f32 / 2.0 - OUTER_R) + delta_y; - let utc_hour_y = IMAGE_WIDTH as f32 / 2.0 - OUTER_R + RING_WIDTH + utc_hour_font_size; + let utc_hour_y = IMAGE_WIDTH as f32 / 2.0 - OUTER_R + RING_WIDTH + UTC_HOUR_FONT_SIZE; let path_data = PathData::new() .move_to((x1, y1)) @@ -125,7 +124,7 @@ fn hour_marker( .set("y", utc_hour_y) .set("text-anchor", "middle") .set("dominant-baseline", "mathematical") - .set("font-size", utc_hour_font_size) + .set("font-size", UTC_HOUR_FONT_SIZE) .add(TextNode::new(format!("U {:02}", hour))); Group::new() @@ -238,9 +237,8 @@ fn gen_svg(config: &Option, hour_name_path_cache: &[PathData; 24]) -> Do let moon_phase = moon_illumination.phase * 28.0; let local_hour_font_size = IMAGE_WIDTH as f32 * 0.02357; - let utc_hour_font_size = IMAGE_WIDTH as f32 * 0.021462; let sun_radius = IMAGE_WIDTH as f32 * 0.0142871; - let marker_radius = OUTER_R - RING_WIDTH - 2.0 * utc_hour_font_size; + let marker_radius = OUTER_R - RING_WIDTH - 2.0 * UTC_HOUR_FONT_SIZE; let border = Rectangle::new() .set("x", 0i32) @@ -316,7 +314,6 @@ fn gen_svg(config: &Option, hour_name_path_cache: &[PathData; 24]) -> Do hour, &hour_name_path_cache[hour as usize], hour == utc_hour as i32, - utc_hour_font_size, )); } diff --git a/src/svg_clock.rs b/src/svg_clock.rs index 1f246f8..1bc1a42 100644 --- a/src/svg_clock.rs +++ b/src/svg_clock.rs @@ -16,6 +16,7 @@ pub const IMAGE_WIDTH: u32 = 700; pub const HOUR_NAME_FONT_SIZE: f32 = IMAGE_WIDTH as f32 * 0.019109; pub const OUTER_R: f32 = (IMAGE_WIDTH as f32) / 2.0 - 3.0 * HOUR_NAME_FONT_SIZE; pub const RING_WIDTH: f32 = HOUR_NAME_FONT_SIZE * 3.0; +pub const UTC_HOUR_FONT_SIZE: f32 = IMAGE_WIDTH as f32 * 0.021462; pub fn svg_to_usvg(document: Document) -> Tree { let doc_str = document.to_string();