.. index:: pair: class; EE::UI::UIDataBind .. _doxid-class_e_e_1_1_u_i_1_1_u_i_data_bind: template class EE::UI::UIDataBind ================================= .. toctree:: :hidden: class_EE_UI_UIDataBind_CallbackSlot.rst Overview ~~~~~~~~ Synchronizes a value with one or more :ref:`UIWidget ` properties. :ref:`More...` .. ref-code-block:: cpp :class: doxyrest-overview-code-block #include template class UIDataBind { public: // typedefs typedef T :target:`ValueType`; typedef :ref:`UIValueConverter` :target:`Converter`; typedef typename :ref:`ObservableValue`:::ref:`Callback` :target:`Callback`; typedef typename :ref:`ObservableValue`<:ref:`Uint64`>:::ref:`Connection` :target:`Connection`; // classes class :ref:`CallbackSlot`; // fields :ref:`CallbackSlot` :target:`onValueChangeCb`; // construction :target:`UIDataBind`(); :target:`UIDataBind`(const UIDataBind&); :target:`UIDataBind`(UIDataBind&&); :target:`UIDataBind`(T* t, const :ref:`UnorderedSet`<:ref:`UIWidget`*>& widgets, const :ref:`Converter`& converter = :ref:`Converter::converterDefault`(), const std::string& valueKey = "value", const :ref:`Event::EventType`& eventType = Event::OnValueChange); :target:`UIDataBind`(T* t, :ref:`UIWidget`* widget, const :ref:`Converter`& converter = :ref:`Converter::converterDefault`(), const std::string& valueKey = "value", const :ref:`Event::EventType`& eventType = Event::OnValueChange); :target:`UIDataBind`(std::shared_ptr value, const :ref:`UnorderedSet`<:ref:`UIWidget`*>& widgets, const :ref:`Converter`& converter = :ref:`Converter::converterDefault`(), const std::string& valueKey = "value", const :ref:`Event::EventType`& eventType = Event::OnValueChange); :target:`UIDataBind`(std::shared_ptr value, :ref:`UIWidget`* widget, const :ref:`Converter`& converter = :ref:`Converter::converterDefault`(), const std::string& valueKey = "value", const :ref:`Event::EventType`& eventType = Event::OnValueChange); :target:`~UIDataBind`(); // methods static :ref:`Converter` :target:`converterDefault`(); static :ref:`Converter` :target:`converterString`(); static :ref:`Converter` :target:`converterBool`(); static std::unique_ptr> :target:`New`(T* t, const :ref:`UnorderedSet`<:ref:`UIWidget`*>& widgets, const :ref:`Converter`& converter = :ref:`Converter::converterDefault`(), const std::string& valueKey = "value", const :ref:`Event::EventType`& eventType = Event::OnValueChange); static std::unique_ptr> :target:`New`(T* t, :ref:`UIWidget`* widget, const :ref:`Converter`& converter = :ref:`Converter::converterDefault`(), const std::string& valueKey = "value", const :ref:`Event::EventType`& eventType = Event::OnValueChange); static std::unique_ptr> :ref:`New`(std::shared_ptr value, const :ref:`UnorderedSet`<:ref:`UIWidget`*>& widgets, const :ref:`Converter`& converter = :ref:`Converter::converterDefault`(), const std::string& valueKey = "value", const :ref:`Event::EventType`& eventType = Event::OnValueChange); static std::unique_ptr> :ref:`New`(std::shared_ptr value, :ref:`UIWidget`* widget, const :ref:`Converter`& converter = :ref:`Converter::converterDefault`(), const std::string& valueKey = "value", const :ref:`Event::EventType`& eventType = Event::OnValueChange); UIDataBind& :target:`operator=`(const UIDataBind&); UIDataBind& :target:`operator=`(UIDataBind&&); void :target:`init`(T* t, :ref:`UIWidget`* widget, const :ref:`Converter`& converter = :ref:`Converter::converterDefault`(), const std::string& valueKey = "value", const :ref:`Event::EventType`& eventType = Event::OnValueChange); void :target:`init`(T* t, const :ref:`UnorderedSet`<:ref:`UIWidget`*>& widgets, const :ref:`Converter`& converter = :ref:`Converter::converterDefault`(), const std::string& valueKey = "value", const :ref:`Event::EventType`& eventType = Event::OnValueChange); void :ref:`init`(std::shared_ptr value, const :ref:`UnorderedSet`<:ref:`UIWidget`*>& widgets, const :ref:`Converter`& converter = :ref:`Converter::converterDefault`(), const std::string& valueKey = "value", const :ref:`Event::EventType`& eventType = Event::OnValueChange); void :ref:`init`(std::shared_ptr value, :ref:`UIWidget`* widget, const :ref:`Converter`& converter = :ref:`Converter::converterDefault`(), const std::string& valueKey = "value", const :ref:`Event::EventType`& eventType = Event::OnValueChange); template void :ref:`initRetained`(T* value, std::shared_ptr owner, Widgets&& widgets, const :ref:`Converter`& converter = :ref:`Converter::converterDefault`(), const std::string& valueKey = "value", const :ref:`Event::EventType`& eventType = Event::OnValueChange); :ref:`UIValueValidationResult` :ref:`set`(const T& t); :ref:`UIValueValidationResult` :ref:`set`(T&& t); const T& :target:`get`() const; :ref:`Connection` :ref:`observe`(:ref:`Callback` callback); bool :ref:`isInitialized`() const; void :ref:`reset`(); void :ref:`bind`(:ref:`UIWidget`* widget); void :ref:`unbind`(:ref:`UIWidget`* widget); const :ref:`PropertyDefinition`* :target:`getPropertyDefinition`() const; const :ref:`UnorderedSet`<:ref:`UIWidget`*>& :target:`getWidgets`() const; :ref:`UIWidget`* :ref:`getValidationEmitter`() const; :ref:`UIValueValidationState`& :ref:`validationState`(); const :ref:`UIValueValidationState`& :target:`validationState`() const; bool :target:`isValid`() const; }; .. _details-class_e_e_1_1_u_i_1_1_u_i_data_bind: Detailed Documentation ~~~~~~~~~~~~~~~~~~~~~~ Synchronizes a value with one or more :ref:`UIWidget ` properties. :ref:`UIDataBind ` observes each widget's value event and writes converted values back to the external object supplied at construction. Calling :ref:`set() ` updates that object and propagates the converted value to every bound widget. The converter maps directly between T and the widget property string. Its toValue() callback decides whether widget input is acceptable. Values passed to :ref:`set() ` are authoritative model state and are formatted through fromValue(). Raw-pointer bindings do not own their value. The external object must outlive the :ref:`UIDataBind ` and every synchronous callback delivery, or :ref:`reset() ` must be called before it is destroyed. The shared_ptr overload retains the value through binding lifetime and callback delivery without copying T. :ref:`UIProperty ` uses that retained form automatically. Widgets are also observed without ownership: EventConnection handles remove listeners when the binding dies, while the widget-level Event::OnClose notification removes widgets that die before the binding. All binding operations and widget events must run on the widgets' owning :ref:`UI ` thread. The class is non-copyable and non-movable because its listeners capture its address. Use :ref:`UIDataBind ` when adapting an existing externally owned value and its lifetime is already controlled by the caller. Prefer :ref:`UIProperty ` for small UI-local state, or :ref:`ObservableValue ` with :ref:`UIValueBinding ` when the model must publish changes without depending on the :ref:`UI `. .. ref-code-block:: cpp bool showDetails = false; auto binding = UIDataBind::New( &showDetails, checkbox, UIValueConverter::converterBool() ); // 'binding' must be destroyed or reset before 'showDetails'. Methods ------- .. index:: pair: function; New .. _doxid-class_e_e_1_1_u_i_1_1_u_i_data_bind_1acc52a864e096ba68e81033db0dd37222: .. ref-code-block:: cpp :class: doxyrest-title-code-block static std::unique_ptr> New(std::shared_ptr value, const :ref:`UnorderedSet`<:ref:`UIWidget`*>& widgets, const :ref:`Converter`& converter = :ref:`Converter::converterDefault`(), const std::string& valueKey = "value", const :ref:`Event::EventType`& eventType = Event::OnValueChange) Creates a binding that retains ``value`` through callback delivery. .. index:: pair: function; New .. _doxid-class_e_e_1_1_u_i_1_1_u_i_data_bind_1a049aad806a02d2db7a5a400ff5158e96: .. ref-code-block:: cpp :class: doxyrest-title-code-block static std::unique_ptr> New(std::shared_ptr value, :ref:`UIWidget`* widget, const :ref:`Converter`& converter = :ref:`Converter::converterDefault`(), const std::string& valueKey = "value", const :ref:`Event::EventType`& eventType = Event::OnValueChange) Creates a binding that retains ``value`` through callback delivery. .. index:: pair: function; init .. _doxid-class_e_e_1_1_u_i_1_1_u_i_data_bind_1acbc6c753b1c548ba6008e2958868a10b: .. ref-code-block:: cpp :class: doxyrest-title-code-block void init(std::shared_ptr value, const :ref:`UnorderedSet`<:ref:`UIWidget`*>& widgets, const :ref:`Converter`& converter = :ref:`Converter::converterDefault`(), const std::string& valueKey = "value", const :ref:`Event::EventType`& eventType = Event::OnValueChange) Reinitializes the binding while retaining ``value``. .. index:: pair: function; init .. _doxid-class_e_e_1_1_u_i_1_1_u_i_data_bind_1a148bf5da7de19eb4163957c4d4b34b3d: .. ref-code-block:: cpp :class: doxyrest-title-code-block void init(std::shared_ptr value, :ref:`UIWidget`* widget, const :ref:`Converter`& converter = :ref:`Converter::converterDefault`(), const std::string& valueKey = "value", const :ref:`Event::EventType`& eventType = Event::OnValueChange) Reinitializes the binding for one widget while retaining ``value``. .. index:: pair: function; initRetained .. _doxid-class_e_e_1_1_u_i_1_1_u_i_data_bind_1a1bba476cd79327e38e093fe51e017fa5: .. ref-code-block:: cpp :class: doxyrest-title-code-block template void initRetained(T* value, std::shared_ptr owner, Widgets&& widgets, const :ref:`Converter`& converter = :ref:`Converter::converterDefault`(), const std::string& valueKey = "value", const :ref:`Event::EventType`& eventType = Event::OnValueChange) Reinitializes the binding with externally retained storage. ``owner`` must keep ``value`` alive. This supports values embedded in a larger shared state without constructing an aliasing shared_ptr or allocating a separate value control block. .. index:: pair: function; set .. _doxid-class_e_e_1_1_u_i_1_1_u_i_data_bind_1a923c2b8a5356fe69da91148ac65393c5: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`UIValueValidationResult` set(const T& t) Propagates the authoritative model value and reports formatting failures. .. index:: pair: function; set .. _doxid-class_e_e_1_1_u_i_1_1_u_i_data_bind_1a43dcdc24faeb68544343d63a45dfdffb: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`UIValueValidationResult` set(T&& t) Propagates the authoritative model value and reports formatting failures. .. index:: pair: function; observe .. _doxid-class_e_e_1_1_u_i_1_1_u_i_data_bind_1a8abd02e75d035f7bf6036073abb00b61: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`Connection` observe(:ref:`Callback` callback) Observes later changes made through this binding. Direct writes through the external pointer cannot be observed; use :ref:`set() ` for model-originated changes that must be published. Notifications publish an integer revision internally, so T is never copied for observer delivery. Shared bindings retain their value in each observer adapter; raw bindings require the external value to survive the complete callback sequence. .. rubric:: Returns: A scoped connection, or an empty connection when the binding is not initialized. .. index:: pair: function; isInitialized .. _doxid-class_e_e_1_1_u_i_1_1_u_i_data_bind_1a2ca1aad9e8b545f90803a7cdcf8177ad: .. ref-code-block:: cpp :class: doxyrest-title-code-block bool isInitialized() const .. rubric:: Returns: True when the binding has a valid external value, property, and converter. .. index:: pair: function; reset .. _doxid-class_e_e_1_1_u_i_1_1_u_i_data_bind_1abb40182c79ba00a2ba2cd9b61396963a: .. ref-code-block:: cpp :class: doxyrest-title-code-block void reset() Disconnects every widget and releases the reference to the external value. After :ref:`reset() `, the binding must be initialized again before :ref:`get() ` or :ref:`set() ` is used. .. index:: pair: function; bind .. _doxid-class_e_e_1_1_u_i_1_1_u_i_data_bind_1aba090dea6da76fa3c248c58cf3e7cd8f: .. ref-code-block:: cpp :class: doxyrest-title-code-block void bind(:ref:`UIWidget`* widget) Adds ``widget`` to the synchronized widget set. Duplicate binds are ignored. .. index:: pair: function; unbind .. _doxid-class_e_e_1_1_u_i_1_1_u_i_data_bind_1af68f69421f80d3d71874fb3391f4de48: .. ref-code-block:: cpp :class: doxyrest-title-code-block void unbind(:ref:`UIWidget`* widget) Disconnects and removes ``widget`` from the synchronized widget set. .. index:: pair: function; getValidationEmitter .. _doxid-class_e_e_1_1_u_i_1_1_u_i_data_bind_1aad2da88402da9f2dc346bcd508a15ebe: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`UIWidget`* getValidationEmitter() const .. rubric:: Returns: The widget that produced the current input error, or nullptr for valid state or a model-to-widget formatting error. .. index:: pair: function; validationState .. _doxid-class_e_e_1_1_u_i_1_1_u_i_data_bind_1af5fa112685fb24c2838c601fed528c65: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`UIValueValidationState`& validationState() .. rubric:: Returns: Observable converter error state for this binding.