diff --git a/src/lib.rs b/src/lib.rs index 485680e..9d6bbf2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,7 +40,8 @@ pub struct RustClock { custom_clock_bg_color: String, tips_store: String, show_tips: String, - font_path: String + font_path: String, + show_time: f32 } impl RustClock { @@ -58,7 +59,8 @@ impl RustClock { custom_number_color: String, custom_clock_bg_color: String, tips_store: String, - font_path: String + font_path: String, + show_time: f32 ) -> Result { Ok(RustClock { quit_index, @@ -76,6 +78,7 @@ impl RustClock { custom_clock_bg_color, tips_store, font_path, + show_time, ..RustClock::default() }) } @@ -135,6 +138,11 @@ impl eframe::App for RustClock { self.init_x = x as f32; } } + if self.show_time == 0.0 { + self.show_time = 100.0; + } else { + self.show_time = self.show_time / 16.0; + } } let mut begin_tik = |index, in_time_popup| { @@ -269,23 +277,23 @@ impl eframe::App for RustClock { } } if self.tikpop == true { - self.time += 2.0; + self.time += 1.0; frame.set_mouse_passthrough(false); - if self.time < 100.0 { - let mut add_x = (self.time / 200.0 * std::f32::consts::PI).sin() * 320.0; + if self.time < 50.0 { + let mut add_x = (self.time / 100.0 * std::f32::consts::PI).sin() * 320.0; if self.pos_dir == "right" { add_x = -add_x; } frame.set_window_pos(Pos2::new(self.init_x + add_x, self.init_y)); - } else if self.time > 250.0 && self.time < 350.0 { - let mut add_x = ((self.time - 250.0) / 200.0 * std::f32::consts::PI).sin() * 320.0; + } else if self.time > self.show_time + 50.0 && self.time < self.show_time + 100.0 { + let mut add_x = ((self.time - self.show_time - 50.0) / 100.0 * std::f32::consts::PI).sin() * 320.0; if self.pos_dir != "right" { add_x = -add_x; } else { add_x = self.init_x + add_x - 320.0; } frame.set_window_pos(Pos2::new(add_x, self.init_y)); - } else if self.time > 350.0 { + } else if self.time > self.show_time + 100.0 { self.tikpop = false; self.show_tips = "".to_string(); self.in_time_popup = false; @@ -324,12 +332,12 @@ impl eframe::App for RustClock { index = index + 1; } } + ctx.request_repaint_after(std::time::Duration::from_millis(300)); } if self.visible == true { clock_window_frame(ctx, frame, self, custom_clock); } - ctx.request_repaint_after(std::time::Duration::from_millis(300)); if let Ok(TrayEvent { event: tray_icon::ClickEvent::Left, diff --git a/src/main.rs b/src/main.rs index 9360349..16ae648 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,14 +18,17 @@ fn main() -> Result<(), eframe::Error> { let ini_path = dir.as_path(); let result = fs::read_to_string(ini_path); if let Err(_) = result { + let ini_default; #[cfg(target_os = "windows")] { - fs::write(ini_path, "[Config]\ntime=:30:,:00:\n#sound=assets/sound.ogg\n#countdown=:20:,::20\n#pos=left,5%\n#tips=by the grave and thee\n#font_path=C:/Windows/Fonts/msyh.ttc").unwrap() + ini_default = "[Config]\ntime=:30:,:00:\n#sound=assets/sound.ogg\n#countdown=:20:,::20\n#pos=left,5%\n#show_time=1000\n#tips=by the grave and thee\n#font_path=C:/Windows/Fonts/msyh.ttc"; } #[cfg(target_os = "macos")] { - fs::write(ini_path, "[Config]\ntime=:30:,:00:\n#sound=assets/sound.ogg\n#countdown=:20:,::20\n#pos=left,5%\n#tips=by the grave and thee\n#font_path=/System/Library/Fonts/STHeiti Light.ttc").unwrap() + ini_default = "[Config]\ntime=:30:,:00:\n#sound=assets/sound.ogg\n#countdown=:20:,::20\n#pos=left,5%\n#show_time=1000\n#tips=by the grave and thee\n#font_path=/System/Library/Fonts/STHeiti Light.ttc"; } + + fs::write(ini_path, ini_default).unwrap(); } let i = Ini::load_from_file(ini_path).unwrap(); @@ -42,6 +45,7 @@ fn main() -> Result<(), eframe::Error> { let mut custom_clock_bg_color = "".to_string(); let mut tips_store = "".to_string(); let mut font_path = "".to_string(); + let mut show_time = 0.0; for (sec, prop) in i.iter() { if let Some(s) = sec { if s == "Config" { @@ -73,6 +77,8 @@ fn main() -> Result<(), eframe::Error> { tips_store = v.to_string(); } else if k == "font_path" { font_path = v.to_string(); + } else if k == "show_time" { + show_time = v.to_string().parse::().unwrap(); } } } @@ -146,7 +152,8 @@ fn main() -> Result<(), eframe::Error> { custom_number_color, custom_clock_bg_color, tips_store, - font_path + font_path, + show_time ).unwrap()) }), )