Skip to content

Commit

Permalink
LibGfx: Add Color::to_string_without_alpha()
Browse files Browse the repository at this point in the history
This simply returns an "#rrggbb" string and ignores the alpha value.
  • Loading branch information
awesomekling committed Apr 29, 2020
1 parent bc305a1 commit 17e76b4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Libraries/LibGfx/Color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,12 @@ Color::Color(NamedColor named)

String Color::to_string() const
{
return String::format("#%b%b%b%b", red(), green(), blue(), alpha());
return String::format("#%02x%02x%02x%02x", red(), green(), blue(), alpha());
}

String Color::to_string_without_alpha() const
{
return String::format("#%02x%02x%02x", red(), green(), blue());
}

static Optional<Color> parse_rgb_color(const StringView& string)
Expand Down
1 change: 1 addition & 0 deletions Libraries/LibGfx/Color.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class Color {
}

String to_string() const;
String to_string_without_alpha() const;
static Optional<Color> from_string(const StringView&);

HSV to_hsv() const
Expand Down

0 comments on commit 17e76b4

Please sign in to comment.