mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-02-23 16:14:23 +00:00
LibGUI: Support cycling through focusable widgets with Tab and Shift-Tab.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user