A node property: a constant, or a slot — a reactive read, with a stable id when it was given one.
More...
|
| | Prop () |
| | The value-initialised constant.
|
template<typename U>
requires (!std::invocable<U&>) && detail::ConstantConvertible<U, T> |
| | Prop (U &&value) |
| | A constant.
|
template<typename F>
requires std::invocable<F&> && std::convertible_to<std::invoke_result_t<F&>, T> |
| | Prop (F binding) |
| | A slot without an id.
|
template<typename F>
requires std::invocable<F&> && std::convertible_to<std::invoke_result_t<F&>, T> |
| | Prop (SlotBinding< F > binding) |
| | A slot with an id, as ui::slot makes it.
|
| bool | isBound () const noexcept |
| | Whether this is a slot.
|
| T const & | constant () const |
| | The constant. Only valid when !isBound().
|
| std::function< T()> const & | binding () const |
| | The slot's read. Only valid when isBound().
|
| std::optional< SlotId > | slotId () const noexcept |
| | The slot's id.
|
| T | evaluate () const |
| | The current value: the constant, or the slot read once.
|
template<typename T>
class morph::ui::Prop< T >
A node property: a constant, or a slot — a reactive read, with a stable id when it was given one.
A constant is set on the widget once and creates no reactive node. A slot becomes an equality-gated reactive::Computed plus an reactive::Effect calling one widget setter. An input whose value is a slot is controlled: after a user's edit, the widget shows what the slot says. A constant is not re-asserted.
A braced list cannot initialise a Prop, because the constant constructor deduces its argument's type: name the type, as in .options = std::vector<ui::SelectOption>{{...}, {...}}.
- Template Parameters
-
| T | The property's value type. |
Definition at line 106 of file view.hpp.
template<typename T>
template<typename U>
requires (!std::invocable<U&>) && detail::ConstantConvertible<U, T>
A constant.
A callable is never a constant, even when it converts to T: a captureless lambda converts to a function pointer and that to bool, so Prop<bool>{[] { return false; }} would otherwise be the constant true.
A pointer does not become a bool constant and a floating-point value does not become an integral one; see detail::ConstantConvertible.
- Template Parameters
-
| U | A non-callable type that converts to T without changing the kind of value. |
- Parameters
-
Definition at line 124 of file view.hpp.
template<typename T>
template<typename F>
requires std::invocable<F&> && std::convertible_to<std::invoke_result_t<F&>, T>
A slot without an id.
The read must be callable: an empty std::function or a null function pointer is refused here, where the mistake is made, rather than when a mount first calls it.
- Template Parameters
-
| F | A callable taking no arguments and returning something convertible to T. |
- Parameters
-
| binding | Evaluated by the mount inside a Computed; every signal it reads is a dependency. |
- Exceptions
-
| std::invalid_argument | when binding is an empty std::function or a null function pointer. |
Definition at line 138 of file view.hpp.