-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PersistentTreeNode/CollapsedHeader saving the "open" state in imgui.ini
- Loading branch information
Showing
10 changed files
with
218 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
|
||
#include "core/Singleton/Singleton.h" | ||
|
||
namespace vg::renderer | ||
{ | ||
class ImGuiSettings : public core::Singleton<ImGuiSettings> | ||
{ | ||
public: | ||
void init(); | ||
|
||
CustomImGuiData & getCustomData(const core::string & _name); | ||
|
||
private: | ||
static void * onReadOpen(ImGuiContext * _imGuiContext, ImGuiSettingsHandler * _imGuiSettingsHandler, const char * _name); | ||
static void onReadLine(ImGuiContext * _imGuiContext, ImGuiSettingsHandler * _imGuiSettingsHandler, void * _entry, const char * _line); | ||
static void onWriteAll(ImGuiContext * _imGuiContext, ImGuiSettingsHandler * _imGuiSettingsHandler, ImGuiTextBuffer * _outputTextBuffer); | ||
|
||
private: | ||
core::map<core::string, CustomImGuiData> m_customImGuiData; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include "ImGuiSettings.h" | ||
|
||
namespace vg::renderer | ||
{ | ||
//-------------------------------------------------------------------------------------- | ||
void ImGuiSettings::init() | ||
{ | ||
ImGuiSettingsHandler ini_handler; | ||
ini_handler.TypeName = "VimontGames"; | ||
ini_handler.TypeHash = ImHashStr("VimontGames"); | ||
ini_handler.ReadOpenFn = onReadOpen; | ||
ini_handler.ReadLineFn = onReadLine; | ||
ini_handler.WriteAllFn = onWriteAll; | ||
ImGui::GetCurrentContext()->SettingsHandlers.push_back(ini_handler); | ||
|
||
ImGui::LoadIniSettingsFromDisk(ImGui::GetIO().IniFilename); | ||
} | ||
|
||
//-------------------------------------------------------------------------------------- | ||
void * ImGuiSettings::onReadOpen(ImGuiContext * _imGuiContext, ImGuiSettingsHandler * _imGuiSettingsHandler, const char * _name) | ||
{ | ||
auto & customState = ImGuiSettings::get()->m_customImGuiData; | ||
customState[_name] = CustomImGuiData(); | ||
return &customState[_name]; | ||
} | ||
|
||
//-------------------------------------------------------------------------------------- | ||
void ImGuiSettings::onReadLine(ImGuiContext * _imGuiContext, ImGuiSettingsHandler * _imGuiSettingsHandler, void * _entry, const char * _line) | ||
{ | ||
CustomImGuiData * data = (CustomImGuiData *)_entry; | ||
int isOpen; | ||
if (sscanf(_line, "Open=%d", &isOpen) == 1) | ||
data->isOpen = (isOpen != 0); | ||
} | ||
|
||
//-------------------------------------------------------------------------------------- | ||
// Function to write data to `imgui.ini` | ||
//-------------------------------------------------------------------------------------- | ||
void ImGuiSettings::onWriteAll(ImGuiContext * _imGuiContext, ImGuiSettingsHandler * _imGuiSettingsHandler, ImGuiTextBuffer * _outputTextBuffer) | ||
{ | ||
const auto & customState = ImGuiSettings::get()->m_customImGuiData; | ||
for (const auto & pair : customState) | ||
{ | ||
_outputTextBuffer->appendf("[%s][%s]\n", _imGuiSettingsHandler->TypeName, pair.first.c_str()); | ||
_outputTextBuffer->appendf("Open=%d\n", pair.second.isOpen ? 1 : 0); | ||
} | ||
} | ||
|
||
//-------------------------------------------------------------------------------------- | ||
CustomImGuiData & ImGuiSettings::getCustomData(const core::string & _name) | ||
{ | ||
return m_customImGuiData[_name]; | ||
} | ||
} |
Oops, something went wrong.