HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Public Types | Public Member Functions
tt::detail::observable_base< T > Class Template Referenceabstract

#include <TTauri/Foundation/detail/observable_base.hpp>

Inheritance diagram for tt::detail::observable_base< T >:
tt::detail::observable_unary< std::string, tt::format10 > tt::detail::observable_unary< bool, OT > tt::detail::observable_unary< T, OT > tt::detail::observable_value< T > tt::detail::observable_cast< std::string, tt::format10 > tt::detail::observable_not< OT > tt::detail::observable_cast< T, OT >

Public Types

using callback_type = std::function<void(T const &)>
 
using time_point = typename hires_utc_clock::time_point
 
using duration = typename hires_utc_clock::duration
 

Public Member Functions

 observable_base (observable_base const &)=delete
 
 observable_base (observable_base &&)=delete
 
observable_baseoperator= (observable_base const &)=delete
 
observable_baseoperator= (observable_base &&)=delete
 
 observable_base () noexcept
 Constructor.
 
previous_value () const noexcept
 Get the previous value.
 
time_point time_when_last_modified () const noexcept
 Time when the value was modified last.
 
duration duration_since_last_modified () const noexcept
 Duration since the value was last modified.
 
float animation_progress (duration animation_duration) const noexcept
 The relative time since the start of the animation.
 
virtual T load () const noexcept=0
 Get the current value.
 
load (duration animation_duration) const noexcept
 Get the current value animated over the animation_duration.
 
virtual bool store (T const &new_value) noexcept=0
 Set the value.
 
size_t add_callback (callback_type callback) noexcept
 Add a callback as a listener.
 
void remove_callback (size_t id) noexcept
 Remove a callback.
 

Detailed Description

template<typename T>
class tt::detail::observable_base< T >

Observable abstract base class.

Objects of the observable_base class will notify listeners through callbacks of changes of its value.

This class does not hold the value itself, concrete subclasses will either hold the value or calculate the value on demand. In many cases concrete subclasses may be sub-expressions of other observable objects.

This object will also track the time when the value was last modified so that the value can be animated. Usefull when displaying the value as an animated graphic element. For calculating inbetween values it will keep track of the previous value.

Constructor & Destructor Documentation

◆ observable_base()

template<typename T >
tt::detail::observable_base< T >::observable_base ( )
inlinenoexcept

Constructor.

Member Function Documentation

◆ add_callback()

template<typename T >
size_t tt::detail::observable_base< T >::add_callback ( callback_type callback)
inlinenoexcept

Add a callback as a listener.

Parameters
callbackThe callback to register, the new value is passed as the first argument.
Returns
The id of the callback, used to unregister the callback.

◆ animation_progress()

template<typename T >
float tt::detail::observable_base< T >::animation_progress ( duration animation_duration) const
inlinenoexcept

The relative time since the start of the animation.

The relative time since the start of the animation according to the duration of the animation.

Parameters
Arelative value between 0.0 and 1.0.

◆ duration_since_last_modified()

template<typename T >
duration tt::detail::observable_base< T >::duration_since_last_modified ( ) const
inlinenoexcept

Duration since the value was last modified.

◆ load() [1/2]

template<typename T >
virtual T tt::detail::observable_base< T >::load ( ) const
pure virtualnoexcept

Get the current value.

The value is often calculated directly from the cached values retrieved from notifications down the chain.

Implemented in tt::detail::observable_cast< T, OT >, tt::detail::observable_not< OT >, tt::detail::observable_value< T >, and tt::detail::observable_cast< std::string, tt::format10 >.

◆ load() [2/2]

template<typename T >
T tt::detail::observable_base< T >::load ( duration animation_duration) const
inlinenoexcept

Get the current value animated over the animation_duration.

◆ previous_value()

template<typename T >
T tt::detail::observable_base< T >::previous_value ( ) const
inlinenoexcept

Get the previous value.

◆ remove_callback()

template<typename T >
void tt::detail::observable_base< T >::remove_callback ( size_t id)
inlinenoexcept

Remove a callback.

Parameters
idThe id of the callback returned by the add_callback() method.

◆ store()

template<typename T >
virtual bool tt::detail::observable_base< T >::store ( T const & new_value)
pure virtualnoexcept

Set the value.

The value is often not directly stored, but instead forwarded up the chain of observables. And then let the notifications flowing backward updated the cached values so that loads() will be quick.

Parameters
new_valueThe new value
Returns
true if the value was different from before.

Implemented in tt::detail::observable_cast< T, OT >, and tt::detail::observable_value< T >.

◆ time_when_last_modified()

template<typename T >
time_point tt::detail::observable_base< T >::time_when_last_modified ( ) const
inlinenoexcept

Time when the value was modified last.


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