.. index:: pair: struct; EE::UI::UIValueConverter .. _doxid-struct_e_e_1_1_u_i_1_1_u_i_value_converter: template struct EE::UI::UIValueConverter ======================================== .. toctree:: :hidden: Overview ~~~~~~~~ Binding-independent conversion between a typed value and a widget property string. :ref:`More...` .. ref-code-block:: cpp :class: doxyrest-overview-code-block #include template struct UIValueConverter { // typedefs typedef std::function<:ref:`UIValueResult`(const :ref:`CSS::PropertyDefinition`*, const std::string&)> :ref:`ToValue`; typedef std::function<:ref:`UIValueResult`(const :ref:`CSS::PropertyDefinition`*, const T&)> :ref:`FromValue`; // fields :ref:`ToValue` :target:`toValue`; :ref:`FromValue` :target:`fromValue`; // construction :target:`UIValueConverter`(); :ref:`UIValueConverter`(:ref:`ToValue` toValue); :ref:`UIValueConverter`(:ref:`ToValue` toValue, :ref:`FromValue` fromValue); // methods static UIValueConverter :ref:`converterDefault`(); static UIValueConverter :ref:`converterString`(); static UIValueConverter :target:`converterBool`(); }; .. _details-struct_e_e_1_1_u_i_1_1_u_i_value_converter: Detailed Documentation ~~~~~~~~~~~~~~~~~~~~~~ Binding-independent conversion between a typed value and a widget property string. :ref:`UIDataBind ` and :ref:`UIValueBinding ` share this policy type, so custom conversions do not depend on either ownership model. The PropertyDefinition describes the widget property being synchronized and can be used for CSS-aware parsing. .. ref-code-block:: cpp auto converter = UIValueConverter( []( const CSS::PropertyDefinition*, const std::string& text ) { MyEnum value; return enumFromString( value, text ) ? UIValueResult::success( value ) : UIValueResult::error( 1 ); }, []( const CSS::PropertyDefinition*, const MyEnum& value ) { return UIValueResult::success( enumToString( value ) ); } ); Typedefs -------- .. index:: pair: typedef; ToValue .. _doxid-struct_e_e_1_1_u_i_1_1_u_i_value_converter_1ab90ee5faa57aa554b7f68b8c40e61045: .. ref-code-block:: cpp :class: doxyrest-title-code-block typedef std::function<:ref:`UIValueResult`(const :ref:`CSS::PropertyDefinition`*, const std::string&)> ToValue Parses a widget property string into the model type. .. index:: pair: typedef; FromValue .. _doxid-struct_e_e_1_1_u_i_1_1_u_i_value_converter_1a2b79f4c801d5a096184f3e81f192d195: .. ref-code-block:: cpp :class: doxyrest-title-code-block typedef std::function<:ref:`UIValueResult`(const :ref:`CSS::PropertyDefinition`*, const T&)> FromValue Formats a model value as a widget property string. Construction ------------ .. index:: pair: function; UIValueConverter .. _doxid-struct_e_e_1_1_u_i_1_1_u_i_value_converter_1aacd90e627e49b1da2fc90485bc469958: .. ref-code-block:: cpp :class: doxyrest-title-code-block UIValueConverter(:ref:`ToValue` toValue) Creates a converter with custom parsing and the default formatter for ``T``. This is the common form for validation rules that only constrain text entering the model. .. index:: pair: function; UIValueConverter .. _doxid-struct_e_e_1_1_u_i_1_1_u_i_value_converter_1ae7d8af19bdf825213940c23d1ea80cc7: .. ref-code-block:: cpp :class: doxyrest-title-code-block UIValueConverter(:ref:`ToValue` toValue, :ref:`FromValue` fromValue) Creates a converter with custom parsing and formatting policies. Methods ------- .. index:: pair: function; converterDefault .. _doxid-struct_e_e_1_1_u_i_1_1_u_i_value_converter_1ae9cf163c1ea47968c25b32bf36464304: .. ref-code-block:: cpp :class: doxyrest-title-code-block static UIValueConverter converterDefault() .. rubric:: Returns: The standard string conversion policy for ``T``. .. index:: pair: function; converterString .. _doxid-struct_e_e_1_1_u_i_1_1_u_i_value_converter_1a23424658cf7089b1309078565fcdd82c: .. ref-code-block:: cpp :class: doxyrest-title-code-block static UIValueConverter converterString() .. rubric:: Returns: A converter that preserves text verbatim for string-compatible ``T``.