mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpigui] Add platform-specific preferences save
This commit is contained in:
committed by
Peter Johnson
parent
751dea32ae
commit
2c5668af46
@@ -140,6 +140,8 @@ bool gui::Initialize(const char* title, int width, int height) {
|
||||
iniHandler.WriteAllFn = IniWriteAll;
|
||||
ImGui::GetCurrentContext()->SettingsHandlers.push_back(iniHandler);
|
||||
|
||||
io.IniFilename = gContext->iniPath.c_str();
|
||||
|
||||
for (auto&& initialize : gContext->initializers) {
|
||||
if (initialize) initialize();
|
||||
}
|
||||
@@ -331,6 +333,25 @@ void gui::SetStyle(Style style) {
|
||||
|
||||
void gui::SetClearColor(ImVec4 color) { gContext->clearColor = color; }
|
||||
|
||||
void gui::ConfigurePlatformSaveFile(const std::string& name) {
|
||||
gContext->iniPath = name;
|
||||
#if defined(_MSC_VER)
|
||||
const char* env = std::getenv("APPDATA");
|
||||
if (env) gContext->iniPath = env + std::string("/" + name);
|
||||
#elif defined(__APPLE__)
|
||||
const char* env = std::getenv("HOME");
|
||||
if (env)
|
||||
gContext->iniPath = env + std::string("/Library/Preferences/" + name);
|
||||
#else
|
||||
const char* xdg = std::getenv("XDG_CONFIG_HOME");
|
||||
const char* env = std::getenv("HOME");
|
||||
if (xdg)
|
||||
gContext->iniPath = xdg + std::string("/" + name);
|
||||
else if (env)
|
||||
gContext->iniPath = env + std::string("/.config/" + name);
|
||||
#endif
|
||||
}
|
||||
|
||||
void gui::EmitViewMenu() {
|
||||
if (ImGui::BeginMenu("View")) {
|
||||
if (ImGui::BeginMenu("Style")) {
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
@@ -123,6 +124,15 @@ void SetStyle(Style style);
|
||||
*/
|
||||
void SetClearColor(ImVec4 color);
|
||||
|
||||
/**
|
||||
* 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
|
||||
* ~/Library/Preferences; on Linux the .ini is stored in $XDG_CONFIG_HOME or
|
||||
* ~/.config if the former is not defined. This must be called before
|
||||
* gui::Initialize().
|
||||
*/
|
||||
void ConfigurePlatformSaveFile(const std::string& name);
|
||||
|
||||
/**
|
||||
* Emits a View menu (e.g. for a main menu bar) that allows setting of
|
||||
* style and zoom. Internally starts with ImGui::BeginMenu("View").
|
||||
|
||||
@@ -56,6 +56,8 @@ struct Context : public SavedSettings {
|
||||
|
||||
int fontScale = 2; // updated by main loop
|
||||
std::vector<Font> fonts;
|
||||
|
||||
std::string iniPath = "imgui.ini";
|
||||
};
|
||||
|
||||
extern Context* gContext;
|
||||
|
||||
Reference in New Issue
Block a user