TGUI  0.9-beta

Executes callbacks after a certain amount of time. More...

#include <TGUI/Timer.hpp>

Inheritance diagram for tgui::Timer:

Public Member Functions

void setInterval (Duration interval)
 Changes the interval at which a timer callback is send. More...
 
Duration getInterval () const
 Returns the interval at which a timer callback is send. More...
 
void setEnabled (bool enabled)
 Starts or stops a timer. More...
 
bool isEnabled () const
 Returns whether the timer is running. More...
 
void setCallback (const std::function< void()> &callback)
 Changes the callback function that should be called by the timer at each interval. More...
 
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. More...
 
void restart ()
 Restarts the timer.
 

Static Public Member Functions

static std::shared_ptr< Timercreate (const std::function< void()> &callback, Duration interval, bool enable=true)
 Sets the time that the mouse has to stand still before the tooltip becomes visible. More...
 
static std::shared_ptr< Timercreate (const std::function< void(std::shared_ptr< Timer >)> &callback, Duration interval, bool enable=true)
 Sets the time that the mouse has to stand still before the tooltip becomes visible. More...
 
static void scheduleCallback (std::function< void()> callback, Duration interval=Duration())
 Starts a timer. More...
 

Detailed Description

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.

Member Function Documentation

◆ create() [1/2]

static std::shared_ptr<Timer> tgui::Timer::create ( const std::function< void()> &  callback,
Duration  interval,
bool  enable = true 
)
static

Sets the time that the mouse has to stand still before the tooltip becomes visible.

Parameters
callbackFunction without parameters, to be called at every interval when the timer is enabled
intervalHow often the callback should be called
enableShould 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]

static std::shared_ptr<Timer> tgui::Timer::create ( const std::function< void(std::shared_ptr< Timer >)> &  callback,
Duration  interval,
bool  enable = true 
)
static

Sets the time that the mouse has to stand still before the tooltip becomes visible.

Parameters
callbackFunction that takes the timer as parameter, to be called at every interval when the timer is enabled
intervalHow often the callback should be called
enableShould 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

Returns the interval at which a timer callback is send.

Returns
How often the callback should be called

◆ isEnabled()

bool tgui::Timer::isEnabled ( ) const

Returns whether the timer is running.

Returns
Is the timer currently enabled?

◆ scheduleCallback()

static void tgui::Timer::scheduleCallback ( std::function< void()>  callback,
Duration  interval = Duration() 
)
static

Starts a timer.

Parameters
callbackFunction to call at every interval when the timer is enabled
intervalTime 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
callbackFunction 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
callbackFunction 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
intervalHow often the callback should be called

The documentation for this class was generated from the following file: