diff options
author | Andreas Kling <kling@serenityos.org> | 2020-05-12 15:47:13 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-12 15:48:31 +0200 |
commit | 39d55d1d761c5443d4b3f55a16e60fc201436b08 (patch) | |
tree | 786f034f7103e6795d4941dfb928da66d7222c2b /Libraries/LibGUI | |
parent | e064999e0d9d6d91b846a9d8afe3e05e45559dd3 (diff) | |
download | serenity-39d55d1d761c5443d4b3f55a16e60fc201436b08.zip |
LibGUI: Add a way to highlight the focused widget for debugging
You can now pass --gui-focus-debug to any GUI::Application and it will
draw a cyan rectangle around the currently focused widget.
Diffstat (limited to 'Libraries/LibGUI')
-rw-r--r-- | Libraries/LibGUI/Application.cpp | 10 | ||||
-rw-r--r-- | Libraries/LibGUI/Application.h | 3 | ||||
-rw-r--r-- | Libraries/LibGUI/Widget.cpp | 7 |
3 files changed, 18 insertions, 2 deletions
diff --git a/Libraries/LibGUI/Application.cpp b/Libraries/LibGUI/Application.cpp index 322869b91f..b2d2121da9 100644 --- a/Libraries/LibGUI/Application.cpp +++ b/Libraries/LibGUI/Application.cpp @@ -56,8 +56,14 @@ Application::Application(int argc, char** argv) WindowServerConnection::the(); if (argc > 0) m_invoked_as = argv[0]; - for (int i = 1; i < argc; i++) - m_args.append(argv[i]); + for (int i = 1; i < argc; i++) { + String arg(argv[i]); + + if (arg == "--gui-focus-debug") + m_focus_debugging_enabled = true; + + m_args.append(move(arg)); + } } Application::~Application() diff --git a/Libraries/LibGUI/Application.h b/Libraries/LibGUI/Application.h index 422bbc06e4..cfb63985d9 100644 --- a/Libraries/LibGUI/Application.h +++ b/Libraries/LibGUI/Application.h @@ -68,6 +68,8 @@ public: void set_system_palette(SharedBuffer&); + bool focus_debugging_enabled() const { return m_focus_debugging_enabled; } + private: OwnPtr<Core::EventLoop> m_event_loop; RefPtr<MenuBar> m_menubar; @@ -77,6 +79,7 @@ private: class TooltipWindow; RefPtr<TooltipWindow> m_tooltip_window; bool m_quit_when_last_window_deleted { true }; + bool m_focus_debugging_enabled { false }; String m_invoked_as; Vector<String> m_args; }; diff --git a/Libraries/LibGUI/Widget.cpp b/Libraries/LibGUI/Widget.cpp index 666ca70ed4..06fd723fda 100644 --- a/Libraries/LibGUI/Widget.cpp +++ b/Libraries/LibGUI/Widget.cpp @@ -242,6 +242,13 @@ void Widget::handle_paint_event(PaintEvent& event) Painter painter(*this); painter.draw_rect(rect(), Color::Magenta); } + + if (Application::the().focus_debugging_enabled()) { + if (is_focused()) { + Painter painter(*this); + painter.draw_rect(rect(), Color::Cyan); + } + } } void Widget::set_layout(NonnullRefPtr<Layout> layout) |