[Refactor] Move hour name calculation to the clock module
This commit is contained in:
parent
d9017d447a
commit
5095d2cc9f
10
src/clock.rs
10
src/clock.rs
@ -6,6 +6,12 @@ use suncalc::SunTimes;
|
||||
|
||||
use crate::config::Config;
|
||||
|
||||
const HOUR_NAMES: [&str; 24] = [
|
||||
"Candle", "Ice", "Comet", "Thimble", "Root", "Mist", "Sprout", "Rainbow", "Worm", "Bud",
|
||||
"Blossom", "Ladybug", "Geese", "Dust", "Peach", "Fog", "Acorn", "Gourd", "Soup", "Crow",
|
||||
"Mushroom", "Thunder", "Frost", "Lantern",
|
||||
];
|
||||
|
||||
pub enum DayPart {
|
||||
LocalNow,
|
||||
UtcNow,
|
||||
@ -98,3 +104,7 @@ pub fn get_hms(config: &Option<Config>, which: DayPart) -> (u8, u8, u8) {
|
||||
pub fn get_utc_offset() -> i32 {
|
||||
Local::now().offset().local_minus_utc()
|
||||
}
|
||||
|
||||
pub fn get_utc_hour_name(hour: usize) -> &'static str {
|
||||
HOUR_NAMES[hour]
|
||||
}
|
||||
|
@ -13,14 +13,11 @@ use svg::{
|
||||
};
|
||||
use usvg::Tree;
|
||||
|
||||
use crate::clock::{get_hms, get_moon_phase, get_seconds_since_midnight, get_utc_offset, DayPart};
|
||||
use crate::clock::{
|
||||
get_hms, get_moon_phase, get_seconds_since_midnight, get_utc_hour_name, get_utc_offset, DayPart,
|
||||
};
|
||||
use crate::config::Config;
|
||||
|
||||
const HOUR_NAMES: [&str; 24] = [
|
||||
"Candle", "Ice", "Comet", "Thimble", "Root", "Mist", "Sprout", "Rainbow", "Worm", "Bud",
|
||||
"Blossom", "Ladybug", "Geese", "Dust", "Peach", "Fog", "Acorn", "Gourd", "Soup", "Crow",
|
||||
"Mushroom", "Thunder", "Frost", "Lantern",
|
||||
];
|
||||
const IMAGE_WIDTH: u32 = 700;
|
||||
const HOUR_NAME_FONT_SIZE: f32 = IMAGE_WIDTH as f32 * 0.019109;
|
||||
const OUTER_R: f32 = (IMAGE_WIDTH as f32) / 2.0 - 3.0 * HOUR_NAME_FONT_SIZE;
|
||||
@ -90,7 +87,7 @@ fn create_temp_document(hour: usize) -> Document {
|
||||
let hour_name_text_path = TextPath::new()
|
||||
.set("xlink:href", "#hour-name-path")
|
||||
.set("startOffset", "50%")
|
||||
.add(TextNode::new(HOUR_NAMES[hour]));
|
||||
.add(TextNode::new(get_utc_hour_name(hour)));
|
||||
let hour_name_text = Text::new()
|
||||
.set("id", "hour-name")
|
||||
.set("text-anchor", "middle")
|
||||
@ -598,7 +595,7 @@ pub fn gen_svg(
|
||||
"y",
|
||||
(current_box_height / 5.0) + (current_hour_name_font_size / 2.0),
|
||||
)
|
||||
.add(TextNode::new(HOUR_NAMES[utc_hour as usize]));
|
||||
.add(TextNode::new(get_utc_hour_name(utc_hour as usize)));
|
||||
|
||||
let current_time_text = Text::new()
|
||||
.set("font-size", current_time_font_size)
|
||||
|
Loading…
Reference in New Issue
Block a user