template class EE::UI::UIValueBinding

Overview

Move-only two-way binding between an ObservableValue and a UIWidget property. More…

#include <uivaluebinding.hpp>

template <typename T>
class UIValueBinding {
public:
    // typedefs

    typedef UIValueConverter<T> Converter;

    // structs

    struct State;

    // construction

    UIValueBinding();
    UIValueBinding(const UIValueBinding&);
    UIValueBinding(UIValueBinding&&);
    UIValueBinding(ObservableValue<T>& value, UIWidget* widget, const Converter& converter = converterDefault(), const std::string& propertyName = "value", Event::EventType eventType = Event::OnValueChange);

    // methods

    static Converter converterDefault();
    UIValueBinding& operator=(const UIValueBinding&);
    UIValueBinding& operator=(UIValueBinding&&);
    void disconnect();
    operator bool() const;
    bool isValid() const;
    UIValueValidationState* validationState();
    const UIValueValidationState* validationState() const;
};

Detailed Documentation

Move-only two-way binding between an ObservableValue and a UIWidget property.

The converter maps directly between T and the widget property string. Its toValue() callback decides whether widget input may enter the model. Model-originated values are authoritative and are formatted through fromValue().

Destroying the binding disconnects both directions. Destroying either the observable or widget first is safe and does not keep that endpoint alive.

Synchronization is immediate and single-threaded. The observable, widget, and binding must all be used on the widget’s owning UI thread.

Use UIValueBinding when an ObservableValue belongs to a UI-independent model. The returned binding must be retained for as long as synchronization is desired.

ObservableValue<std::string> userName{ "Ada" };
auto binding = bindValue( userName, textInput,
                     UIValueConverter<std::string>::converterString(),
                     "text", Event::OnTextChanged );
userName = "Grace"; // Updates textInput without coupling the model to UIWidget.

Methods

UIValueValidationState* validationState()

Returns:

Observable conversion and input-validation state.