template struct EE::UI::UIValueConverter¶
Overview¶
Binding-independent conversion between a typed value and a widget property string. More…
#include <uivalueconverter.hpp> template <typename T> struct UIValueConverter { // typedefs typedef std::function<UIValueResult<T>(const CSS::PropertyDefinition*, const std::string&)> ToValue; typedef std::function<UIValueResult<std::string>(const CSS::PropertyDefinition*, const T&)> FromValue; // fields ToValue toValue; FromValue fromValue; // construction UIValueConverter(); UIValueConverter(ToValue toValue); UIValueConverter(ToValue toValue, FromValue fromValue); // methods static UIValueConverter converterDefault(); static UIValueConverter converterString(); static UIValueConverter converterBool(); };
Detailed Documentation¶
Binding-independent conversion between a typed value and a widget property string.
UIDataBind and 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.
auto converter = UIValueConverter<MyEnum>( []( const CSS::PropertyDefinition*, const std::string& text ) { MyEnum value; return enumFromString( value, text ) ? UIValueResult<MyEnum>::success( value ) : UIValueResult<MyEnum>::error( 1 ); }, []( const CSS::PropertyDefinition*, const MyEnum& value ) { return UIValueResult<std::string>::success( enumToString( value ) ); } );
Typedefs¶
typedef std::function<UIValueResult<T>(const CSS::PropertyDefinition*, const std::string&)> ToValue
Parses a widget property string into the model type.
typedef std::function<UIValueResult<std::string>(const CSS::PropertyDefinition*, const T&)> FromValue
Formats a model value as a widget property string.
Construction¶
UIValueConverter(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.
UIValueConverter(ToValue toValue, FromValue fromValue)
Creates a converter with custom parsing and formatting policies.
Methods¶
static UIValueConverter converterDefault()
Returns:
The standard string conversion policy for T.
static UIValueConverter converterString()
Returns:
A converter that preserves text verbatim for string-compatible T.