Skip to content

Commit

Permalink
show_time
Browse files Browse the repository at this point in the history
  • Loading branch information
hoothin committed Jun 8, 2023
1 parent c2dce2c commit 24334b4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
26 changes: 17 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<RustClock, &'static str> {
Ok(RustClock {
quit_index,
Expand All @@ -76,6 +78,7 @@ impl RustClock {
custom_clock_bg_color,
tips_store,
font_path,
show_time,
..RustClock::default()
})
}
Expand Down Expand Up @@ -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| {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 10 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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" {
Expand Down Expand Up @@ -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::<f32>().unwrap();
}
}
}
Expand Down Expand Up @@ -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())
}),
)
Expand Down

0 comments on commit 24334b4

Please sign in to comment.