diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ThemeBuilder/components/properties/ColorPropertyEditor.cpp | 6 | ||||
-rw-r--r-- | src/platform/Color.cpp | 333 | ||||
-rw-r--r-- | src/ui/mapper/ColorMapper.cpp | 2 |
3 files changed, 171 insertions, 170 deletions
diff --git a/src/ThemeBuilder/components/properties/ColorPropertyEditor.cpp b/src/ThemeBuilder/components/properties/ColorPropertyEditor.cpp index e9e486ac..0fe3908e 100644 --- a/src/ThemeBuilder/components/properties/ColorPropertyEditor.cpp +++ b/src/ThemeBuilder/components/properties/ColorPropertyEditor.cpp @@ -20,12 +20,12 @@ ColorPropertyEditor::ColorPropertyEditor() { color_cube_.SetForegroundBrush(color_cube_brush_); - color_text_.SetText(color_.ToString()); + color_text_.SetText(String::FromUtf8(color_.ToString())); color_text_.SetMargin(ui::Thickness(10, 0, 0, 0)); color_text_.TextChangeEvent()->AddHandler([this](std::nullptr_t) { auto text = color_text_.GetTextView(); - auto color = ui::Color::Parse(text); + auto color = ui::Color::Parse(text.ToUtf8()); if (color) { color_ = *color; color_cube_brush_->SetColor(*color); @@ -43,6 +43,6 @@ ColorPropertyEditor::~ColorPropertyEditor() {} void ColorPropertyEditor::SetValue(const ui::Color &color, bool trigger_change) { if (!trigger_change) SuppressNextChangeEvent(); - color_text_.SetText(color.ToString()); + color_text_.SetText(String::FromUtf8(color.ToString())); } } // namespace cru::theme_builder::components::properties diff --git a/src/platform/Color.cpp b/src/platform/Color.cpp index bbb78628..c4a10577 100644 --- a/src/platform/Color.cpp +++ b/src/platform/Color.cpp @@ -5,16 +5,16 @@ #include <optional> namespace cru::platform { -String Color::ToString() const { - auto to_hex = [](std::uint8_t v) -> char16_t { - return v >= 10 ? v - 10 + u'a' : v + u'0'; +std::string Color::ToString() const { + auto to_hex = [](std::uint8_t v) -> char { + return v >= 10 ? v - 10 + 'a' : v + '0'; }; - auto to_two_hex_digit = [to_hex](std::uint8_t v) -> String { + auto to_two_hex_digit = [to_hex](std::uint8_t v) -> std::string { return {to_hex(v /= 16), to_hex(v %= 16)}; }; - String result = u"#"; + std::string result = "#"; result.append(to_two_hex_digit(red)); result.append(to_two_hex_digit(green)); result.append(to_two_hex_digit(blue)); @@ -22,7 +22,7 @@ String Color::ToString() const { return result; } -std::optional<Color> Color::Parse(StringView string, +std::optional<Color> Color::Parse(std::string_view string, bool parse_predefined_color) { if (parse_predefined_color) { auto optional_predefined_color = GetPredefinedColorByName(string); @@ -31,14 +31,15 @@ std::optional<Color> Color::Parse(StringView string, } } - auto get_num = [](char16_t c) -> std::optional<int> { - if (c >= u'0' && c <= u'9') return c - u'0'; - if (c >= u'A' && c <= u'F') return c - u'A' + 10; - if (c >= u'a' && c <= u'f') return c - u'a' + 10; + auto get_num = [](char c) -> std::optional<int> { + if (c >= '0' && c <= '9') return c - '0'; + if (c >= 'A' && c <= 'F') return c - 'A' + 10; + if (c >= 'a' && c <= 'f') return c - 'a' + 10; return std::nullopt; }; - auto get_num_for_two_digit = [get_num](StringView str) -> std::optional<int> { + auto get_num_for_two_digit = + [get_num](std::string_view str) -> std::optional<int> { int num = 0; auto d1 = get_num(str[0]); if (!d1) return std::nullopt; @@ -78,163 +79,163 @@ std::optional<Color> Color::Parse(StringView string, } } -namespace details { -const std::unordered_map<StringView, Color> predefined_name_color_map{ - {u"transparent", colors::transparent}, - {u"black", colors::black}, - {u"silver", colors::silver}, - {u"gray", colors::gray}, - {u"white", colors::white}, - {u"maroon", colors::maroon}, - {u"red", colors::red}, - {u"purple", colors::purple}, - {u"fuchsia", colors::fuchsia}, - {u"green", colors::green}, - {u"lime", colors::lime}, - {u"olive", colors::olive}, - {u"yellow", colors::yellow}, - {u"navy", colors::navy}, - {u"blue", colors::blue}, - {u"teal", colors::teal}, - {u"aqua", colors::aqua}, - {u"orange", colors::orange}, - {u"aliceblue", colors::aliceblue}, - {u"antiquewhite", colors::antiquewhite}, - {u"aquamarine", colors::aquamarine}, - {u"azure", colors::azure}, - {u"beige", colors::beige}, - {u"bisque", colors::bisque}, - {u"blanchedalmond", colors::blanchedalmond}, - {u"blueviolet", colors::blueviolet}, - {u"brown", colors::brown}, - {u"burlywood", colors::burlywood}, - {u"cadetblue", colors::cadetblue}, - {u"chartreuse", colors::chartreuse}, - {u"chocolate", colors::chocolate}, - {u"coral", colors::coral}, - {u"cornflowerblue", colors::cornflowerblue}, - {u"cornsilk", colors::cornsilk}, - {u"crimson", colors::crimson}, - {u"cyan", colors::cyan}, - {u"darkblue", colors::darkblue}, - {u"darkcyan", colors::darkcyan}, - {u"darkgoldenrod", colors::darkgoldenrod}, - {u"darkgray", colors::darkgray}, - {u"darkgreen", colors::darkgreen}, - {u"darkgrey", colors::darkgrey}, - {u"darkkhaki", colors::darkkhaki}, - {u"darkmagenta", colors::darkmagenta}, - {u"darkolivegreen", colors::darkolivegreen}, - {u"darkorange", colors::darkorange}, - {u"darkorchid", colors::darkorchid}, - {u"darkred", colors::darkred}, - {u"darksalmon", colors::darksalmon}, - {u"darkseagreen", colors::darkseagreen}, - {u"darkslateblue", colors::darkslateblue}, - {u"darkslategray", colors::darkslategray}, - {u"darkslategrey", colors::darkslategrey}, - {u"darkturquoise", colors::darkturquoise}, - {u"darkviolet", colors::darkviolet}, - {u"deeppink", colors::deeppink}, - {u"deepskyblue", colors::deepskyblue}, - {u"dimgray", colors::dimgray}, - {u"dimgrey", colors::dimgrey}, - {u"dodgerblue", colors::dodgerblue}, - {u"firebrick", colors::firebrick}, - {u"floralwhite", colors::floralwhite}, - {u"forestgreen", colors::forestgreen}, - {u"gainsboro", colors::gainsboro}, - {u"ghostwhite", colors::ghostwhite}, - {u"gold", colors::gold}, - {u"goldenrod", colors::goldenrod}, - {u"greenyellow", colors::greenyellow}, - {u"grey", colors::grey}, - {u"honeydew", colors::honeydew}, - {u"hotpink", colors::hotpink}, - {u"indianred", colors::indianred}, - {u"indigo", colors::indigo}, - {u"ivory", colors::ivory}, - {u"khaki", colors::khaki}, - {u"lavender", colors::lavender}, - {u"lavenderblush", colors::lavenderblush}, - {u"lawngreen", colors::lawngreen}, - {u"lemonchiffon", colors::lemonchiffon}, - {u"lightblue", colors::lightblue}, - {u"lightcoral", colors::lightcoral}, - {u"lightcyan", colors::lightcyan}, - {u"lightgoldenrodyellow", colors::lightgoldenrodyellow}, - {u"lightgray", colors::lightgray}, - {u"lightgreen", colors::lightgreen}, - {u"lightgrey", colors::lightgrey}, - {u"lightpink", colors::lightpink}, - {u"lightsalmon", colors::lightsalmon}, - {u"lightseagreen", colors::lightseagreen}, - {u"lightskyblue", colors::lightskyblue}, - {u"lightslategray", colors::lightslategray}, - {u"lightslategrey", colors::lightslategrey}, - {u"lightsteelblue", colors::lightsteelblue}, - {u"lightyellow", colors::lightyellow}, - {u"limegreen", colors::limegreen}, - {u"linen", colors::linen}, - {u"magenta", colors::magenta}, - {u"mediumaquamarine", colors::mediumaquamarine}, - {u"mediumblue", colors::mediumblue}, - {u"mediumorchid", colors::mediumorchid}, - {u"mediumpurple", colors::mediumpurple}, - {u"mediumseagreen", colors::mediumseagreen}, - {u"mediumslateblue", colors::mediumslateblue}, - {u"mediumspringgreen", colors::mediumspringgreen}, - {u"mediumturquoise", colors::mediumturquoise}, - {u"mediumvioletred", colors::mediumvioletred}, - {u"midnightblue", colors::midnightblue}, - {u"mintcream", colors::mintcream}, - {u"mistyrose", colors::mistyrose}, - {u"moccasin", colors::moccasin}, - {u"navajowhite", colors::navajowhite}, - {u"oldlace", colors::oldlace}, - {u"olivedrab", colors::olivedrab}, - {u"orangered", colors::orangered}, - {u"orchid", colors::orchid}, - {u"palegoldenrod", colors::palegoldenrod}, - {u"palegreen", colors::palegreen}, - {u"paleturquoise", colors::paleturquoise}, - {u"palevioletred", colors::palevioletred}, - {u"papayawhip", colors::papayawhip}, - {u"peachpuff", colors::peachpuff}, - {u"peru", colors::peru}, - {u"pink", colors::pink}, - {u"plum", colors::plum}, - {u"powderblue", colors::powderblue}, - {u"rosybrown", colors::rosybrown}, - {u"royalblue", colors::royalblue}, - {u"saddlebrown", colors::saddlebrown}, - {u"salmon", colors::salmon}, - {u"sandybrown", colors::sandybrown}, - {u"seagreen", colors::seagreen}, - {u"seashell", colors::seashell}, - {u"sienna", colors::sienna}, - {u"skyblue", colors::skyblue}, - {u"slateblue", colors::slateblue}, - {u"slategray", colors::slategray}, - {u"slategrey", colors::slategrey}, - {u"snow", colors::snow}, - {u"springgreen", colors::springgreen}, - {u"steelblue", colors::steelblue}, - {u"tan", colors::tan}, - {u"thistle", colors::thistle}, - {u"tomato", colors::tomato}, - {u"turquoise", colors::turquoise}, - {u"violet", colors::violet}, - {u"wheat", colors::wheat}, - {u"whitesmoke", colors::whitesmoke}, - {u"yellowgreen", colors::yellowgreen}, - {u"rebeccapurple", colors::rebeccapurple}, +namespace { +const std::unordered_map<std::string_view, Color> predefined_name_color_map{ + {"transparent", colors::transparent}, + {"black", colors::black}, + {"silver", colors::silver}, + {"gray", colors::gray}, + {"white", colors::white}, + {"maroon", colors::maroon}, + {"red", colors::red}, + {"purple", colors::purple}, + {"fuchsia", colors::fuchsia}, + {"green", colors::green}, + {"lime", colors::lime}, + {"olive", colors::olive}, + {"yellow", colors::yellow}, + {"navy", colors::navy}, + {"blue", colors::blue}, + {"teal", colors::teal}, + {"aqua", colors::aqua}, + {"orange", colors::orange}, + {"aliceblue", colors::aliceblue}, + {"antiquewhite", colors::antiquewhite}, + {"aquamarine", colors::aquamarine}, + {"azure", colors::azure}, + {"beige", colors::beige}, + {"bisque", colors::bisque}, + {"blanchedalmond", colors::blanchedalmond}, + {"blueviolet", colors::blueviolet}, + {"brown", colors::brown}, + {"burlywood", colors::burlywood}, + {"cadetblue", colors::cadetblue}, + {"chartreuse", colors::chartreuse}, + {"chocolate", colors::chocolate}, + {"coral", colors::coral}, + {"cornflowerblue", colors::cornflowerblue}, + {"cornsilk", colors::cornsilk}, + {"crimson", colors::crimson}, + {"cyan", colors::cyan}, + {"darkblue", colors::darkblue}, + {"darkcyan", colors::darkcyan}, + {"darkgoldenrod", colors::darkgoldenrod}, + {"darkgray", colors::darkgray}, + {"darkgreen", colors::darkgreen}, + {"darkgrey", colors::darkgrey}, + {"darkkhaki", colors::darkkhaki}, + {"darkmagenta", colors::darkmagenta}, + {"darkolivegreen", colors::darkolivegreen}, + {"darkorange", colors::darkorange}, + {"darkorchid", colors::darkorchid}, + {"darkred", colors::darkred}, + {"darksalmon", colors::darksalmon}, + {"darkseagreen", colors::darkseagreen}, + {"darkslateblue", colors::darkslateblue}, + {"darkslategray", colors::darkslategray}, + {"darkslategrey", colors::darkslategrey}, + {"darkturquoise", colors::darkturquoise}, + {"darkviolet", colors::darkviolet}, + {"deeppink", colors::deeppink}, + {"deepskyblue", colors::deepskyblue}, + {"dimgray", colors::dimgray}, + {"dimgrey", colors::dimgrey}, + {"dodgerblue", colors::dodgerblue}, + {"firebrick", colors::firebrick}, + {"floralwhite", colors::floralwhite}, + {"forestgreen", colors::forestgreen}, + {"gainsboro", colors::gainsboro}, + {"ghostwhite", colors::ghostwhite}, + {"gold", colors::gold}, + {"goldenrod", colors::goldenrod}, + {"greenyellow", colors::greenyellow}, + {"grey", colors::grey}, + {"honeydew", colors::honeydew}, + {"hotpink", colors::hotpink}, + {"indianred", colors::indianred}, + {"indigo", colors::indigo}, + {"ivory", colors::ivory}, + {"khaki", colors::khaki}, + {"lavender", colors::lavender}, + {"lavenderblush", colors::lavenderblush}, + {"lawngreen", colors::lawngreen}, + {"lemonchiffon", colors::lemonchiffon}, + {"lightblue", colors::lightblue}, + {"lightcoral", colors::lightcoral}, + {"lightcyan", colors::lightcyan}, + {"lightgoldenrodyellow", colors::lightgoldenrodyellow}, + {"lightgray", colors::lightgray}, + {"lightgreen", colors::lightgreen}, + {"lightgrey", colors::lightgrey}, + {"lightpink", colors::lightpink}, + {"lightsalmon", colors::lightsalmon}, + {"lightseagreen", colors::lightseagreen}, + {"lightskyblue", colors::lightskyblue}, + {"lightslategray", colors::lightslategray}, + {"lightslategrey", colors::lightslategrey}, + {"lightsteelblue", colors::lightsteelblue}, + {"lightyellow", colors::lightyellow}, + {"limegreen", colors::limegreen}, + {"linen", colors::linen}, + {"magenta", colors::magenta}, + {"mediumaquamarine", colors::mediumaquamarine}, + {"mediumblue", colors::mediumblue}, + {"mediumorchid", colors::mediumorchid}, + {"mediumpurple", colors::mediumpurple}, + {"mediumseagreen", colors::mediumseagreen}, + {"mediumslateblue", colors::mediumslateblue}, + {"mediumspringgreen", colors::mediumspringgreen}, + {"mediumturquoise", colors::mediumturquoise}, + {"mediumvioletred", colors::mediumvioletred}, + {"midnightblue", colors::midnightblue}, + {"mintcream", colors::mintcream}, + {"mistyrose", colors::mistyrose}, + {"moccasin", colors::moccasin}, + {"navajowhite", colors::navajowhite}, + {"oldlace", colors::oldlace}, + {"olivedrab", colors::olivedrab}, + {"orangered", colors::orangered}, + {"orchid", colors::orchid}, + {"palegoldenrod", colors::palegoldenrod}, + {"palegreen", colors::palegreen}, + {"paleturquoise", colors::paleturquoise}, + {"palevioletred", colors::palevioletred}, + {"papayawhip", colors::papayawhip}, + {"peachpuff", colors::peachpuff}, + {"peru", colors::peru}, + {"pink", colors::pink}, + {"plum", colors::plum}, + {"powderblue", colors::powderblue}, + {"rosybrown", colors::rosybrown}, + {"royalblue", colors::royalblue}, + {"saddlebrown", colors::saddlebrown}, + {"salmon", colors::salmon}, + {"sandybrown", colors::sandybrown}, + {"seagreen", colors::seagreen}, + {"seashell", colors::seashell}, + {"sienna", colors::sienna}, + {"skyblue", colors::skyblue}, + {"slateblue", colors::slateblue}, + {"slategray", colors::slategray}, + {"slategrey", colors::slategrey}, + {"snow", colors::snow}, + {"springgreen", colors::springgreen}, + {"steelblue", colors::steelblue}, + {"tan", colors::tan}, + {"thistle", colors::thistle}, + {"tomato", colors::tomato}, + {"turquoise", colors::turquoise}, + {"violet", colors::violet}, + {"wheat", colors::wheat}, + {"whitesmoke", colors::whitesmoke}, + {"yellowgreen", colors::yellowgreen}, + {"rebeccapurple", colors::rebeccapurple}, }; -} // namespace details +} // namespace -std::optional<Color> GetPredefinedColorByName(StringView name) { - auto result = details::predefined_name_color_map.find(name); - if (result != details::predefined_name_color_map.cend()) { +std::optional<Color> GetPredefinedColorByName(std::string_view name) { + auto result = predefined_name_color_map.find(name); + if (result != predefined_name_color_map.cend()) { return result->second; } else { return std::nullopt; diff --git a/src/ui/mapper/ColorMapper.cpp b/src/ui/mapper/ColorMapper.cpp index a959e6d8..dcf3a522 100644 --- a/src/ui/mapper/ColorMapper.cpp +++ b/src/ui/mapper/ColorMapper.cpp @@ -6,7 +6,7 @@ bool ColorMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) { } Color ColorMapper::DoMapFromString(std::string str) { - auto c = Color::Parse(String::FromUtf8(str)); + auto c = Color::Parse(str); if (!c) { throw Exception("Invalid color value."); } |