From 943371873a408b697335adb196db8b1ff38cfad4 Mon Sep 17 00:00:00 2001
From: Doralitze <doralitze@chaotikum.org>
Date: Sun, 10 Mar 2019 12:52:16 +0100
Subject: [PATCH] add: new child event

---
 src/ui/new_child_event.hpp | 13 +++++++++++++
 src/ui/view.cpp            | 13 ++++++++++---
 src/ui/view.hpp            |  9 ++++++++-
 3 files changed, 31 insertions(+), 4 deletions(-)
 create mode 100644 src/ui/new_child_event.hpp

diff --git a/src/ui/new_child_event.hpp b/src/ui/new_child_event.hpp
new file mode 100644
index 0000000..78c71ee
--- /dev/null
+++ b/src/ui/new_child_event.hpp
@@ -0,0 +1,13 @@
+#pragma once
+
+#include <memory>
+#include <string>
+
+#include "ui/event.hpp"
+
+namespace rmrf::ui {
+
+class new_child_event : event {
+};
+
+}
diff --git a/src/ui/view.cpp b/src/ui/view.cpp
index ce62f4b..4501cc9 100644
--- a/src/ui/view.cpp
+++ b/src/ui/view.cpp
@@ -1,13 +1,20 @@
+#include <memory>
+
 #include "ui/view.hpp"
+#include "ui/new_child_event.hpp"
 
 namespace rmrf::ui {
 
-view::view(std::shared_ptr<view> parent) {
-	this->parent = parent;
+view::view(std::shared_ptr<view> parent) : parent_view{parent} {
+	if(this->parent_view != nullptr) {
+		std::shared_ptr<new_child_event> child_event(new new_child_event(this));
+		this->parent_view->schedule_update(child_event);
+		delete child_event;
+	}
 }
 
 std::shared_ptr<view> view::get_parent() {
-	return this->parent;
+	return this->parent_view;
 }
 
 }
diff --git a/src/ui/view.hpp b/src/ui/view.hpp
index d4372d1..501f130 100644
--- a/src/ui/view.hpp
+++ b/src/ui/view.hpp
@@ -44,7 +44,7 @@ public:
  */
 class view : ui_context {
 private:
-    std::shared_ptr<view> parent;
+    std::shared_ptr<view> parent_view;
 public:
     /**
      * This method will be called when an operation is taking place. It may add
@@ -65,6 +65,13 @@ public:
      * @return True if rerendering is required or otherwise false.
      */
     virtual bool update(std::shared_ptr<display> display, std::shared_ptr<event> event);
+    /**
+     * This method gets called when events need to be processed that do not
+     * necessarily come from the UI thread.
+     *
+     * @param event The event that caused the update.
+     */
+    virtual void schedule_update(std::shared_ptr<event> event);
     /**
      * Use this method in order to retrieve the parent of this view.
      * @warn Keep in mind that this might be null.
-- 
GitLab