add PopupManager

This commit is contained in:
SweetId
2023-10-17 18:04:12 -04:00
parent 37c1297cf4
commit 9d2f992297
5 changed files with 160 additions and 0 deletions

View File

@@ -10,6 +10,7 @@
#include <NazaraEditor/Core/Application/EditorLogger.hpp>
#include <NazaraEditor/Core/Application/Level.hpp>
#include <NazaraEditor/Core/Components/NameComponent.hpp>
#include <NazaraEditor/Core/UI/PopupManager.hpp>
#include <NazaraEditor/Core/UI/Window.hpp>
#include <NazaraEditor/Core/Reflection/Math.hpp>
#include <NazaraEditor/Core/Reflection/Core.hpp>

View File

@@ -10,6 +10,7 @@
#include <NazaraEditor/Core/Application/Action.hpp>
#include <NazaraEditor/Core/Application/ActionStack.hpp>
#include <NazaraEditor/Core/Application/Level.hpp>
#include <NazaraEditor/Core/UI/PopupManager.hpp>
#include <NazaraEditor/Core/UI/Window.hpp>
#include <NazaraImgui/NazaraImgui.hpp>
@@ -71,6 +72,8 @@ namespace Nz
std::filesystem::path m_resourceFolder;
Nz::ActionStack m_actionStack;
Nz::EditorPopupManager m_popupManager;
Nz::Level m_level;
};
}

View File

@@ -0,0 +1,67 @@
#pragma once
#include <NazaraEditor/Core/Core.hpp>
#include <memory>
#include <vector>
namespace Nz
{
struct EditorPopupParameters
{
struct Choice
{
std::string name;
std::function<void(void)> callback;
};
std::string title;
std::string description;
std::vector<Choice> choices;
};
class EditorPopup
: public Nz::ImguiHandler
{
public:
EditorPopup(uint64_t id, const EditorPopupParameters& parameters);
~EditorPopup();
void OnRenderImgui() override;
uint64_t GetId() const { return m_id; }
private:
uint64_t m_id;
EditorPopupParameters m_parameters;
};
class NAZARAEDITOR_CORE_API EditorPopupManager
{
public:
static EditorPopupManager* Instance();
void Update();
uint64_t CreatePopup(const EditorPopupParameters& parameters);
void DestroyPopup(uint64_t popupId);
private:
EditorPopupManager();
~EditorPopupManager();
EditorPopupManager(const EditorPopupManager&) = delete;
EditorPopupManager& operator=(const EditorPopupManager&) = delete;
EditorPopupManager(EditorPopup&&) noexcept = delete;
EditorPopupManager& operator=(EditorPopup&&) = delete;
void DestroyPopupInternal(uint64_t popupId);
uint64_t m_currentIndex;
std::vector<std::unique_ptr<EditorPopup>> m_popups;
std::vector<uint64_t> m_popupsToDelete;
static EditorPopupManager* s_instance;
friend class EditorBaseApplication;
};
}