Adds LogIfFailed to the OpRes class

Gui_Panel_Refactor
Joeyrp 4 years ago
parent 4c48c455b1
commit 72fb87e667

@ -33,6 +33,8 @@ namespace lunarium { namespace gui
DDZ_CENTER, DDZ_CENTER,
DDZ_RIGHT, DDZ_RIGHT,
DDZ_BOTTOM, DDZ_BOTTOM,
DDZ_BOT_LEFT,
DDZ_BOT_RIGHT,
DDZ_NONE DDZ_NONE
}; };

@ -7,6 +7,7 @@
* *
******************************************************************************/ ******************************************************************************/
#include "logger.h"
#include "opRes.h" #include "opRes.h"
#include <stdarg.h> #include <stdarg.h>
@ -40,6 +41,21 @@ namespace lunarium
return { ResultType::FAIL, OpRes::Buffer }; return { ResultType::FAIL, OpRes::Buffer };
} }
OpRes OpRes::LogIfFailed(int category, const char* prepend_msg)
{
if (ResultType::FAIL == Type)
{
std::string msg;
if (prepend_msg)
{
msg = prepend_msg;
}
msg += Description;
Logger::Log(category, LogLevel::ERROR, msg.c_str());
}
return *this;
}
bool IsOK(OpRes&& res) bool IsOK(OpRes&& res)
{ {
return res.Type == ResultType::OK; return res.Type == ResultType::OK;

@ -38,6 +38,8 @@ namespace lunarium
static OpRes Fail(const char* why, ...); static OpRes Fail(const char* why, ...);
OpRes LogIfFailed(int category, const char* prepend_msg = nullptr);
private: private:
static const int BUFFER_SIZE = 512; static const int BUFFER_SIZE = 512;
static char Buffer[OpRes::BUFFER_SIZE]; static char Buffer[OpRes::BUFFER_SIZE];

@ -51,15 +51,16 @@ namespace editor
// Init editor panels // Init editor panels
mAboutPanel.SetOpen(false); mAboutPanel.SetOpen(false);
mPanelManager.Initialize(this, "Lunarium editor"); OpRes res = mPanelManager.Initialize(this, "Lunarium editor", true).LogIfFailed(mLogCat);
OpRes result = mPanelManager.AddPanel(gui::PanelType::PT_ASSET_BROWSER, new AssetBrowser("")); if (Failed(res))
LOG_ERR_AND_RETURN(result); {
result = mPanelManager.AddPanel(gui::PanelType::PT_WORLD_TREE, new WorldTree()); return res;
LOG_ERR_AND_RETURN(result); }
result = mPanelManager.AddPanel(gui::PanelType::PT_WORLD_VIEW, new WorldView());
LOG_ERR_AND_RETURN(result); mPanelManager.AddPanel(gui::PanelType::PT_ASSET_BROWSER, new AssetBrowser("")).LogIfFailed(mLogCat);
result = mPanelManager.AddPanel(gui::PanelType::PT_PROPERTIES_VIEW, new PropertiesView()); mPanelManager.AddPanel(gui::PanelType::PT_WORLD_TREE, new WorldTree()).LogIfFailed(mLogCat);
LOG_ERR_AND_RETURN(result); mPanelManager.AddPanel(gui::PanelType::PT_WORLD_VIEW, new WorldView()).LogIfFailed(mLogCat);
mPanelManager.AddPanel(gui::PanelType::PT_PROPERTIES_VIEW, new PropertiesView()).LogIfFailed(mLogCat);
return OpRes::OK(); return OpRes::OK();
} }
@ -303,6 +304,13 @@ namespace editor
{ {
mPanelManager.ResetDocking(); mPanelManager.ResetDocking();
} }
ImGui::Separator();
HanelOpenPanel("Asset Browser", gui::PanelType::PT_ASSET_BROWSER);
HanelOpenPanel("World Tree", gui::PanelType::PT_WORLD_TREE);
HanelOpenPanel("World View", gui::PanelType::PT_WORLD_VIEW);
HanelOpenPanel("Properties", gui::PanelType::PT_PROPERTIES_VIEW);
ImGui::EndMenu(); ImGui::EndMenu();
} }
@ -335,6 +343,15 @@ namespace editor
ImGui::EndMainMenuBar(); ImGui::EndMainMenuBar();
} }
void Editor::HanelOpenPanel(const char* name, gui::PanelType type)
{
if (ImGui::MenuItem(name))
{
mPanelManager.OpenPanel(type);
}
}
void Editor::DoStatusBar() void Editor::DoStatusBar()
{ {
const ImGuiViewport* viewport = ImGui::GetMainViewport(); const ImGuiViewport* viewport = ImGui::GetMainViewport();

@ -78,6 +78,8 @@ namespace lunarium
void DoStatusBar(); void DoStatusBar();
void DestroyTools(); void DestroyTools();
void HandleMenuEvents(); void HandleMenuEvents();
void HanelOpenPanel(const char* name, gui::PanelType type);
}; };
} }

@ -24,15 +24,16 @@ using namespace lunarium::gui;
namespace lunarium { namespace editor namespace lunarium { namespace editor
{ {
PanelManager::PanelManager() PanelManager::PanelManager()
: mpEditor(nullptr), mResetDockSpace(false), mDockSpaceID(0) : mpEditor(nullptr), mResetDockSpace(false), mDockSpaceID(0), mSplitBottom(false)
{ {
} }
OpRes PanelManager::Initialize(Editor* editor, std::string name) OpRes PanelManager::Initialize(Editor* editor, std::string name, bool split_bottom)
{ {
mpEditor = editor; mpEditor = editor;
mName = name; mName = name;
mSplitBottom = split_bottom;
memset(&mWindowClass, 0, sizeof(ImGuiWindowClass)); memset(&mWindowClass, 0, sizeof(ImGuiWindowClass));
mWindowClass.ClassId = mpEditor->GetNextWindowID(); mWindowClass.ClassId = mpEditor->GetNextWindowID();
@ -53,7 +54,7 @@ namespace lunarium { namespace editor
OpRes PanelManager::AddPanel(gui::PanelType type, gui::Panel* panel) OpRes PanelManager::AddPanel(gui::PanelType type, gui::Panel* panel)
{ {
if (GetPanel(type)) if (mPanels.find(type) != mPanels.end())
{ {
return OpRes::Fail("Cannot add panel - panel already exists. Panel Name: %s", panel->GetName()); return OpRes::Fail("Cannot add panel - panel already exists. Panel Name: %s", panel->GetName());
} }
@ -113,6 +114,17 @@ namespace lunarium { namespace editor
return &mWindowClass; return &mWindowClass;
} }
bool PanelManager::IsBottomSplit() const
{
return mSplitBottom;
}
void PanelManager::SetSplitBottom(bool split_bottom)
{
mSplitBottom = split_bottom;
}
void PanelManager::ResetDocking() void PanelManager::ResetDocking()
{ {
mResetDockSpace = true; mResetDockSpace = true;
@ -195,6 +207,12 @@ namespace lunarium { namespace editor
//ImGui::DockBuilderSetNodePos(mDockSpaces.Main, Viewport->WorkPos); //ImGui::DockBuilderSetNodePos(mDockSpaces.Main, Viewport->WorkPos);
ImGui::DockBuilderSplitNode(mDockSpaceID, ImGuiDir_Down, 0.25f, &mDockZoneIDs[PanelDockZone::DDZ_BOTTOM], &mDockZoneIDs[PanelDockZone::DDZ_CENTER]); ImGui::DockBuilderSplitNode(mDockSpaceID, ImGuiDir_Down, 0.25f, &mDockZoneIDs[PanelDockZone::DDZ_BOTTOM], &mDockZoneIDs[PanelDockZone::DDZ_CENTER]);
if (mSplitBottom)
{
ImGui::DockBuilderSplitNode(mDockZoneIDs[PanelDockZone::DDZ_BOTTOM], ImGuiDir_Left, 0.2f, &mDockZoneIDs[PanelDockZone::DDZ_BOT_LEFT], &mDockZoneIDs[PanelDockZone::DDZ_BOT_RIGHT]);
}
ImGui::DockBuilderSplitNode(mDockZoneIDs[PanelDockZone::DDZ_CENTER], ImGuiDir_Right, 0.2f, &mDockZoneIDs[PanelDockZone::DDZ_RIGHT], &mDockZoneIDs[PanelDockZone::DDZ_CENTER]); ImGui::DockBuilderSplitNode(mDockZoneIDs[PanelDockZone::DDZ_CENTER], ImGuiDir_Right, 0.2f, &mDockZoneIDs[PanelDockZone::DDZ_RIGHT], &mDockZoneIDs[PanelDockZone::DDZ_CENTER]);
ImGui::DockBuilderSplitNode(mDockZoneIDs[PanelDockZone::DDZ_CENTER], ImGuiDir_Left, 0.2f, &mDockZoneIDs[PanelDockZone::DDZ_LEFT], &mDockZoneIDs[PanelDockZone::DDZ_CENTER]); ImGui::DockBuilderSplitNode(mDockZoneIDs[PanelDockZone::DDZ_CENTER], ImGuiDir_Left, 0.2f, &mDockZoneIDs[PanelDockZone::DDZ_LEFT], &mDockZoneIDs[PanelDockZone::DDZ_CENTER]);
ImGui::DockBuilderFinish(mDockSpaceID); ImGui::DockBuilderFinish(mDockSpaceID);
@ -205,6 +223,22 @@ namespace lunarium { namespace editor
PanelDockZone dz = iter->second->GetDockZone(); PanelDockZone dz = iter->second->GetDockZone();
if (dz != PanelDockZone::DDZ_NONE) if (dz != PanelDockZone::DDZ_NONE)
{ {
// If the panel expects the bottom node to be split but it isn't
// we need to change it to just dock to the bottom
if ((dz == PanelDockZone::DDZ_BOT_LEFT ||
dz == PanelDockZone::DDZ_BOT_RIGHT) &&
!mSplitBottom)
{
dz = PanelDockZone::DDZ_BOTTOM;
}
// Also need to account for the opposite situation
// Default it to the bottom left
if (dz == PanelDockZone::DDZ_BOTTOM && mSplitBottom)
{
dz = PanelDockZone::DDZ_BOT_LEFT;
}
ImGui::DockBuilderDockWindow(iter->second->GetName(), mDockZoneIDs[dz]); ImGui::DockBuilderDockWindow(iter->second->GetName(), mDockZoneIDs[dz]);
} }
} }

@ -26,9 +26,10 @@ namespace editor
public: public:
PanelManager(); PanelManager();
OpRes Initialize(Editor* editor, std::string name); OpRes Initialize(Editor* editor, std::string name, bool split_bottom = false);
void Shutdown(); void Shutdown();
// Panel interface
OpRes AddPanel(gui::PanelType type, gui::Panel* panel); OpRes AddPanel(gui::PanelType type, gui::Panel* panel);
void OpenPanel(gui::PanelType type); void OpenPanel(gui::PanelType type);
void ClosePanel(gui::PanelType type); void ClosePanel(gui::PanelType type);
@ -36,6 +37,9 @@ namespace editor
gui::Panel* GetPanel(gui::PanelType type); gui::Panel* GetPanel(gui::PanelType type);
const ImGuiWindowClass* GetWindowClass() const; const ImGuiWindowClass* GetWindowClass() const;
// Docking
bool IsBottomSplit() const;
void SetSplitBottom(bool split_bottom);
void ResetDocking(); void ResetDocking();
void OnTick(double delta); void OnTick(double delta);
@ -44,6 +48,7 @@ namespace editor
private: private:
Editor* mpEditor; Editor* mpEditor;
std::string mName; std::string mName;
bool mSplitBottom; // If ture the bottom dock node will also be split into left/right
bool mResetDockSpace; bool mResetDockSpace;
std::map<gui::PanelType, gui::Panel*> mPanels; std::map<gui::PanelType, gui::Panel*> mPanels;
unsigned int mDockSpaceID; unsigned int mDockSpaceID;

Loading…
Cancel
Save