From 8da596f7b5fdbcf11fbda4aa66efc87a219f58ae Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 26 Feb 2022 20:33:02 +0800 Subject: ... --- assets/cru/theme_builder/ThemeResources.xml | 7 ++++++- include/cru/common/Format.h | 12 +++++++----- src/common/Format.cpp | 19 +++++++++++++++++++ .../components/properties/ColorPropertyEditor.cpp | 2 ++ 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 @@ + + + + - + + 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 #include "Exception.h" #include "String.h" @@ -28,11 +29,12 @@ std::enable_if_t, String> ToString(T value) { return String::FromBuffer(b, size, size); } -template -std::enable_if_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 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 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(); -- cgit v1.2.3