Skip to content
Snippets Groups Projects
view.cpp 669 B
Newer Older
Leon Dietrich's avatar
Leon Dietrich committed
#include <memory>

#include "ui/view.hpp"
Leon Dietrich's avatar
Leon Dietrich committed
#include "ui/new_child_event.hpp"
Leon Dietrich's avatar
Leon Dietrich committed
view::view(std::shared_ptr<view> parent) : parent_view{parent} {
	if(this->parent_view != nullptr) {
		this->parent_view->add_child(this);
Leon Dietrich's avatar
Leon Dietrich committed
	}
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() {
Leon Dietrich's avatar
Leon Dietrich committed
	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);
}