diff options
author | Andreas Kling <kling@serenityos.org> | 2020-12-07 19:46:34 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-12-07 19:46:34 +0100 |
commit | ab289e183efdb0a5f57dc512e2979dd86c749bb4 (patch) | |
tree | 305091426584336b497d2e7a211ef056fc329d0d /Libraries | |
parent | 5b0deba49c3879a1ac78e1f646348dbe79038dda (diff) | |
download | serenity-ab289e183efdb0a5f57dc512e2979dd86c749bb4.zip |
LibGUI: Expose widget focus policy as a Core::Object property
This makes focus policies show up in the inspector which is helpful.
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibGUI/Widget.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Libraries/LibGUI/Widget.cpp b/Libraries/LibGUI/Widget.cpp index 9c5cb721f5..2406e2119e 100644 --- a/Libraries/LibGUI/Widget.cpp +++ b/Libraries/LibGUI/Widget.cpp @@ -124,6 +124,40 @@ Widget::Widget() REGISTER_INT_PROPERTY("preferred_height", preferred_height, set_preferred_height); REGISTER_SIZE_POLICY_PROPERTY("horizontal_size_policy", horizontal_size_policy, set_horizontal_size_policy); REGISTER_SIZE_POLICY_PROPERTY("vertical_size_policy", vertical_size_policy, set_vertical_size_policy); + + register_property( + "focus_policy", [this]() -> JsonValue { + auto policy = focus_policy(); + if (policy == GUI::FocusPolicy::ClickFocus) + return "ClickFocus"; + if (policy == GUI::FocusPolicy::NoFocus) + return "NoFocus"; + if (policy == GUI::FocusPolicy::TabFocus) + return "TabFocus"; + if (policy == GUI::FocusPolicy::StrongFocus) + return "StrongFocus"; + return JsonValue(); }, + [this](auto& value) { + if (!value.is_string()) + return false; + if (value.as_string() == "ClickFocus") { + set_focus_policy(GUI::FocusPolicy::ClickFocus); + return true; + } + if (value.as_string() == "NoFocus") { + set_focus_policy(GUI::FocusPolicy::NoFocus); + return true; + } + if (value.as_string() == "TabFocus") { + set_focus_policy(GUI::FocusPolicy::TabFocus); + return true; + } + if (value.as_string() == "StrongFocus") { + set_focus_policy(GUI::FocusPolicy::StrongFocus); + return true; + } + return false; + }); } Widget::~Widget() |