diff options
Diffstat (limited to 'src/theme_builder/components/properties/ThicknessPropertyEditor.cpp')
-rw-r--r-- | src/theme_builder/components/properties/ThicknessPropertyEditor.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/theme_builder/components/properties/ThicknessPropertyEditor.cpp b/src/theme_builder/components/properties/ThicknessPropertyEditor.cpp new file mode 100644 index 00000000..3121d288 --- /dev/null +++ b/src/theme_builder/components/properties/ThicknessPropertyEditor.cpp @@ -0,0 +1,35 @@ +#include "ThicknessPropertyEditor.h" +#include "cru/ui/mapper/MapperRegistry.h" +#include "cru/ui/mapper/ThicknessMapper.h" + +namespace cru::theme_builder::components::properties { +ThicknessPropertyEditor::ThicknessPropertyEditor() { + container_.AddChild(&label_); + container_.AddChild(&text_); + + text_.TextChangeEvent()->AddHandler([this](std::nullptr_t) { + auto text = text_.GetTextView(); + auto thickness_mapper = + ui::mapper::MapperRegistry::GetInstance()->GetMapper<ui::Thickness>(); + try { + auto thickness = thickness_mapper->MapFromString(text.ToString()); + thickness_ = thickness; + is_text_valid_ = true; + thickness_change_event_.Raise(thickness); + } catch (const Exception &) { + is_text_valid_ = false; + // TODO: Show error! + } + }); +} + +ThicknessPropertyEditor::~ThicknessPropertyEditor() {} + +void ThicknessPropertyEditor::SetThickness(const ui::Thickness &thickness) { + thickness_ = thickness; + text_.SetText(Format(u"{} {} {} {}", thickness_.left, thickness_.top, + thickness_.right, thickness_.bottom)); + is_text_valid_ = true; + thickness_change_event_.Raise(thickness_); +} +} // namespace cru::theme_builder::components::properties |