aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/StringToNumberConverter.cpp15
-rw-r--r--src/theme_builder/components/properties/FontPropertyEditor.cpp49
-rw-r--r--src/theme_builder/components/properties/FontPropertyEditor.h37
3 files changed, 99 insertions, 2 deletions
diff --git a/src/common/StringToNumberConverter.cpp b/src/common/StringToNumberConverter.cpp
index 259e39b0..d77f7886 100644
--- a/src/common/StringToNumberConverter.cpp
+++ b/src/common/StringToNumberConverter.cpp
@@ -143,10 +143,21 @@ StringToIntegerConverterImplResult StringToIntegerConverterImpl::Parse(
while (current != end && IsSpace(*current)) {
current++;
}
+
+ if (current != end) {
+ if (processed_characters_count) {
+ *processed_characters_count = 0;
+ }
+ if (throw_on_error) {
+ throw Exception(u"There is trailing junk.");
+ } else {
+ return {false, 0};
+ }
+ }
}
- if (current != end) {
- throw Exception(u"There is trailing junk.");
+ if (processed_characters_count) {
+ *processed_characters_count = current - str;
}
return {negate, result};
diff --git a/src/theme_builder/components/properties/FontPropertyEditor.cpp b/src/theme_builder/components/properties/FontPropertyEditor.cpp
new file mode 100644
index 00000000..b4f5fa06
--- /dev/null
+++ b/src/theme_builder/components/properties/FontPropertyEditor.cpp
@@ -0,0 +1,49 @@
+#include "FontPropertyEditor.h"
+#include "cru/platform/graphics/Factory.h"
+#include "cru/platform/graphics/Font.h"
+#include "cru/platform/gui/UiApplication.h"
+#include "cru/ui/controls/FlexLayout.h"
+#include "cru/ui/render/FlexLayoutRenderObject.h"
+
+namespace cru::theme_builder::components::properties {
+using namespace cru::ui::controls;
+
+FontPropertyEditor::FontPropertyEditor() {
+ main_container_.SetFlexDirection(FlexDirection::Horizontal);
+ main_container_.AddChild(&label_);
+ main_container_.AddChild(&right_container_);
+
+ right_container_.SetFlexDirection(FlexDirection::Vertical);
+ right_container_.AddChild(&font_family_container_);
+ right_container_.AddChild(&font_size_container_);
+
+ font_family_container_.SetFlexDirection(FlexDirection::Horizontal);
+ font_family_container_.AddChild(&font_family_label_);
+ font_family_container_.AddChild(&font_family_text_);
+ font_family_label_.SetText(u"Font Family");
+
+ font_size_container_.SetFlexDirection(FlexDirection::Horizontal);
+ font_size_container_.AddChild(&font_size_label_);
+ font_size_container_.AddChild(&font_size_text_);
+ font_size_label_.SetText(u"Font Size");
+
+ font_family_text_.TextChangeEvent()->AddSpyOnlyHandler(
+ [this] { RaiseChangeEvent(); });
+
+ font_size_text_.TextChangeEvent()->AddSpyOnlyHandler(
+ [this] { RaiseChangeEvent(); });
+}
+
+FontPropertyEditor::~FontPropertyEditor() {}
+
+Control* FontPropertyEditor::GetRootControl() { return &main_container_; }
+
+std::shared_ptr<platform::graphics::IFont> FontPropertyEditor::GetValue()
+ const {
+ return platform::gui::IUiApplication::GetInstance()
+ ->GetGraphicsFactory()
+ ->CreateFont(font_family_text_.GetText(),
+ font_size_text_.GetText().ParseToFloat());
+}
+
+} // namespace cru::theme_builder::components::properties
diff --git a/src/theme_builder/components/properties/FontPropertyEditor.h b/src/theme_builder/components/properties/FontPropertyEditor.h
new file mode 100644
index 00000000..f7dd0362
--- /dev/null
+++ b/src/theme_builder/components/properties/FontPropertyEditor.h
@@ -0,0 +1,37 @@
+#pragma once
+#include "../Editor.h"
+#include "cru/platform/graphics/Font.h"
+#include "cru/ui/controls/Control.h"
+#include "cru/ui/controls/FlexLayout.h"
+#include "cru/ui/controls/TextBlock.h"
+#include "cru/ui/controls/TextBox.h"
+
+namespace cru::theme_builder::components::properties {
+class FontPropertyEditor : public Editor {
+ public:
+ using PropertyType = std::shared_ptr<platform::graphics::IFont>;
+
+ FontPropertyEditor();
+ ~FontPropertyEditor() override;
+
+ ui::controls::Control* GetRootControl() override;
+
+ String GetLabelText() const { return label_.GetText(); }
+ void SetLabelText(String label) { label_.SetText(std::move(label)); }
+
+ std::shared_ptr<platform::graphics::IFont> GetValue() const;
+ void SetValue(std::shared_ptr<platform::graphics::IFont> value,
+ bool trigger_change = true);
+
+ private:
+ ui::controls::FlexLayout main_container_;
+ ui::controls::TextBlock label_;
+ ui::controls::FlexLayout right_container_;
+ ui::controls::FlexLayout font_family_container_;
+ ui::controls::TextBlock font_family_label_;
+ ui::controls::TextBox font_family_text_;
+ ui::controls::FlexLayout font_size_container_;
+ ui::controls::TextBlock font_size_label_;
+ ui::controls::TextBox font_size_text_;
+};
+} // namespace cru::theme_builder::components::properties