Skip to content
Snippets Groups Projects
Unverified Commit c0f01da0 authored by Leon Dietrich's avatar Leon Dietrich
Browse files

chg: Wrote better code for child handling

Not deleting the objects should be fine due to the ussage of
std::unique_ptr
parent 978911f2
No related branches found
No related tags found
No related merge requests found
Pipeline #
...@@ -7,16 +7,28 @@ namespace rmrf::ui { ...@@ -7,16 +7,28 @@ namespace rmrf::ui {
view::view(std::shared_ptr<view> parent) : parent_view{parent} { view::view(std::shared_ptr<view> parent) : parent_view{parent} {
if(this->parent_view != nullptr) { if(this->parent_view != nullptr) {
const std::shared_ptr<new_child_event> child_event(new new_child_event(this)); this->parent_view->add_child(this);
this->parent_view->schedule_update(child_event);
if (child_event->unique()) {
child_event->reset(); // Delete the object if it wasn't stored elsewhere
}
} }
} }
view::~view() {
if(this->parent_view != nullptr) {
this->parent_view->remove_child(this);
}
// Delete all childs that still exist
this->child_views.clear();
}
std::shared_ptr<view> view::get_parent() { std::shared_ptr<view> view::get_parent() {
return this->parent_view; return this->parent_view;
} }
void view::add_child(std::unique_ptr<view> child) {
this->child_views.push_back(child);
}
void view::remove_child(std::unique_ptr<view> child) {
this->child_views.remove(child);
}
} }
...@@ -45,6 +45,10 @@ public: ...@@ -45,6 +45,10 @@ public:
class view : public ui_context { class view : public ui_context {
private: private:
std::shared_ptr<view> parent_view; std::shared_ptr<view> parent_view;
std::list<std::unique_ptr<view>> child_views;
private:
void add_child(std::unique_ptr<view> child);
void remove_child(std::unique_ptr<view> child);
public: public:
/** /**
* This method will be called when an operation is taking place. It may add * This method will be called when an operation is taking place. It may add
...@@ -84,7 +88,7 @@ public: ...@@ -84,7 +88,7 @@ public:
* @param parent The parent view of this view. This may be null if there is none. * @param parent The parent view of this view. This may be null if there is none.
*/ */
view(std::shared_ptr<view> parent); view(std::shared_ptr<view> parent);
virtual ~view(); ~view();
}; };
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment