summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibGUI/GLazyWidget.cpp20
-rw-r--r--Libraries/LibGUI/GLazyWidget.h19
-rw-r--r--Libraries/LibGUI/Makefile1
3 files changed, 40 insertions, 0 deletions
diff --git a/Libraries/LibGUI/GLazyWidget.cpp b/Libraries/LibGUI/GLazyWidget.cpp
new file mode 100644
index 0000000000..e8eed96d0e
--- /dev/null
+++ b/Libraries/LibGUI/GLazyWidget.cpp
@@ -0,0 +1,20 @@
+#include <LibGUI/GLazyWidget.h>
+
+GLazyWidget::GLazyWidget(GWidget* parent)
+ : GWidget(parent)
+{
+}
+
+GLazyWidget::~GLazyWidget()
+{
+}
+
+void GLazyWidget::show_event(GShowEvent&)
+{
+ if (m_has_been_shown)
+ return;
+ m_has_been_shown = true;
+
+ ASSERT(on_first_show);
+ on_first_show(*this);
+}
diff --git a/Libraries/LibGUI/GLazyWidget.h b/Libraries/LibGUI/GLazyWidget.h
new file mode 100644
index 0000000000..69bc235508
--- /dev/null
+++ b/Libraries/LibGUI/GLazyWidget.h
@@ -0,0 +1,19 @@
+#pragma once
+
+#include <LibGUI/GWidget.h>
+
+class GLazyWidget : public GWidget {
+ C_OBJECT(GLazyWidget)
+public:
+ virtual ~GLazyWidget() override;
+
+ Function<void(GLazyWidget&)> on_first_show;
+
+protected:
+ explicit GLazyWidget(GWidget* parent = nullptr);
+
+private:
+ virtual void show_event(GShowEvent&) override;
+
+ bool m_has_been_shown { false };
+};
diff --git a/Libraries/LibGUI/Makefile b/Libraries/LibGUI/Makefile
index ad806e4108..24d3d70ad7 100644
--- a/Libraries/LibGUI/Makefile
+++ b/Libraries/LibGUI/Makefile
@@ -55,6 +55,7 @@ OBJS = \
GJsonArrayModel.o \
GAboutDialog.o \
GModelSelection.o \
+ GLazyWidget.o \
GWindow.o
LIBRARY = libgui.a