ImGui::Begin call moved to the Panel class

Adds PreBegin in case code needs to be run just before ImGui::Begin is called
gui_api_redesign
Joey Pollack 4 years ago
parent 09953c0e7d
commit 578bd98b40

@ -15,7 +15,8 @@
namespace lunarium
{
CoreConsole::CoreConsole()
: Console("Core Console"), mDockIsInit(false)
: Console("Core Console", ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar
| ImGuiWindowFlags_NoCollapse), mDockIsInit(false)
{
}
@ -24,14 +25,10 @@ namespace lunarium
{
}
bool CoreConsole::DoFrame()
void CoreConsole::PreBegin()
{
InitDock();
if (!mIsOpen)
return false;
ImGuiViewport* pView = ImGui::GetMainViewport();
float myHeight = pView->WorkSize.y / 3.0f;
@ -41,18 +38,11 @@ namespace lunarium
ImGui::SetNextWindowPos(ImVec2(pView->WorkPos.x, y), ImGuiCond_Always);
ImGui::SetNextWindowSize(ImVec2(pView->WorkSize.x, myHeight), ImGuiCond_Always);
ImGui::SetNextWindowBgAlpha(alpha);
if (!ImGui::Begin(GetName(), &mIsOpen, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar
| ImGuiWindowFlags_NoCollapse))
{
ImGui::End();
return mIsOpen;
}
}
void CoreConsole::DoFrame()
{
Console::DoFrame();
ImGui::End();
return mIsOpen;
}
void CoreConsole::InitDock()

@ -18,7 +18,8 @@ namespace lunarium
public:
CoreConsole();
virtual ~CoreConsole();
bool DoFrame() override;
void DoFrame() override;
void PreBegin();
private:
void InitDock();

@ -43,8 +43,8 @@ namespace lunarium
////////////////////////////////////////////////////////////
// CONSOLE
////////////////////////////////////////////////////////////
Console::Console(const char* name)
: Panel(name, PanelDockZone::DDZ_NONE, false),
Console::Console(const char* name, int window_flags)
: Panel(name, PanelDockZone::DDZ_NONE, false, window_flags),
mbNewCommand(false), mRecalledCommand(-1), mIsFocused(false), mListener(nullptr),
mbOglDebug(false), mbInfoVerbose(false), mpListener(nullptr)
{
@ -67,20 +67,14 @@ namespace lunarium
void Console::Update(float dt)
{
}
bool Console::DoFrame()
{
if (Core::Input().IsKeyDown(KeyCode::ESCAPE, true))
{
mRecalledCommand = -1;
}
}
void Console::DoFrame()
{
float history_height = ImGui::GetWindowSize().y - 45;
ImGui::BeginChild("history", ImVec2(0, history_height), false, ImGuiWindowFlags_AlwaysVerticalScrollbar | ImGuiWindowFlags_NoMove);
mIsFocused = ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows);
@ -156,8 +150,6 @@ namespace lunarium
ImGui::EndChild();
//mAlpha = mIsFocused ? 0.75f : 0.5f;
return mIsOpen;
}
const std::vector<std::string>* Console::GetCommandHistory() const

@ -32,10 +32,10 @@ namespace lunarium
class Console : public Panel
{
public:
Console(const char* name);
Console(const char* name, int window_flags);
virtual ~Console();
virtual void Update(float dt);
virtual bool DoFrame();
virtual void DoFrame();
bool IsFocused() const;

@ -12,8 +12,8 @@
namespace lunarium
{
Panel::Panel(std::string name, PanelDockZone dock_zone, bool isOpen)
: mIsOpen(isOpen), mPanelName(name), mDockZone(dock_zone)
Panel::Panel(std::string name, PanelDockZone dock_zone, bool isOpen, int window_flags)
: mIsOpen(isOpen), mPanelName(name), mDockZone(dock_zone), mWindowFlags(window_flags)
{
}
@ -33,6 +33,12 @@ namespace lunarium
return mDockZone;
}
void Panel::SetWindowFlags(int flags)
{
mWindowFlags = flags;
}
void Panel::SetOpen(bool isOpen)
{
mIsOpen = isOpen;
@ -43,7 +49,6 @@ namespace lunarium
return mIsOpen;
}
void Panel::GetPosition(int& x, int& y) const
{
x = mX;
@ -56,11 +61,74 @@ namespace lunarium
h = mHeight;
}
void Panel::SetNumPushedStyles(int num)
{
mNumPushedStyles = num;
}
void Panel::Update(float dt)
{
}
void Panel::PreBegin()
{
}
bool Panel::OnUIRender()
{
if (!mIsOpen)
return false;
PreBegin();
if (!ImGui::Begin(GetName(), &mIsOpen, (ImGuiWindowFlags) mWindowFlags))
{
ImGui::PopStyleVar(mNumPushedStyles);
ImGui::End();
return false;
}
ImGui::PopStyleVar(mNumPushedStyles);
UpdateMetaInfo();
DoFrame();
RunPopups();
ImGui::End();
return true;
}
OpRes Panel::AddPopup(int id, std::string name, std::function<bool(Panel*)> func)
{
auto iter = mPopups.find(id);
if (iter != mPopups.end())
{
return OpRes::Fail("A popup with id: %d alread exists. Existing name: %s, New Name: %s",
iter->first, iter->second->Name.c_str(), name.c_str());
}
mPopups[id] = new Popup { func, false, name };
return OpRes::OK();
}
void Panel::RunPopups()
{
for (auto iter = mPopups.begin(); iter != mPopups.end(); iter++)
{
Popup* ppu = iter->second;
if (ppu->IsOpen)
{
ppu->IsOpen = ppu->PopupFunc(this);
ImGui::OpenPopup(ppu->Name.c_str());
}
}
}
void Panel::UpdateMetaInfo()
{
ImVec2 p = ImGui::GetWindowPos();

@ -11,8 +11,11 @@
#include "panel_defs.h"
#include "panel_manager.h"
#include <utils/op_res.h>
#include <string>
#include <map>
#include <functional>
struct ImGuiInputTextCallbackData;
@ -21,30 +24,57 @@ namespace lunarium
class Panel
{
public:
Panel(std::string name, PanelDockZone dock_zone, bool isOpen = false);
struct Popup
{
std::function<bool(Panel*)> PopupFunc;
bool IsOpen;
std::string Name;
};
public:
Panel(std::string name, PanelDockZone dock_zone, bool isOpen = false, int window_flags = 0);
virtual ~Panel();
const char* GetName() const;
virtual void Update(float dt);
virtual bool DoFrame() = 0;
bool OnUIRender();
void SetWindowFlags(int flags);
void SetOpen(bool isOpen);
bool IsOpen();
void GetPosition(int& x, int& y) const;
void GetSize(int& w, int& h) const;
PanelDockZone GetDockZone() const;
protected:
OpRes AddPopup(int id, std::string name, std::function<bool(Panel*)>);
private:
std::string mPanelName;
bool mIsOpen;
PanelDockZone mDockZone;
int mWindowFlags;
// TODO: Not sure I like this solution...
int mNumPushedStyles;
// Popups
std::map<int, Popup*> mPopups;
int mX;
int mY;
int mWidth;
int mHeight;
protected:
private: // Helpers
void UpdateMetaInfo();
void RunPopups();
protected:
virtual void PreBegin();
virtual void DoFrame() = 0;
void SetNumPushedStyles(int num);
void OpenPopup(int id);
private:
friend class PanelManager;

@ -134,7 +134,7 @@ namespace lunarium
if ((*iter)->IsOpen())
{
ImGui::SetNextWindowClass(&mWindowClass);
(*iter)->DoFrame();
(*iter)->OnUIRender();
}
}
}

@ -16,27 +16,18 @@ namespace lunarium
namespace editor
{
AboutPanel::AboutPanel()
: Panel("About", PanelDockZone::DDZ_NONE)
: Panel("About", PanelDockZone::DDZ_NONE, false, (int)ImGuiWindowFlags_NoCollapse)
{
}
bool AboutPanel::DoFrame()
void AboutPanel::PreBegin()
{
if (!mIsOpen)
return false;
ImGui::SetNextWindowSize(ImVec2(300, ImGui::GetFrameHeight() * 20));
if (!ImGui::Begin(GetName(), &mIsOpen, ImGuiWindowFlags_NoCollapse ))
{
ImGui::End();
return false;
}
}
void AboutPanel::DoFrame()
{
ImGui::TextWrapped("Lunarium Editor Version %s - Written by Joey Pollack", Version::GetVersion().ToString().c_str());
ImGui::End();
return true;
}
}
}

@ -22,7 +22,8 @@ namespace editor
AboutPanel();
// Returns false if the window is closed
bool DoFrame();
void PreBegin();
void DoFrame();
};
}
}

@ -23,7 +23,7 @@ namespace lunarium
namespace editor
{
AssetBrowser::AssetBrowser(std::filesystem::path dir, Editor* pEditor)
: Panel("Asset Browser", PanelDockZone::DDZ_BOTTOM, true),
: Panel("Asset Browser", PanelDockZone::DDZ_BOTTOM, true, (ImGuiWindowFlags)ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar),
mAssetDirectory(dir), mpEditor(pEditor), mNewFolder(false), mSyncTree(false)
{
}
@ -39,18 +39,8 @@ namespace editor
return mSelectedDir;
}
bool AssetBrowser::DoFrame()
void AssetBrowser::DoFrame()
{
if (!mIsOpen)
return false;
if (!ImGui::Begin(GetName(), &mIsOpen, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar))
{
ImGui::End();
return false;
}
//DoNewFolder();
// Directory tree
// TODO: Figure out a better way to size stuff other
@ -74,9 +64,6 @@ namespace editor
DoContentArea(wind_size);
HandlePopupActions();
ImGui::End();
return true;
}
void AssetBrowser::DoDirTree(std::filesystem::path dir)
@ -233,6 +220,11 @@ namespace editor
}
void AssetBrowser::DefinePopups()
{
}
void AssetBrowser::DoNewFolder()
{
if (ImGui::BeginPopupContextItem("New Folder Name"))

@ -26,7 +26,7 @@ namespace editor
void SetAssetDirectory(std::filesystem::path dir);
bool DoFrame();
void DoFrame();
std::filesystem::path GetSelectedDirectory();
@ -46,6 +46,8 @@ namespace editor
bool mSyncTree;
private:
void DefinePopups();
void HandlePopupActions();
void HandleAssetDrop(std::filesystem::path dir);

@ -17,22 +17,14 @@
namespace lunarium { namespace editor
{
PropertiesView::PropertiesView()
: Panel("Properties", PanelDockZone::DDZ_RIGHT, true), mpSelectedAsset(nullptr), mpSelectedEntity(nullptr)
: Panel("Properties", PanelDockZone::DDZ_RIGHT, true, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar),
mpSelectedAsset(nullptr), mpSelectedEntity(nullptr)
{
}
bool PropertiesView::DoFrame()
void PropertiesView::DoFrame()
{
if (!mIsOpen)
return false;
if (!ImGui::Begin(GetName(), &mIsOpen, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar))
{
ImGui::End();
return false;
}
if (mpSelectedEntity)
{
// TODO: iterate through components
@ -42,8 +34,6 @@ namespace lunarium { namespace editor
}
}
ImGui::End();
return true;
}
void PropertiesView::SetSelection(Entity* pEntity)

@ -29,7 +29,7 @@ namespace editor
void SetSelection(Entity* pEntity);
void SetSelection(EditorAsset* pAsset);
bool DoFrame();
void DoFrame();
private:
std::vector<CustromProperty*> mCustomProps;

@ -20,7 +20,8 @@ namespace lunarium
namespace editor
{
WorldTree::WorldTree()
: Panel("World Tree", PanelDockZone::DDZ_LEFT, true), mpWorld(new lunarium::World), mDoNewEntity(false)
: Panel("World Tree", PanelDockZone::DDZ_LEFT, true, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar),
mpWorld(new lunarium::World), mDoNewEntity(false)
{
}
@ -35,17 +36,8 @@ namespace editor
return mpWorld;
}
bool WorldTree::DoFrame()
void WorldTree::DoFrame()
{
if (!mIsOpen)
return false;
if (!ImGui::Begin(GetName(), &mIsOpen, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar))
{
ImGui::End();
return false;
}
if (ImGui::TreeNode("World Root") && mpWorld)
{
// List all world entities
@ -74,8 +66,6 @@ namespace editor
DoContextMenu();
HandlePopupEvents();
ImGui::End();
return true;
}
void WorldTree::DoContextMenu()

@ -25,7 +25,7 @@ namespace editor
void SetWorld(lunarium::World* pWorld);
lunarium::World* GetWorld();
bool DoFrame();
void DoFrame();
private:
lunarium::World* mpWorld;

@ -13,29 +13,16 @@
#include <editor/editor.h>
#include <gui/panel_manager.h>
namespace lunarium
{
namespace editor
namespace lunarium { namespace editor
{
WorldView::WorldView()
: Panel("World View", PanelDockZone::DDZ_CENTER ,true), mpWorld(nullptr)
: Panel("World View", PanelDockZone::DDZ_CENTER, true, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar), mpWorld(nullptr)
{
}
bool WorldView::DoFrame()
void WorldView::DoFrame()
{
if (!mIsOpen)
return false;
if (!ImGui::Begin(GetName(), &mIsOpen, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar))
{
ImGui::End();
return false;
}
ImGui::End();
return true;
}
}
}
}}

@ -23,7 +23,7 @@ namespace editor
{
public:
WorldView();
bool DoFrame();
void DoFrame();
void SetWorld(World* pWorld);
World* GetWorld();

@ -21,7 +21,7 @@
namespace lunarium { namespace editor
{
MapCanvas::MapCanvas(MapEditor* editor)
: Panel("Map Canvas", PanelDockZone::DDZ_CENTER, true),
: Panel("Map Canvas", PanelDockZone::DDZ_CENTER, true, ImGuiWindowFlags_NoScrollbar),
mpMapEditor(editor), mpCanvasImage(nullptr), mMap(nullptr), mSelectedTile({-1, -1}), mFrameBuffer(-1), mMapSizeChanged(false),
mZoomFactor(1.0f), mScrollDragged(false), mCurrentRegion({0, 0}), mRegionString("")
{
@ -129,23 +129,17 @@ namespace lunarium { namespace editor
}
}
bool MapCanvas::DoFrame()
{
if (!mIsOpen)
return false;
void MapCanvas::PreBegin()
{
ImGui::PushStyleVar( ImGuiStyleVar_WindowRounding, 0.0f );
ImGui::PushStyleVar( ImGuiStyleVar_WindowBorderSize, 0.0f );
ImGui::PushStyleVar( ImGuiStyleVar_WindowPadding, ImVec2( 0.0f, 0.0f ) );
if (!ImGui::Begin(GetName(), &mIsOpen, ImGuiWindowFlags_NoScrollbar))
{
ImGui::PopStyleVar(3);
ImGui::End();
return false;
}
ImGui::PopStyleVar(3);
SetNumPushedStyles(3);
}
void MapCanvas::DoFrame()
{
ImVec2 pos = ImGui::GetWindowPos();
ImVec2 size = ImGui::GetWindowSize();
@ -189,8 +183,6 @@ namespace lunarium { namespace editor
}
ImGui::EndChild();
ImGui::End();
return mIsOpen;
}
void MapCanvas::SetTileMap(TileMap* pMap)

@ -25,7 +25,8 @@ namespace lunarium { namespace editor
public:
MapCanvas(MapEditor* editor);
void Update(float delta);
bool DoFrame();
void PreBegin();
void DoFrame();
void SetTileMap(TileMap* pMap);

@ -20,7 +20,7 @@
namespace lunarium { namespace editor
{
TileSetView::TileSetView(MapEditor* editor)
: Panel("Tile Set View", PanelDockZone::DDZ_RIGHT, true),
: Panel("Tile Set View", PanelDockZone::DDZ_RIGHT, true, ImGuiWindowFlags_HorizontalScrollbar),
mpEditor(editor), mpSelectedTileSet(nullptr), mpViewImage(nullptr), mFrameBuffer(-1),
mViewOffset({0, 0}), mViewZoom(1.0f), mMouseDown(false)
{
@ -97,22 +97,16 @@ namespace lunarium { namespace editor
}
}
bool TileSetView::DoFrame()
void TileSetView::PreBegin()
{
if (!mIsOpen)
return false;
ImGui::PushStyleVar( ImGuiStyleVar_WindowRounding, 0.0f );
ImGui::PushStyleVar( ImGuiStyleVar_WindowBorderSize, 0.0f );
ImGui::PushStyleVar( ImGuiStyleVar_WindowPadding, ImVec2( 0.0f, 0.0f ) );
if (!ImGui::Begin(GetName(), &mIsOpen, ImGuiWindowFlags_HorizontalScrollbar))
{
ImGui::PopStyleVar(3);
ImGui::End();
return false;
}
ImGui::PopStyleVar(3);
SetNumPushedStyles(3);
}
void TileSetView::DoFrame()
{
ImVec2 window_size = ImGui::GetWindowSize();
float child_height = ImGui::GetFrameHeight() * 2;
@ -159,9 +153,6 @@ namespace lunarium { namespace editor
ImGui::Image((ImTextureID)mpViewImage->GetGLTextureID64(),
ImVec2(mpViewImage->GetWidth(), mpViewImage->GetHeight()), ImVec2(0, 1), ImVec2(1, 0)); // the last 2 params are flipping the image on the y
}
ImGui::End();
return mIsOpen;
}
void TileSetView::ClearTileSets()

@ -26,7 +26,8 @@ namespace lunarium { namespace editor
TileSetView(MapEditor* editor);
void Update(float delta);
bool DoFrame();
void DoFrame();
void PreBegin();
void ClearTileSets();
void AddTileSet(TileSet* set);

Loading…
Cancel
Save