#pragma once #include #define IMGUI_DEFINE_MATH_OPERATORS #include "imgui.h" class ViewManager; // A single screen of the UI, swapped in through the ViewManager. class View { public: virtual ~View() = default; virtual void Init() {} virtual void Update() {} virtual void Render() = 0; void InternalInit(const std::shared_ptr& manager) { // Weak to avoid a cycle: the ViewManager owns the View. this->mManager = manager; this->Init(); } protected: std::shared_ptr Manager() const { return mManager.lock(); } private: std::weak_ptr mManager; }; // Owns the active View and drives its per-frame Update/Render. class ViewManager : public std::enable_shared_from_this { public: void SetView(const std::shared_ptr& view) { mCurrent = view; if (mCurrent != nullptr) { mCurrent->InternalInit(shared_from_this()); } } const std::shared_ptr& Current() const { return mCurrent; } void Render() { if (mCurrent != nullptr) { mCurrent->Update(); mCurrent->Render(); } } private: std::shared_ptr mCurrent = nullptr; };