template class EE::UI::UIProperty

Overview

Owns a value and exposes it as a UIDataBind-backed widget property. More…

#include <uiproperty.hpp>

template <typename T>
class UIProperty {
public:
    // construction

    UIProperty(const UIProperty&);
    UIProperty(UIProperty&&);
    UIProperty(T defaultValue, UIWidget* widget, const typename EE::UI::UIDataBind<T>::Converter& converter = EE::UI::UIDataBind<T>::converterDefault(), const std::string& valueKey = "value", const Event::EventType& eventType = Event::OnValueChange);
    UIProperty(T defaultValue, const UnorderedSet<UIWidget*>& widgets = {}, const typename EE::UI::UIDataBind<T>::Converter& converter = EE::UI::UIDataBind<T>::converterDefault(), const std::string& valueKey = "value", const Event::EventType& eventType = Event::OnValueChange);
    UIProperty(const UnorderedSet<UIWidget*>& widgets = {}, const typename EE::UI::UIDataBind<T>::Converter& converter = EE::UI::UIDataBind<T>::converterDefault(), const std::string& valueKey = "value", const Event::EventType& eventType = Event::OnValueChange);
    UIProperty(UIWidget* widget, const typename EE::UI::UIDataBind<T>::Converter& converter = EE::UI::UIDataBind<T>::converterDefault(), const std::string& valueKey = "value", const Event::EventType& eventType = Event::OnValueChange);

    // methods

    template <typename U = T, std::enable_if_t<(std::is_arithmetic_v<U>&&!std::is_same_v<U, bool>>
    UIProperty& operator+=(const T& operand);

    template <typename U = T, std::enable_if_t<std::is_same_v<U, std::string>||std::is_same_v<U, String>, int> = 0>
    T operator+(const T& operand) const;

    template <typename U = T, std::enable_if_t<std::is_arithmetic_v<U>&&!std::is_same_v<U, bool>, int> = 0>
    UIProperty& operator-=(const T& operand);

    template <typename U = T, std::enable_if_t<std::is_arithmetic_v<U>&&!std::is_same_v<U, bool>, int> = 0>
    UIProperty& operator*=(const T& operand);

    template <typename U = T, std::enable_if_t<std::is_arithmetic_v<U>&&!std::is_same_v<U, bool>, int> = 0>
    UIProperty& operator/=(const T& operand);

    template <typename U = T, std::enable_if_t<std::is_arithmetic_v<U>&&!std::is_same_v<U, bool>, int> = 0>
    UIProperty& operator++();

    template <typename U = T, std::enable_if_t<std::is_arithmetic_v<U>&&!std::is_same_v<U, bool>, int> = 0>
    T operator++(int);

    template <typename U = T, std::enable_if_t<std::is_arithmetic_v<U>&&!std::is_same_v<U, bool>, int> = 0>
    UIProperty& operator--();

    template <typename U = T, std::enable_if_t<std::is_arithmetic_v<U>&&!std::is_same_v<U, bool>, int> = 0>
    T operator--(int);

    UIProperty& operator=(const UIProperty&);
    UIProperty& operator=(UIProperty&&);
    UIProperty& operator=(const T& newVal);
    UIProperty& operator=(T&& newVal);
    const T& value() const;
    const UIDataBind<T>& databind() const;
    UIDataBind<T>& databind();
    const UIValueValidationState& validationState() const;
    UIProperty& connect(UIWidget* widget);
    UIProperty& disconnect(UIWidget* widget);
    const T& operator*() const;
    const T* operator->() const;
    operator const T &() const;
    UIProperty& changed(const std::function<void(const T&newVal)>& fn);
    UIProperty& changed(std::function<void(const T&newVal)>&& fn);
};

Detailed Documentation

Owns a value and exposes it as a UIDataBind-backed widget property.

UIProperty is the owning counterpart to UIDataBind : the synchronized value is stored inside the property, so callers only need to ensure the UIProperty itself remains alive while using it. Assignments propagate to connected widgets, and widget-originated changes update value(). Connections are removed automatically when either the UIProperty or a connected widget dies.

The class is non-copyable and non-movable because its UIDataBind stores the address of mValue and installs callbacks that capture the binding’s address.

Use UIProperty for concise UI-local state when the value and its widgets naturally share a lifetime. It avoids the shared state required by ObservableValue and owns its UIDataBind directly. A custom UIValueConverter can provide presentation-specific parsing and formatting.

UIProperty<double> celsius( 0.0, celsiusInput );
UIProperty<double> fahrenheit( 32.0, fahrenheitInput );
celsius.changed( [&fahrenheit]( double value ) {
    fahrenheit = value * 9.0 / 5.0 + 32.0;
} );

Methods

const UIValueValidationState& validationState() const

Returns:

Current converter error state.

UIProperty& connect(UIWidget* widget)

Connects another widget to this property’s value.

UIProperty& disconnect(UIWidget* widget)

Disconnects a widget from this property’s value.

UIProperty& changed(const std::function<void(const T&newVal)>& fn)

Sets the callback invoked after the synchronized value changes.