[Refactor] Convert utc_hour_font_size to a constant
This commit is contained in:
parent
2fd9d4e8de
commit
f567362c29
11
src/main.rs
11
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<Config>, 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<Config>, hour_name_path_cache: &[PathData; 24]) -> Do
|
||||
hour,
|
||||
&hour_name_path_cache[hour as usize],
|
||||
hour == utc_hour as i32,
|
||||
utc_hour_font_size,
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user