29#include <TGUI/Config.hpp>
30#include <TGUI/Duration.hpp>
31#include <TGUI/Optional.hpp>
33#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
41TGUI_MODULE_EXPORT
namespace tgui
52 class TGUI_API
Timer :
public std::enable_shared_from_this<Timer>
56 using Ptr = std::shared_ptr<Timer>;
71 TGUI_NODISCARD
static std::shared_ptr<Timer>
create(
const std::function<
void()>& callback,
Duration interval,
bool enable =
true);
83 TGUI_NODISCARD
static std::shared_ptr<Timer>
create(
const std::function<
void(std::shared_ptr<Timer>)>& callback,
Duration interval,
bool enable =
true);
141 void setCallback(
const std::function<
void(std::shared_ptr<Timer>)>& callback);
156 static bool updateTime(
Duration elapsedTime);
164 TGUI_NODISCARD
static Optional<Duration> getNextScheduledTime();
171 static void clearTimers();
186 static std::vector<std::shared_ptr<Timer>> m_activeTimers;
188 bool m_repeats =
false;
189 bool m_enabled =
false;
191 std::function<void()> m_callback;
Wrapper for durations.
Definition Duration.hpp:56
Executes callbacks after a certain amount of time.
Definition Timer.hpp:53
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.
TGUI_NODISCARD Duration getInterval() const
Returns the interval at which a timer callback is send.
void setInterval(Duration interval)
Changes the interval at which a timer callback is send.
TGUI_NODISCARD bool isEnabled() const
Returns whether the timer is running.
void setEnabled(bool enabled)
Starts or stops a timer.
static void scheduleCallback(const std::function< void()> &callback, Duration interval=Duration())
Starts a timer.
static TGUI_NODISCARD 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()> &callback)
Changes the callback function that should be called by the timer at each interval.
static TGUI_NODISCARD 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:39