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()
: 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;
}
unsigned int Editor::GetNextWindowID()
{
return ++mNextWindowID;
}
bool Editor::IsToolOpen(ToolType type) const
{

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

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

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

Loading…
Cancel
Save