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, 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 ) ); } );