summaryrefslogtreecommitdiff
path: root/Libraries/LibGUI/GWidget.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-11-11 19:12:32 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-11-11 22:20:02 +0100
commit524da0ad01ef6b76669fcb69539b907d315e8e87 (patch)
tree084e2a48d41c9dc8f63deae1d60ab7f7f3fb8fc0 /Libraries/LibGUI/GWidget.cpp
parent3ef287eb9f673f6cc10cae5f7d249c0083533ee9 (diff)
downloadserenity-524da0ad01ef6b76669fcb69539b907d315e8e87.zip
LibGUI: Add "Vector<GWidget*> GWidget::child_widgets()"
This is quite inefficient since it constructs a new Vector each time.
Diffstat (limited to 'Libraries/LibGUI/GWidget.cpp')
-rw-r--r--Libraries/LibGUI/GWidget.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/Libraries/LibGUI/GWidget.cpp b/Libraries/LibGUI/GWidget.cpp
index a7088352cd..1859d84ecd 100644
--- a/Libraries/LibGUI/GWidget.cpp
+++ b/Libraries/LibGUI/GWidget.cpp
@@ -675,3 +675,15 @@ void GWidget::save_to(AK::JsonObject& json)
json.set("size_policy", String::format("[%s,%s]", to_string(horizontal_size_policy()), to_string(vertical_size_policy())));
CObject::save_to(json);
}
+
+Vector<GWidget*> GWidget::child_widgets() const
+{
+ Vector<GWidget*> widgets;
+ widgets.ensure_capacity(children().size());
+ for (auto& child : const_cast<GWidget*>(this)->children()) {
+ if (child.is_widget())
+ widgets.append(static_cast<GWidget*>(&child));
+ }
+ return widgets;
+}
+