diff --git a/internal/core/platform.rs b/internal/core/platform.rs index a3164d7d0..a969901b8 100644 --- a/internal/core/platform.rs +++ b/internal/core/platform.rs @@ -166,7 +166,7 @@ pub fn set_platform(platform: Box) -> Result<(), SetPlat /// This function should be called before rendering or processing input event, at the /// beginning of each event loop iteration. pub fn update_timers_and_animations() { - crate::timers::TimerList::maybe_activate_timers(); + crate::timers::TimerList::maybe_activate_timers(crate::animations::Instant::now()); crate::animations::update_animations(); } diff --git a/internal/core/tests.rs b/internal/core/tests.rs index 3059412f6..ae7a80aee 100644 --- a/internal/core/tests.rs +++ b/internal/core/tests.rs @@ -16,12 +16,13 @@ use crate::SharedString; /// This function will add some milliseconds to the fake time #[no_mangle] pub extern "C" fn slint_mock_elapsed_time(time_in_ms: u64) { - crate::animations::CURRENT_ANIMATION_DRIVER.with(|driver| { + let tick = crate::animations::CURRENT_ANIMATION_DRIVER.with(|driver| { let mut tick = driver.current_tick(); tick += core::time::Duration::from_millis(time_in_ms); - driver.update_animations(tick) + driver.update_animations(tick); + tick }); - crate::platform::update_timers_and_animations(); + crate::timers::TimerList::maybe_activate_timers(tick); } /// Simulate a click on a position within the component. diff --git a/internal/core/timers.rs b/internal/core/timers.rs index f0c079032..a861847b7 100644 --- a/internal/core/timers.rs +++ b/internal/core/timers.rs @@ -214,8 +214,7 @@ impl TimerList { /// Activates any expired timers by calling their callback function. Returns true if any timers were /// activated; false otherwise. - pub fn maybe_activate_timers() -> bool { - let now = Instant::now(); + pub fn maybe_activate_timers(now: Instant) -> bool { // Shortcut: Is there any timer worth activating? if TimerList::next_timeout().map(|timeout| now < timeout).unwrap_or(false) { return false;