ui::TwoWayField¶
Header: winui/core/Property.hpp.
Derives from ui::Binding< T >.
The type of an editable spec field: one the user changes and a two-way bind() writes back from (a text box's text, a slider's value, a selected_index, an is_open). It is a Binding
- A writable
Property<U>whose type loses some of the field's values does not compile:.value = levelwith aProperty<int> levelon a Slider, whose value is a double. Bind a property of the field's own type, or say one-way with bind_one_way(). Types that convert both ways without loss stay two-way (aProperty<float>on that same Slider). - A field that can be unset (a selection that can be empty, a check box's indeterminate state, an empty number box) is a
TwoWayField<std::optional<T>>, and a two-way bind() of aProperty<T>into it does not compile: the control can go unset, which the property cannot hold. Bind aProperty<std::optional<T>>, or bind_one_way().
A display field stays a plain Binding, and bind() of any property that converts goes into it one-way.
Example:
ui::Property<std::optional<std::size_t>> picked;
ui::Property<std::size_t> size{0};
ui::Property<int> volume{40};
ui::ComboBox{.items = {"Small", "Large"}, .selected_index = picked}; // two-way
ui::ComboBox{.items = {"Small", "Large"}, .selected_index = ui::bind_one_way(size)}; // one-way
ui::Slider{.value = ui::bind_one_way(volume)}; // one-way
// .selected_index = size does not compile: the dropdown can be left with
// nothing selected, which `size` cannot hold.
// .value = volume does not compile: a drag to 40.5 does not fit an int.
TwoWayField¶
A constant value-initialized T.
TwoWayField¶
Any binding of the field's own type: a constant, bind() or bind_one_way().
TwoWayField¶
bind_choice() into an index field that always shows a selection. A value not in the list leaves the selection where it is, and starts the field on the first choice.
TwoWayField¶
template <typename U>
TwoWayField(const TwoWayBinding<U>& two_way)
requires detail::LossyWriteBack<U, T> && (!detail::UnsetIntoPlain<U, T>)
Does not compile: a two-way bind() of a Property<U> that cannot hold every value of the field. See the class comment.
TwoWayField¶
template <typename S>
TwoWayField(S& source)
requires detail::is_source<S> && (!std::is_const_v<S>) && std::same_as<S, Property<detail::source_value_t<S>>> && detail::LossyWriteBack<detail::source_value_t<S>, T> && (!detail::UnsetIntoPlain<detail::source_value_t<S>, T>)
Does not compile: a writable Property<U> written straight into the field, the same two-way bind() as above. See the class comment.
TwoWayField¶
template <typename U>
TwoWayField(const TwoWayBinding<U>& two_way) = delete
requires detail::OptionalValue<T>::optional && (!detail::OptionalValue<U>::optional)
Deleted: a two-way bind() of a Property<U> into a field that can be unset. See the class comment.
TwoWayField¶
template <typename S>
TwoWayField(S& source) = delete
requires detail::is_source<S> && detail::PropertyBindsTo<detail::source_value_t<S>, T> && (!std::is_const_v<S>) && std::same_as<S, Property<detail::source_value_t<S>>> && detail::OptionalValue<T>::optional && (!detail::OptionalValue<detail::source_value_t<S>>::optional)
Deleted: a writable Property<U> written straight into a field that can be unset, which is the same two-way bind() as above. See the class comment.