From 6c9fffc4c1aa15d200dc7b206271bf60ed44b678 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Mon, 20 Nov 2023 20:31:39 +1300 Subject: [PATCH] LibGfx: Add String variants of Color::to_string*() --- Userland/Libraries/LibGfx/Color.cpp | 14 ++++++++++++-- Userland/Libraries/LibGfx/Color.h | 3 +++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibGfx/Color.cpp b/Userland/Libraries/LibGfx/Color.cpp index 4bdf4fdcad..5c538aa368 100644 --- a/Userland/Libraries/LibGfx/Color.cpp +++ b/Userland/Libraries/LibGfx/Color.cpp @@ -18,14 +18,24 @@ namespace Gfx { +String Color::to_string() const +{ + return MUST(String::formatted("#{:02x}{:02x}{:02x}{:02x}", red(), green(), blue(), alpha())); +} + +String Color::to_string_without_alpha() const +{ + return MUST(String::formatted("#{:02x}{:02x}{:02x}", red(), green(), blue())); +} + DeprecatedString Color::to_deprecated_string() const { - return DeprecatedString::formatted("#{:02x}{:02x}{:02x}{:02x}", red(), green(), blue(), alpha()); + return to_string().to_deprecated_string(); } DeprecatedString Color::to_deprecated_string_without_alpha() const { - return DeprecatedString::formatted("#{:02x}{:02x}{:02x}", red(), green(), blue()); + return to_string_without_alpha().to_deprecated_string(); } static Optional parse_rgb_color(StringView string) diff --git a/Userland/Libraries/LibGfx/Color.h b/Userland/Libraries/LibGfx/Color.h index b26c00a7d2..d0526bdb26 100644 --- a/Userland/Libraries/LibGfx/Color.h +++ b/Userland/Libraries/LibGfx/Color.h @@ -356,6 +356,9 @@ public: return m_value == other.m_value; } + String to_string() const; + String to_string_without_alpha() const; + DeprecatedString to_deprecated_string() const; DeprecatedString to_deprecated_string_without_alpha() const; static Optional from_string(StringView);