mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 05:08:13 +00:00
LibGUI/Widget: Add helpers to set the background color
This commit is contained in:
parent
e4019ba9dc
commit
999a44969d
2 changed files with 25 additions and 9 deletions
|
@ -152,15 +152,12 @@ Widget::Widget()
|
||||||
|
|
||||||
register_property(
|
register_property(
|
||||||
"background_color", [this]() -> JsonValue { return palette().color(background_role()).to_deprecated_string(); },
|
"background_color", [this]() -> JsonValue { return palette().color(background_role()).to_deprecated_string(); },
|
||||||
[this](auto& value) {
|
[this](JsonValue const& value) {
|
||||||
auto c = Color::from_string(value.to_deprecated_string());
|
auto color_str = String::from_deprecated_string(value.to_deprecated_string());
|
||||||
if (c.has_value()) {
|
if (color_str.is_error())
|
||||||
auto _palette = palette();
|
return false;
|
||||||
_palette.set_color(background_role(), c.value());
|
|
||||||
set_palette(_palette);
|
return set_background_color(color_str.release_value());
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
register_property(
|
register_property(
|
||||||
|
@ -1085,6 +1082,22 @@ void Widget::set_foreground_role(ColorRole role)
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Widget::set_background_color(String color_str)
|
||||||
|
{
|
||||||
|
auto color = Color::from_string(color_str.to_deprecated_string());
|
||||||
|
if (!color.has_value())
|
||||||
|
return false;
|
||||||
|
set_background_color(color.release_value());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Widget::set_background_color(Gfx::Color color)
|
||||||
|
{
|
||||||
|
auto _palette = palette();
|
||||||
|
_palette.set_color(background_role(), color);
|
||||||
|
set_palette(_palette);
|
||||||
|
}
|
||||||
|
|
||||||
Gfx::Palette Widget::palette() const
|
Gfx::Palette Widget::palette() const
|
||||||
{
|
{
|
||||||
return Gfx::Palette(*m_palette);
|
return Gfx::Palette(*m_palette);
|
||||||
|
|
|
@ -254,6 +254,9 @@ public:
|
||||||
Gfx::ColorRole foreground_role() const { return m_foreground_role; }
|
Gfx::ColorRole foreground_role() const { return m_foreground_role; }
|
||||||
void set_foreground_role(Gfx::ColorRole);
|
void set_foreground_role(Gfx::ColorRole);
|
||||||
|
|
||||||
|
bool set_background_color(String);
|
||||||
|
void set_background_color(Gfx::Color);
|
||||||
|
|
||||||
void set_autofill(bool b) { set_fill_with_background_color(b); }
|
void set_autofill(bool b) { set_fill_with_background_color(b); }
|
||||||
|
|
||||||
Window* window()
|
Window* window()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue