LibGfx/Color: Add suggested_foreground_color() method

This allows you to ask the color to recommend either white/black
as a contrasting text color if you were using the color as the
background. This uses the previously added luminosity() method.
This commit is contained in:
Mustafa Quraish 2021-09-02 17:51:56 -04:00 committed by Andreas Kling
parent 882d57326c
commit 1cbab1c7e6
Notes: sideshowbarker 2024-07-18 04:50:51 +09:00

View file

@ -392,6 +392,11 @@ public:
return Color(out_r, out_g, out_b);
}
constexpr Color suggested_foreground_color() const
{
return luminosity() < 128 ? Color::White : Color::Black;
}
private:
constexpr explicit Color(RGBA32 rgba)
: m_value(rgba)