summaryrefslogtreecommitdiff
path: root/Libraries/LibGUI/GStackWidget.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-07-04 16:16:50 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-07-04 16:16:50 +0200
commit04b9dc2d30cfc9b383029f6a4b02e2725108b0ae (patch)
treee117a998173b767f9fd009d49c4f8573d8b85432 /Libraries/LibGUI/GStackWidget.cpp
parent63814ffebf16291419745cd8ba29a4d2fd888563 (diff)
downloadserenity-04b9dc2d30cfc9b383029f6a4b02e2725108b0ae.zip
Libraries: Create top level directory for libraries.
Things were getting a little crowded in the project root, so this patch moves the Lib*/ directories into Libraries/.
Diffstat (limited to 'Libraries/LibGUI/GStackWidget.cpp')
-rw-r--r--Libraries/LibGUI/GStackWidget.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/Libraries/LibGUI/GStackWidget.cpp b/Libraries/LibGUI/GStackWidget.cpp
new file mode 100644
index 0000000000..010cfc6855
--- /dev/null
+++ b/Libraries/LibGUI/GStackWidget.cpp
@@ -0,0 +1,55 @@
+#include <LibGUI/GBoxLayout.h>
+#include <LibGUI/GStackWidget.h>
+
+GStackWidget::GStackWidget(GWidget* parent)
+ : GWidget(parent)
+{
+}
+
+GStackWidget::~GStackWidget()
+{
+}
+
+void GStackWidget::set_active_widget(GWidget* widget)
+{
+ if (widget == m_active_widget)
+ return;
+
+ if (m_active_widget)
+ m_active_widget->set_visible(false);
+ m_active_widget = widget;
+ if (m_active_widget) {
+ m_active_widget->set_relative_rect(rect());
+ m_active_widget->set_visible(true);
+ }
+}
+
+void GStackWidget::resize_event(GResizeEvent& event)
+{
+ if (!m_active_widget)
+ return;
+ m_active_widget->set_relative_rect({ {}, event.size() });
+}
+
+void GStackWidget::child_event(CChildEvent& event)
+{
+ if (!event.child() || !is<GWidget>(*event.child()))
+ return GWidget::child_event(event);
+ auto& child = to<GWidget>(*event.child());
+ if (event.type() == GEvent::ChildAdded) {
+ if (!m_active_widget)
+ set_active_widget(&child);
+ else if (m_active_widget != &child)
+ child.set_visible(false);
+ } else if (event.type() == GEvent::ChildRemoved) {
+ if (m_active_widget == &child) {
+ GWidget* new_active_widget = nullptr;
+ for_each_child_widget([&](auto& new_child) {
+ new_active_widget = &new_child;
+ return IterationDecision::Break;
+ });
+ set_active_widget(new_active_widget);
+ }
+ }
+ GWidget::child_event(event);
+}