Skip to content

Commit

Permalink
state.toast_cooldown is an Instant
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrabovets committed Jul 23, 2023
1 parent aae6951 commit 19a730c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/appstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub struct OculanteState {
pub always_on_top: bool,
pub network_mode: bool,
/// how long the toast message appears
pub toast_cooldown: f32,
pub toast_cooldown: Instant,
/// data to transform image once fullscreen is entered/left
pub fullscreen_offset: Option<(i32, i32)>,
/// List of images to cycle through. Usually the current dir or dropped files
Expand Down Expand Up @@ -188,7 +188,7 @@ impl Default for OculanteState {
always_on_top: Default::default(),
network_mode: Default::default(),
window_size: Default::default(),
toast_cooldown: Default::default(),
toast_cooldown: Instant::now(),
fullscreen_offset: Default::default(),
scrubber: Default::default(),
checker_texture: Default::default(),
Expand Down
8 changes: 3 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ fn update(app: &mut App, state: &mut OculanteState) {
// check if a new message has been sent
if let Ok(msg) = state.message_channel.1.try_recv() {
debug!("Received message: {:?}", msg);
state.toast_cooldown = 0.;
state.toast_cooldown = Instant::now();
match msg {
Message::LoadError(_) => {
state.current_image = None;
Expand Down Expand Up @@ -990,7 +990,7 @@ fn drawe(app: &mut App, gfx: &mut Graphics, plugins: &mut Plugins, state: &mut O
let egui_output = plugins.egui(|ctx| {
// the top menu bar

if state.show_metadata_tooltip && !state.settings_enabled && state.cursor_within_image() {
if state.show_metadata_tooltip && !state.pointer_over_ui && state.cursor_within_image() {
let pos_y = TOP_MENU_HEIGHT + 5. + if state.current_image_is_favourite {STAR.y} else {0.};

show_tooltip_at(
Expand Down Expand Up @@ -1054,14 +1054,12 @@ fn drawe(app: &mut App, gfx: &mut Graphics, plugins: &mut Plugins, state: &mut O
ui.ctx().request_repaint();
},
);
let max_anim_len = 2.5;

// using delta does not work with rfd
// state.toast_cooldown += app.timer.delta_f32();
state.toast_cooldown += 0.01;
// debug!("cooldown {}", state.toast_cooldown);

if state.toast_cooldown > max_anim_len {
if state.toast_cooldown.elapsed() > Duration::from_secs(3u64) {
state.message = None;
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,7 @@ pub fn edit_ui(app: &mut App, ctx: &Context, state: &mut OculanteState, gfx: &mu
state.send_message_err(&format!("Error: Could not save: {e}"));
}
}
state.toast_cooldown = 0.0;
state.toast_cooldown = Instant::now();
ui.ctx().request_repaint();
}
}
Expand Down Expand Up @@ -1771,7 +1771,9 @@ pub fn main_menu(ui: &mut Ui, state: &mut OculanteState, app: &mut App, gfx: &mu
// toggle_fullscreen(app, state);
// }

if unframed_button("⛶", ui).clicked() {
if unframed_button("⛶", ui)
.on_hover_text("Fullscreen")
.clicked() {
toggle_fullscreen(app, state);
}

Expand Down

0 comments on commit 19a730c

Please sign in to comment.