mirror of
https://github.com/slint-ui/slint.git
synced 2025-11-17 18:57:10 +00:00
C++ platform: duration_until_next_timer_update and change return type of duration_since_start
This commit is contained in:
parent
de532d372a
commit
81bb6e2c70
3 changed files with 158 additions and 4 deletions
|
|
@ -216,7 +216,7 @@ public:
|
|||
/// Returns the amount of milliseconds since start of the application.
|
||||
///
|
||||
/// This function should only be implemented if the runtime is compiled with no_std
|
||||
virtual uint64_t duration_since_start() const { return 0; }
|
||||
virtual std::chrono::milliseconds duration_since_start() const { return {}; }
|
||||
|
||||
/// Spins an event loop and renders the visible windows.
|
||||
virtual void run_event_loop() { }
|
||||
|
|
@ -248,7 +248,7 @@ public:
|
|||
(void)w.release();
|
||||
},
|
||||
[](void *p) -> uint64_t {
|
||||
return reinterpret_cast<const Platform *>(p)->duration_since_start();
|
||||
return reinterpret_cast<const Platform *>(p)->duration_since_start().count();
|
||||
},
|
||||
[](void *p) { return reinterpret_cast<Platform *>(p)->run_event_loop(); },
|
||||
[](void *p) { return reinterpret_cast<Platform *>(p)->quit_event_loop(); },
|
||||
|
|
@ -427,6 +427,19 @@ inline void update_timers_and_animations()
|
|||
cbindgen_private::slint_platform_update_timers_and_animations();
|
||||
}
|
||||
|
||||
/// Returns the duration until the next timer if there are pending timers
|
||||
inline std::optional<std::chrono::milliseconds> duration_until_next_timer_update()
|
||||
{
|
||||
uint64_t val = cbindgen_private::slint_platform_duration_until_next_timer_update();
|
||||
if (val == std::numeric_limits<uint64_t>::max()) {
|
||||
return std::nullopt;
|
||||
} else if (val >= uint64_t(std::chrono::milliseconds::max().count())) {
|
||||
return std::chrono::milliseconds::max();
|
||||
} else {
|
||||
return std::chrono::milliseconds(val);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue