Files
mirage/src/widget_tree/widget_manager.cpp
2025-03-24 00:48:27 +08:00

39 lines
1.2 KiB
C++

#include "widget_manager.h"
#include "widget_system.h"
#include "core/window/mwindow.h"
void widget_manager::init_window(const std::shared_ptr<mwindow>& in_window) {
auto& registry = registries[in_window.get()];
auto& system_manager = registry.systems();
auto& entity_manager = registry.entities();
const auto layout_system = std::make_shared<widget_layout_system>();
const auto hit_test_system = std::make_shared<widget_hit_test_system>();
const auto render_system = std::make_shared<widget_render_system>();
layout_system->set_window(in_window);
hit_test_system->set_window(in_window);
render_system->set_window(in_window);
system_manager.addSystem(layout_system);
system_manager.addSystem(hit_test_system);
system_manager.addSystem(render_system);
registry.init();
in_window->on_close_delegate.add_raw(this, &widget_manager::on_window_close);
const auto& entity = entity_manager.create<>();
widget_key key { in_window.get(), entity };
in_window->set_key(key);
in_window->init_component(entity_manager);
}
void widget_manager::update() {
for (auto& pair : registries) {
auto& registry = pair.second;
registry.systems().update();
}
}