Editor manages window class IDs so tool windows cannot be docked with other tools or with the main editor window

Gui_Panel_Refactor
Joeyrp 4 years ago
parent 145dd7095c
commit 8ac5ef51d5

@ -31,7 +31,7 @@ namespace editor
Editor::Editor() Editor::Editor()
: mLogCat(-1), mpFileBrowser(nullptr), mpPath(nullptr), mDoNewProject(false), mDoOpenProject(false), : mLogCat(-1), mpFileBrowser(nullptr), mpPath(nullptr), mDoNewProject(false), mDoOpenProject(false),
mDoSaveProject(false), mDoSaveAs(false), mpMapEditor(nullptr) mDoSaveProject(false), mDoSaveAs(false), mNextWindowID(0), mpMapEditor(nullptr)
{ {
} }
@ -94,6 +94,11 @@ namespace editor
return mLogCat; return mLogCat;
} }
unsigned int Editor::GetNextWindowID()
{
return ++mNextWindowID;
}
bool Editor::IsToolOpen(ToolType type) const bool Editor::IsToolOpen(ToolType type) const
{ {

@ -25,6 +25,7 @@ namespace lunarium
enum ToolType enum ToolType
{ {
TT_MAIN_EDITOR,
TT_MAP_EDITOR, TT_MAP_EDITOR,
}; };
@ -40,6 +41,7 @@ namespace lunarium
uint32_t GetLogCat() const; uint32_t GetLogCat() const;
unsigned int GetNextWindowID();
bool IsToolOpen(ToolType type) const; bool IsToolOpen(ToolType type) const;
private: private:
@ -52,6 +54,7 @@ namespace lunarium
Project mProject; Project mProject;
// Tools // Tools
unsigned int mNextWindowID;
MapEditor* mpMapEditor; MapEditor* mpMapEditor;
FileBrowser* mpFileBrowser; FileBrowser* mpFileBrowser;

@ -9,7 +9,6 @@
#include "panel_manager.h" #include "panel_manager.h"
#include "editor.h" #include "editor.h"
#include <utils/logger.h> #include <utils/logger.h>
#include <gui/dearimgui/imgui.h>
#include <gui/dearimgui/imgui_internal.h> // To use the DockWindowXXX methods #include <gui/dearimgui/imgui_internal.h> // To use the DockWindowXXX methods
#include <filesystem> #include <filesystem>
@ -52,10 +51,8 @@ namespace lunarium { namespace editor
{ {
mpEditor = editor; mpEditor = editor;
memset(&mWindowClass, 0, sizeof(ImGuiWindowClass));
//mpMainPanel = &MainPanel::GetInstance(); mWindowClass.ClassId = mpEditor->GetNextWindowID();
// mpMainPanel->SetEditor(mpEditor);
//mpMainPanel->ResetDockSpace();
if (!std::filesystem::exists("imgui.ini")) if (!std::filesystem::exists("imgui.ini"))
{ {
@ -70,7 +67,6 @@ namespace lunarium { namespace editor
void PanelManager::Shutdown() void PanelManager::Shutdown()
{ {
DestoryPanels(); DestoryPanels();
//MainPanel::FreeInstance();
} }
void PanelManager::OpenPanel(PanelType type) void PanelManager::OpenPanel(PanelType type)
@ -118,6 +114,11 @@ namespace lunarium { namespace editor
return nullptr; return nullptr;
} }
const ImGuiWindowClass* PanelManager::GetWindowClass() const
{
return &mWindowClass;
}
void PanelManager::ResetDocking() void PanelManager::ResetDocking()
{ {
mResetDockSpace = true; mResetDockSpace = true;
@ -161,6 +162,7 @@ namespace lunarium { namespace editor
{ {
if (iter->second->IsOpen()) if (iter->second->IsOpen())
{ {
ImGui::SetNextWindowClass(&mWindowClass);
iter->second->DoFrame(); iter->second->DoFrame();
} }
} }
@ -193,11 +195,13 @@ namespace lunarium { namespace editor
void PanelManager::MakeDockSpaces() void PanelManager::MakeDockSpaces()
{ {
ImGuiViewport* Viewport = ImGui::GetMainViewport(); ImGuiViewport* Viewport = ImGui::GetMainViewport();
mDockSpaceID = ImGui::DockSpace(ImGui::GetID("Lunarium Editor Dockspace")); ImGuiID windowID = mpEditor->GetNextWindowID();
mDockSpaceID = ImGui::DockSpace(ImGui::GetID("Lunarium Editor Dockspace"), ImVec2(0, 0), 0, &mWindowClass);
if (!ImGui::DockBuilderGetNode(mDockSpaceID) || mResetDockSpace) if (!ImGui::DockBuilderGetNode(mDockSpaceID) || mResetDockSpace)
{ {
Logger::Log(mpEditor->GetLogCat(), LogLevel::INFO, "Resetting Dockspaces"); Logger::Log(mpEditor->GetLogCat(), LogLevel::INFO, "Resetting Dockspaces");
mResetDockSpace = false; mResetDockSpace = false;
ImGui::DockBuilderRemoveNode(mDockSpaceID); ImGui::DockBuilderRemoveNode(mDockSpaceID);
ImGui::DockBuilderAddNode(mDockSpaceID, ImGuiDockNodeFlags_DockSpace); ImGui::DockBuilderAddNode(mDockSpaceID, ImGuiDockNodeFlags_DockSpace);

@ -10,10 +10,12 @@
#define PANEL_MANAGER_H_ #define PANEL_MANAGER_H_
#include <utils/opRes.h> #include <utils/opRes.h>
//#include "panels/mainPanel.h" #include <gui/dearimgui/imgui.h>
#include <gui/panel.h> #include <gui/panel.h>
#include <map> #include <map>
struct ImGuiWindowClass;
namespace lunarium{ namespace lunarium{
class IGraphics; class IGraphics;
namespace editor namespace editor
@ -32,6 +34,7 @@ namespace editor
void ClosePanel(gui::PanelType type); void ClosePanel(gui::PanelType type);
bool IsOpen(gui::PanelType type); bool IsOpen(gui::PanelType type);
gui::Panel* GetPanel(gui::PanelType type); gui::Panel* GetPanel(gui::PanelType type);
const ImGuiWindowClass* GetWindowClass() const;
void ResetDocking(); void ResetDocking();
@ -44,6 +47,7 @@ namespace editor
bool mResetDockSpace; bool mResetDockSpace;
std::map<gui::PanelType, gui::Panel*> mPanels; std::map<gui::PanelType, gui::Panel*> mPanels;
unsigned int mDockSpaceID; unsigned int mDockSpaceID;
ImGuiWindowClass mWindowClass;
std::map<gui::PanelDockZone, unsigned int> mDockZoneIDs; std::map<gui::PanelDockZone, unsigned int> mDockZoneIDs;
private: private:

Loading…
Cancel
Save