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:
Olivier Goffart 2024-09-17 18:01:10 +02:00
parent bcdc3e1cee
commit d2bd5366f4
5 changed files with 13 additions and 20 deletions

View file

@ -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.