1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-11 18:20:43 +09: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:
DoubleNegation 2021-06-28 13:30:28 +02:00 committed by Andreas Kling
parent d0c7a48186
commit d19edb0762
Notes: sideshowbarker 2024-07-18 11:11:30 +09:00

View file

@ -21,6 +21,7 @@
#include <LibGfx/Font.h>
#include <LibGfx/FontDatabase.h>
#include <LibGfx/Palette.h>
#include <LibGfx/SystemTheme.h>
#include <unistd.h>
REGISTER_CORE_OBJECT(GUI, Widget)
@ -136,6 +137,50 @@ Widget::Widget()
}
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()