28#include <TGUI/Config.hpp>
29#include <TGUI/Duration.hpp>
30#include <TGUI/Optional.hpp>
32#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
40TGUI_MODULE_EXPORT
namespace tgui
51 class TGUI_API
Timer :
public std::enable_shared_from_this<Timer>
55 using Ptr = std::shared_ptr<Timer>;
69 TGUI_NODISCARD
static std::shared_ptr<Timer>
create(
const std::function<
void()>& callback,
Duration interval,
bool enable =
true);
80 TGUI_NODISCARD
static std::shared_ptr<Timer>
create(
const std::function<
void(std::shared_ptr<Timer>)>& callback,
Duration interval,
bool enable =
true);
131 void setCallback(
const std::function<
void(std::shared_ptr<Timer>)>& callback);
144 static bool updateTime(
Duration elapsedTime);
151 TGUI_NODISCARD
static Optional<Duration> getNextScheduledTime();
157 static void clearTimers();
170 static std::vector<std::shared_ptr<Timer>> m_activeTimers;
172 bool m_repeats =
false;
173 bool m_enabled =
false;
175 std::function<void()> m_callback;
Wrapper for durations.
Definition Duration.hpp:55
Executes callbacks after a certain amount of time.
Definition Timer.hpp:52
bool isEnabled() const
Returns whether the timer is running.
Duration getInterval() const
Returns the interval at which a timer callback is send.
static std::shared_ptr< Timer > create(const std::function< void()> &callback, Duration interval, bool enable=true)
Creates a new timer.
void setCallback(const std::function< void(std::shared_ptr< Timer >)> &callback)
Changes the callback function that should be called by the timer at each interval.
void restart()
Restarts the timer.
void setInterval(Duration interval)
Changes the interval at which a timer callback is send.
void setEnabled(bool enabled)
Starts or stops a timer.
static void scheduleCallback(const std::function< void()> &callback, Duration interval=Duration())
Starts a timer.
void setCallback(const std::function< void()> &callback)
Changes the callback function that should be called by the timer at each interval.
static std::shared_ptr< Timer > create(const std::function< void(std::shared_ptr< Timer >)> &callback, Duration interval, bool enable=true)
Creates a new timer.
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38