1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-22 19:45:08 +00:00

LibGUI: Support cycling through focusable widgets with Tab and Shift-Tab.

This commit is contained in:
Andreas Kling 2019-05-15 02:39:58 +02:00
parent 01ffcdfa31
commit ad731cc08f
10 changed files with 82 additions and 8 deletions

View file

@ -513,3 +513,27 @@ void GWindow::start_wm_resize()
message.wm.window_id = m_window_id;
GEventLoop::post_message_to_server(message);
}
Vector<GWidget*> GWindow::focusable_widgets() const
{
if (!m_main_widget)
return { };
Vector<GWidget*> collected_widgets;
Function<void(GWidget&)> collect_focusable_widgets = [&] (GWidget& widget) {
if (widget.accepts_focus())
collected_widgets.append(&widget);
for (auto& child : widget.children()) {
if (!child->is_widget())
continue;
auto& child_widget = *static_cast<GWidget*>(child);
if (!child_widget.is_visible())
continue;
collect_focusable_widgets(child_widget);
}
};
collect_focusable_widgets(*m_main_widget);
return collected_widgets;
}