eepp: Layouts improvements. Added UICodeEditorSplitter::createWidget. Fixed a bug in UITouchDraggableWidget.

ecode: WIP Build Settings UI.
This commit is contained in:
Martín Lucas Golini
2023-05-30 02:04:43 -03:00
parent e6bb1076d4
commit 5ea1678832
17 changed files with 612 additions and 61 deletions

View File

@@ -43,8 +43,8 @@ class EE_API Translator {
void setCurrentLanguage( const std::string& currentLanguage );
protected:
typedef std::map<std::string, String> StringDictionary;
typedef std::map<std::string, StringDictionary> StringLocaleDictionary;
typedef std::unordered_map<std::string, String> StringDictionary;
typedef std::unordered_map<std::string, StringDictionary> StringLocaleDictionary;
std::string mDefaultLanguage;
std::string mCurrentLanguage;

View File

@@ -85,6 +85,9 @@ class EE_API UICodeEditorSplitter {
const std::string& tabName,
bool focus = true );
std::pair<UITab*, UIWidget*> createWidget( UIWidget* widget, const std::string& tabName,
bool focus = true );
std::vector<std::pair<UITab*, UITabWidget*>> getTabFromOwnedWidgetId( const std::string& id );
bool removeTabWithOwnedWidgetId( const std::string& id, bool destroyOwnedNode = true,

View File

@@ -4,6 +4,7 @@
#include <eepp/ui/uiwidget.hpp>
#include <memory>
#include <set>
#include <variant>
namespace EE { namespace UI {
@@ -29,6 +30,18 @@ template <typename T> class UIDataBind {
} );
}
static Converter converterString() {
return Converter(
[]( const UIDataBind<T>*, T& val, const std::string& str ) {
val = str;
return true;
},
[]( const UIDataBind<T>*, std::string& str, const T& val ) {
str = val;
return true;
} );
}
static Converter converterBool() {
return Converter(
[]( const UIDataBind<T>* databind, T& val, const std::string& str ) -> bool {
@@ -44,39 +57,45 @@ template <typename T> class UIDataBind {
static std::unique_ptr<UIDataBind<T>>
New( T* t, const std::set<UIWidget*>& widgets,
const Converter& converter = UIDataBind<T>::converterDefault(),
const std::string& valueKey = "value" ) {
const std::string& valueKey = "value",
const Event::EventType& eventType = Event::OnValueChange ) {
return std::unique_ptr<UIDataBind<T>>(
new UIDataBind<T>( t, widgets, converter, valueKey ) );
new UIDataBind<T>( t, widgets, converter, valueKey, eventType ) );
}
static std::unique_ptr<UIDataBind<T>>
New( T* t, UIWidget* widget, const Converter& converter = UIDataBind<T>::converterDefault(),
const std::string& valueKey = "value" ) {
const std::string& valueKey = "value",
const Event::EventType& eventType = Event::OnValueChange ) {
return std::unique_ptr<UIDataBind<T>>(
new UIDataBind<T>( t, widget, converter, valueKey ) );
new UIDataBind<T>( t, widget, converter, valueKey, eventType ) );
}
UIDataBind() {}
UIDataBind( T* t, const std::set<UIWidget*>& widgets,
const Converter& converter = UIDataBind<T>::converterDefault(),
const std::string& valueKey = "value" ) {
init( t, widgets, converter, valueKey );
const std::string& valueKey = "value",
const Event::EventType& eventType = Event::OnValueChange ) {
init( t, widgets, converter, valueKey, eventType );
}
UIDataBind( T* t, UIWidget* widget,
const Converter& converter = UIDataBind<T>::converterDefault(),
const std::string& valueKey = "value" ) {
init( t, { widget }, converter, valueKey );
const std::string& valueKey = "value",
const Event::EventType& eventType = Event::OnValueChange ) {
init( t, { widget }, converter, valueKey, eventType );
}
void init( T* t, const std::set<UIWidget*>& widgets,
const Converter& converter = UIDataBind<T>::converterDefault(),
const std::string& valueKey = "value" ) {
const std::string& valueKey = "value",
const Event::EventType& eventType = Event::OnValueChange ) {
data = t;
this->widgets = widgets;
this->property = StyleSheetSpecification::instance()->getProperty( valueKey );
this->converter = converter;
this->eventType = eventType;
for ( auto widget : widgets )
bindListeners( widget );
set( *data );
@@ -134,17 +153,17 @@ template <typename T> class UIDataBind {
protected:
T* data{ nullptr };
std::set<UIWidget*> widgets;
std::map<UIWidget*, Uint32> valueCbs;
std::map<UIWidget*, Uint32> closeCbs;
std::unordered_map<UIWidget*, Uint32> valueCbs;
std::unordered_map<UIWidget*, Uint32> closeCbs;
bool inSetValue{ false };
const PropertyDefinition* property{ nullptr };
Converter converter;
Event::EventType eventType{ Event::OnValueChange };
void bindListeners( UIWidget* widget ) {
valueCbs[widget] =
widget->addEventListener( Event::OnValueChange, [this]( const Event* event ) {
processValueChange( event->getNode()->asType<UIWidget>() );
} );
valueCbs[widget] = widget->addEventListener( eventType, [this]( const Event* event ) {
processValueChange( event->getNode()->asType<UIWidget>() );
} );
closeCbs[widget] = widget->addEventListener( Event::OnClose, [this]( const Event* event ) {
closeCbs.erase( event->getNode()->asType<UIWidget>() );
this->widgets.erase( event->getNode()->asType<UIWidget>() );
@@ -190,14 +209,16 @@ template <typename T> class UIDataBind {
class UIDataBindBool {
public:
static std::unique_ptr<UIDataBind<bool>>
using Ptr = std::unique_ptr<UIDataBind<bool>>;
static Ptr
New( bool* t, const std::set<UIWidget*>& widgets,
const UIDataBind<bool>::Converter& converter = UIDataBind<bool>::converterBool(),
const std::string& valueKey = "value" ) {
return UIDataBind<bool>::New( t, widgets, converter, valueKey );
}
static std::unique_ptr<UIDataBind<bool>>
static Ptr
New( bool* t, UIWidget* widget,
const UIDataBind<bool>::Converter& converter = UIDataBind<bool>::converterBool(),
const std::string& valueKey = "value" ) {
@@ -205,6 +226,51 @@ class UIDataBindBool {
}
};
class UIDataBindString {
public:
using Ptr = std::unique_ptr<UIDataBind<std::string>>;
static Ptr New( std::string* t, const std::set<UIWidget*>& widgets,
const UIDataBind<std::string>::Converter& converter =
UIDataBind<std::string>::converterString(),
const std::string& valueKey = "text",
const Event::EventType& eventType = Event::OnTextChanged ) {
return UIDataBind<std::string>::New( t, widgets, converter, valueKey, eventType );
}
static Ptr New( std::string* t, UIWidget* widget,
const UIDataBind<std::string>::Converter& converter =
UIDataBind<std::string>::converterString(),
const std::string& valueKey = "text",
const Event::EventType& eventType = Event::OnTextChanged ) {
return UIDataBind<std::string>::New( t, widget, converter, valueKey, eventType );
}
};
class UIDataBindHolder {
public:
using UIDataBindVariant =
std::variant<UIDataBindString::Ptr, UIDataBindBool::Ptr, UIDataBind<Uint32>,
UIDataBind<Int32>, UIDataBind<Uint64>, UIDataBind<Int64>, UIDataBind<Uint8>,
UIDataBind<Int8>, UIDataBind<Uint16>, UIDataBind<Int16>, UIDataBind<float>,
UIDataBind<double>>;
UIDataBindHolder& hold( UIDataBindVariant&& ptr ) {
mHolder.emplace_back( std::move( ptr ) );
return *this;
}
UIDataBindHolder& operator+=( UIDataBindVariant&& ptr ) {
mHolder.emplace_back( std::move( ptr ) );
return *this;
}
void clear() { mHolder.clear(); }
protected:
std::vector<UIDataBindVariant> mHolder;
};
}} // namespace EE::UI
#endif // EE_UI_UIDATABIND_HPP