mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:27:45 +00:00
LibGUI: Add foreground_role and background_role property to GUI::Widget
These properties allow GML files to specify a Gfx::ColorRole instead of a color, so that the effective color of the Widget is resolved using the system theme.
This commit is contained in:
parent
d0c7a48186
commit
d19edb0762
1 changed files with 45 additions and 0 deletions
|
@ -21,6 +21,7 @@
|
||||||
#include <LibGfx/Font.h>
|
#include <LibGfx/Font.h>
|
||||||
#include <LibGfx/FontDatabase.h>
|
#include <LibGfx/FontDatabase.h>
|
||||||
#include <LibGfx/Palette.h>
|
#include <LibGfx/Palette.h>
|
||||||
|
#include <LibGfx/SystemTheme.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
REGISTER_CORE_OBJECT(GUI, Widget)
|
REGISTER_CORE_OBJECT(GUI, Widget)
|
||||||
|
@ -136,6 +137,50 @@ Widget::Widget()
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
register_property(
|
||||||
|
"foreground_role", [this]() -> JsonValue { return Gfx::to_string(foreground_role()); },
|
||||||
|
[this](auto& value) {
|
||||||
|
if (!value.is_string())
|
||||||
|
return false;
|
||||||
|
auto str = value.as_string();
|
||||||
|
if (str == "NoRole") {
|
||||||
|
set_foreground_role(Gfx::ColorRole::NoRole);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#undef __ENUMERATE_COLOR_ROLE
|
||||||
|
#define __ENUMERATE_COLOR_ROLE(role) \
|
||||||
|
else if (str == #role) \
|
||||||
|
{ \
|
||||||
|
set_foreground_role(Gfx::ColorRole::role); \
|
||||||
|
return true; \
|
||||||
|
}
|
||||||
|
ENUMERATE_COLOR_ROLES(__ENUMERATE_COLOR_ROLE)
|
||||||
|
#undef __ENUMERATE_COLOR_ROLE
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
register_property(
|
||||||
|
"background_role", [this]() -> JsonValue { return Gfx::to_string(background_role()); },
|
||||||
|
[this](auto& value) {
|
||||||
|
if (!value.is_string())
|
||||||
|
return false;
|
||||||
|
auto str = value.as_string();
|
||||||
|
if (str == "NoRole") {
|
||||||
|
set_background_role(Gfx::ColorRole::NoRole);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#undef __ENUMERATE_COLOR_ROLE
|
||||||
|
#define __ENUMERATE_COLOR_ROLE(role) \
|
||||||
|
else if (str == #role) \
|
||||||
|
{ \
|
||||||
|
set_background_role(Gfx::ColorRole::role); \
|
||||||
|
return true; \
|
||||||
|
}
|
||||||
|
ENUMERATE_COLOR_ROLES(__ENUMERATE_COLOR_ROLE)
|
||||||
|
#undef __ENUMERATE_COLOR_ROLE
|
||||||
|
return false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget::~Widget()
|
Widget::~Widget()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue