Executes callbacks after a certain amount of time.
More...
#include <TGUI/Timer.hpp>
|
|
using | Ptr = std::shared_ptr<Timer> |
|
|
| Timer (const Timer &)=delete |
|
Timer & | operator= (const Timer &)=delete |
| void | setInterval (Duration interval) |
| | Changes the interval at which a timer callback is send.
|
| Duration | getInterval () const |
| | Returns the interval at which a timer callback is send.
|
| void | setEnabled (bool enabled) |
| | Starts or stops a timer.
|
| bool | isEnabled () const |
| | Returns whether the timer is running.
|
| void | setCallback (const std::function< void()> &callback) |
| | Changes the callback function that should be called by the timer at each interval.
|
| 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.
|
|
| static std::shared_ptr< Timer > | create (const std::function< void()> &callback, Duration interval, bool enable=true) |
| | Creates a new timer.
|
| static std::shared_ptr< Timer > | create (const std::function< void(std::shared_ptr< Timer >)> &callback, Duration interval, bool enable=true) |
| | Creates a new timer.
|
| static void | scheduleCallback (const std::function< void()> &callback, Duration interval=Duration()) |
| | Starts a timer.
|
|
static bool | updateTime (Duration elapsedTime) |
|
static Optional< Duration > | getNextScheduledTime () |
|
static void | clearTimers () |
Executes callbacks after a certain amount of time.
The static create method will create a timer object that you can start and stop. The static scheduleCallback method is for when the timer only needs to be triggered a single time.
This timer is not intended to be used when high accuracy is required. If the callback is e.g. a millisecond too late then this extra time is NOT subtracted from the next scheduled time.
◆ create() [1/2]
| std::shared_ptr< Timer > tgui::Timer::create |
( |
const std::function< void()> & | callback, |
|
|
Duration | interval, |
|
|
bool | enable = true ) |
|
staticnodiscard |
Creates a new timer.
- Parameters
-
| callback | Function without parameters, to be called at every interval when the timer is enabled |
| interval | How often the callback should be called |
| enable | Should the timer be started immediately? |
- Returns
- The created timer that can be used to start/stop it later or change the interval.
◆ create() [2/2]
| std::shared_ptr< Timer > tgui::Timer::create |
( |
const std::function< void(std::shared_ptr< Timer >)> & | callback, |
|
|
Duration | interval, |
|
|
bool | enable = true ) |
|
staticnodiscard |
Creates a new timer.
- Parameters
-
| callback | Function that takes the timer as parameter, to be called at every interval when the timer is enabled |
| interval | How often the callback should be called |
| enable | Should the timer be started immediately? |
- Returns
- The created timer that can be used to start/stop it later or change the interval.
◆ getInterval()
| Duration tgui::Timer::getInterval |
( |
| ) |
const |
|
nodiscard |
Returns the interval at which a timer callback is send.
- Returns
- How often the callback should be called
◆ isEnabled()
| bool tgui::Timer::isEnabled |
( |
| ) |
const |
|
nodiscard |
Returns whether the timer is running.
- Returns
- Is the timer currently enabled?
◆ scheduleCallback()
| void tgui::Timer::scheduleCallback |
( |
const std::function< void()> & | callback, |
|
|
Duration | interval = Duration() ) |
|
static |
Starts a timer.
- Parameters
-
| callback | Function to call at every interval when the timer is enabled |
| interval | Time until callback should occur. Don't pass this parameter to call the callback at the next update. |
There is no way to cancel a scheduled call. If you need this functionality then you should create a proper timer (with the create function) which you then stop when the callback happens.
◆ setCallback() [1/2]
| void tgui::Timer::setCallback |
( |
const std::function< void()> & | callback | ) |
|
Changes the callback function that should be called by the timer at each interval.
- Parameters
-
| callback | Function without parameters, to be called at every interval when the timer is enabled |
◆ setCallback() [2/2]
| void tgui::Timer::setCallback |
( |
const std::function< void(std::shared_ptr< Timer >)> & | callback | ) |
|
Changes the callback function that should be called by the timer at each interval.
- Parameters
-
| callback | Function that takes the timer as parameter, to be called at every interval when the timer is enabled |
◆ setEnabled()
| void tgui::Timer::setEnabled |
( |
bool | enabled | ) |
|
Starts or stops a timer.
When enabling a timer that is already enabled, the timer will be restarted.
◆ setInterval()
| void tgui::Timer::setInterval |
( |
Duration | interval | ) |
|
Changes the interval at which a timer callback is send.
- Parameters
-
| interval | How often the callback should be called |
The documentation for this class was generated from the following file: