mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 02:39:28 +00:00
Timer::set_interval
Don't return an Option, just return 0 when the timer is not started. As discussed in the API review, the rational is that the interval is just like a field in a struct and when the struct is default constructed, it is initialized to 0
This commit is contained in:
parent
bcdc3e1cee
commit
d2bd5366f4
5 changed files with 13 additions and 20 deletions
|
@ -6,8 +6,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
|
||||
#include <optional>
|
||||
#include <slint_timer_internal.h>
|
||||
|
||||
namespace slint {
|
||||
|
@ -61,14 +59,10 @@ struct Timer
|
|||
/// 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
|
||||
/// Returns 0 if the timer was never started.
|
||||
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);
|
||||
return std::chrono::milliseconds(cbindgen_private::slint_timer_interval(id));
|
||||
}
|
||||
|
||||
/// Call the callback after the given duration.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue