mirror of
https://github.com/slint-ui/slint.git
synced 2025-11-01 20:31:27 +00:00
Fix the slint_mock_elapsed_time when not using the testing backend
The nodejs tests don't use the testing backend, as a result, calling `platform::update_timers_and_animations` would use the real time instead of the fake time. So call `maybe_activate_timers` with the fake time instead
This commit is contained in:
parent
f954cb4ced
commit
adb1b24c28
3 changed files with 6 additions and 6 deletions
|
|
@ -166,7 +166,7 @@ pub fn set_platform(platform: Box<dyn Platform + 'static>) -> 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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue