Timer Element

Closes #5724
This commit is contained in:
Olivier Goffart 2024-08-15 13:02:05 +02:00
parent 2643a327e8
commit a9f526491a
25 changed files with 599 additions and 14 deletions

View file

@ -7,6 +7,7 @@
#include <chrono>
#include <optional>
#include <slint_timer_internal.h>
namespace slint {
@ -59,6 +60,16 @@ struct Timer
void restart() { cbindgen_private::slint_timer_restart(id); }
/// Returns true if the timer is running; false otherwise.
bool running() const { return cbindgen_private::slint_timer_running(id); }
/// Returns the interval of the timer.
/// Returns `nullopt` if the timer is not running.
std::optional<std::chrono::milliseconds> interval() const
{
int64_t val = cbindgen_private::slint_timer_interval(id);
if (val < 0) {
return std::nullopt;
}
return std::chrono::milliseconds(val);
}
/// Call the callback after the given duration.
template<std::invocable F>