Observable single-value container.
More...
#include <Bindable.hpp>
|
|
| Bindable (T initial) |
| | Construct with an initial value.
|
|
| Bindable (const Bindable &)=delete |
|
Bindable & | operator= (const Bindable &)=delete |
|
| Bindable (Bindable &&)=delete |
|
Bindable & | operator= (Bindable &&)=delete |
|
const T & | get () const |
| | Read the current value.
|
| void | set (T v) |
| | Replace the value and notify subscribers if it changed.
|
| Subscription | onChanged (std::function< void(const T &)> cb, bool fireImmediately=false) |
| | Register a callback fired on value changes.
|
| template<typename W, typename Arg> |
| Subscription | bindTo (std::weak_ptr< W > widget, void(W::*method)(Arg), bool fireImmediately=false) |
| | Bind this value to a widget method.
|
|
template<typename W, typename Arg> |
| Subscription | bindTo (std::shared_ptr< W > widget, void(W::*method)(Arg), bool fireImmediately=false) |
| | Overload for shared_ptr widgets; forwards to the weak-pointer version.
|
template<typename T>
class ZenitUI::Bindable< T >
Observable single-value container.
- Template Parameters
-
| T | Value type; must be copy-constructible and support ==. |
- Examples
- 00_demo/main.cpp, 05_data_binding/main.cpp, and 07_dynamic_lists/main.cpp.
◆ bindTo()
template<typename T>
template<typename W, typename Arg>
Bind this value to a widget method.
- Template Parameters
-
| W | Widget type. |
| Arg | Argument type of the widget method; must be implicitly constructible from T. |
- Parameters
-
| widget | Weak pointer to the target widget. |
| method | Member function to call on change. |
| fireImmediately | When true, invoke method right away. |
- Returns
- A Subscription that unregisters on destruction.
The weak pointer is locked on every notification, so the widget can be destroyed independently of the subscription.
- Examples
- 00_demo/main.cpp.
◆ onChanged()
Register a callback fired on value changes.
- Parameters
-
| cb | Callback invoked with the new value. |
| fireImmediately | When true, invoke cb right away with the current value (before returning). |
- Returns
- A Subscription that unregisters on destruction.
- Examples
- 00_demo/main.cpp, and 05_data_binding/main.cpp.
◆ set()
Replace the value and notify subscribers if it changed.
Equality is compared on T; setting the same value is a no-op. Subscribers are snapshotted before dispatch, so a subscriber that (un)subscribes from within its callback does not invalidate the loop.
- Examples
- 00_demo/main.cpp.
The documentation for this class was generated from the following file: