summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI/Widget.cpp
diff options
context:
space:
mode:
authorDoubleNegation <43982164+DoubleNegation@users.noreply.github.com>2021-06-28 13:30:28 +0200
committerAndreas Kling <kling@serenityos.org>2021-07-01 00:10:25 +0200
commitd19edb076228009f53f74439a9e88113ef7c885f (patch)
tree04e833890af259d1999b564565e99188d739c10f /Userland/Libraries/LibGUI/Widget.cpp
parentd0c7a481863fd98c51591f9178843ab7cf9af819 (diff)
downloadserenity-d19edb076228009f53f74439a9e88113ef7c885f.zip
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.
Diffstat (limited to 'Userland/Libraries/LibGUI/Widget.cpp')
-rw-r--r--Userland/Libraries/LibGUI/Widget.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/Widget.cpp b/Userland/Libraries/LibGUI/Widget.cpp
index 8dcb9a5062..026bab275b 100644
--- a/Userland/Libraries/LibGUI/Widget.cpp
+++ b/Userland/Libraries/LibGUI/Widget.cpp
@@ -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()