aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--assets/cru/theme_builder/ThemeResources.xml7
-rw-r--r--include/cru/common/Format.h12
-rw-r--r--src/common/Format.cpp19
-rw-r--r--src/theme_builder/components/properties/ColorPropertyEditor.cpp2
4 files changed, 34 insertions, 6 deletions
diff --git a/assets/cru/theme_builder/ThemeResources.xml b/assets/cru/theme_builder/ThemeResources.xml
index 544f6908..e39cc232 100644
--- a/assets/cru/theme_builder/ThemeResources.xml
+++ b/assets/cru/theme_builder/ThemeResources.xml
@@ -1,15 +1,20 @@
<Theme>
+ <Resource key="cru.theme_builder.editor.label.font">
+ <Font size="16" />
+ </Resource>
+
<Resource key="cru.theme_builder.color_cube.style">
<StyleRuleSet>
<StyleRule>
<NoCondition />
- <PreferredSizeStyler width="20" height="20" />
+ <PreferredSizeStyler width="30" height="20" />
<BorderStyler>
<BorderStyle>
<Color value="black" />
<Thickness value="1" />
</BorderStyle>
</BorderStyler>
+ <MarginStyler value="10 0 0 0" />
</StyleRule>
</StyleRuleSet>
</Resource>
diff --git a/include/cru/common/Format.h b/include/cru/common/Format.h
index 2b08f03b..d99098b4 100644
--- a/include/cru/common/Format.h
+++ b/include/cru/common/Format.h
@@ -1,5 +1,6 @@
#pragma once
+#include <double-conversion/double-conversion.h>
#include "Exception.h"
#include "String.h"
@@ -28,11 +29,12 @@ std::enable_if_t<std::is_integral_v<T>, String> ToString(T value) {
return String::FromBuffer(b, size, size);
}
-template <typename T>
-std::enable_if_t<std::is_floating_point_v<T>, String> ToString(T value) {
- auto str = std::to_string(value);
- return String(str.cbegin(), str.cend());
-}
+extern double_conversion::DoubleToStringConverter kDefaultDoubleToStringConverter;
+
+String ToString(float value, StringView option);
+String ToString(double value, StringView option);
+inline String ToString(float value) { return ToString(value, u""); }
+inline String ToString(double value) { return ToString(value, u""); }
template <typename T>
String ToString(const T& value, StringView option) {
diff --git a/src/common/Format.cpp b/src/common/Format.cpp
index d58c90b7..0ae744fc 100644
--- a/src/common/Format.cpp
+++ b/src/common/Format.cpp
@@ -1,6 +1,25 @@
#include "cru/common/Format.h"
+#include <double-conversion/utils.h>
namespace cru {
+
+double_conversion::DoubleToStringConverter kDefaultDoubleToStringConverter(
+ 0, "infinity", "nan", 'e', -6, 21, 6, 1);
+
+String ToString(float value, StringView option) {
+ char buffer[50];
+ double_conversion::StringBuilder string_builder(buffer, sizeof(buffer));
+ kDefaultDoubleToStringConverter.ToShortestSingle(value, &string_builder);
+ return String::FromUtf8(std::string_view(buffer, string_builder.position()));
+}
+
+String ToString(double value, StringView option) {
+ char buffer[50];
+ double_conversion::StringBuilder string_builder(buffer, sizeof(buffer));
+ kDefaultDoubleToStringConverter.ToShortestSingle(value, &string_builder);
+ return String::FromUtf8(std::string_view(buffer, string_builder.position()));
+}
+
namespace details {
FormatToken ParsePlaceHolder(String place_holder_string) {
if (place_holder_string.empty()) {
diff --git a/src/theme_builder/components/properties/ColorPropertyEditor.cpp b/src/theme_builder/components/properties/ColorPropertyEditor.cpp
index 89b145a7..e9e486ac 100644
--- a/src/theme_builder/components/properties/ColorPropertyEditor.cpp
+++ b/src/theme_builder/components/properties/ColorPropertyEditor.cpp
@@ -19,7 +19,9 @@ ColorPropertyEditor::ColorPropertyEditor() {
->CreateSolidColorBrush(color_);
color_cube_.SetForegroundBrush(color_cube_brush_);
+
color_text_.SetText(color_.ToString());
+ color_text_.SetMargin(ui::Thickness(10, 0, 0, 0));
color_text_.TextChangeEvent()->AddHandler([this](std::nullptr_t) {
auto text = color_text_.GetTextView();