[wpigui] Add hooks for custom load/save settings

Add GetPlatformSaveFileDir().
This commit is contained in:
Peter Johnson
2021-11-07 23:21:18 -08:00
parent f6e9fc7d71
commit 141354cd79
3 changed files with 88 additions and 10 deletions

View File

@@ -79,6 +79,36 @@ void AddEarlyExecute(std::function<void()> execute);
*/
void AddLateExecute(std::function<void()> execute);
/**
* Customizes save/load behavior.
*
* By default, the integrated ImGui functions are used for this;
* ImGui::LoadIniSettingsFromDisk(io.IniFilename) is called at startup, and
* ImGui default automatic save file handling is used via io.IniFilename.
*
* Calling this function results in the load function being called at startup,
* io.IniFilename set to null (which disables ImGui's integrated file saving),
* and the save function being called when io.WantSaveIniSettings is true.
* The loadIni function should call ImGui::LoadIniSettingsFromMemory() to load
* ImGui save data, and the save function should call
* ImGui::SaveIniSettingsToMemory() to get ImGui save data.
*
* The load function is called PRIOR to AddInit() functions, and the loadIni
* function is called AFTER to AddInit() functions. This allows initialize
* functions that use custom storage to handle the loaded values, and initialize
* functions that use INI storage to add hooks prior to the load INI occurring.
*
* This must be called prior to Initialize().
*
* @param load load function
* @param loadIni load INI function
* @param save save function; false is passed periodically, true is passed once
* when the main loop is exiting
*/
void ConfigureCustomSaveSettings(std::function<void()> load,
std::function<void()> loadIni,
std::function<void(bool exiting)> save);
/**
* Gets GLFW window handle.
*/
@@ -137,6 +167,14 @@ void SetStyle(Style style);
*/
void SetClearColor(ImVec4 color);
/**
* Gets the (platform-specific) absolute directory for save files.
*
* @return Absolute path, including trailing "/". Empty string if directory
* could not be determined.
*/
std::string GetPlatformSaveFileDir();
/**
* Configures a save file (.ini) in a platform specific location. On Windows,
* the .ini is saved in %APPDATA%; on macOS the .ini is saved in

View File

@@ -40,6 +40,9 @@ struct Context : public SavedSettings {
GLFWwindow* window = nullptr;
std::function<void()> loadSettings;
std::function<void()> loadIniSettings;
std::function<void(bool exiting)> saveSettings;
std::vector<std::function<void()>> initializers;
std::vector<std::function<void(float scale)>> windowScalers;
std::vector<std::pair<