2
0
Эх сурвалжийг харах

Examples: Android: Using LoadIniSettingsFromMemory() / SaveIniSettingsToMemory() to save in appropriate location for Android. (#5836)

Rewtio 2 жил өмнө
parent
commit
c2694ef75e

+ 1 - 0
docs/CHANGELOG.txt

@@ -181,6 +181,7 @@ Other Changes:
 - Demo: Fixed Log & Console from losing scrolling position with Auto-Scroll when child is clipped. (#5721)
 - Examples: Added all SDL examples to default VS solution.
 - Examples: Win32: Always use RegisterClassW() to ensure windows are Unicode. (#5725)
+- Examples: Android: Enable .ini file loading/saving into application internal data folder. (#5836) [@rewtio]
 - Backends: GLFW: Honor GLFW_CURSOR_DISABLED by not setting mouse position. (#5625) [@scorpion-26]
 - Backends: GLFW: Add glfwGetError() call on GLFW 3.3 to inhibit missing mouse cursor errors. (#5785) [@mitchellh]
 - Backends: SDL: Disable SDL 2.0.22 new "auto capture" which prevents drag and drop across windows

+ 6 - 3
examples/example_android_opengl3/main.cpp

@@ -9,6 +9,7 @@
 #include <android/asset_manager.h>
 #include <EGL/egl.h>
 #include <GLES3/gl3.h>
+#include <string>
 
 // Data
 static EGLDisplay           g_EglDisplay = EGL_NO_DISPLAY;
@@ -17,6 +18,7 @@ static EGLContext           g_EglContext = EGL_NO_CONTEXT;
 static struct android_app*  g_App = NULL;
 static bool                 g_Initialized = false;
 static char                 g_LogTag[] = "ImGuiExample";
+static std::string          g_IniFilename = "";
 
 // Forward declarations of helper functions
 static int ShowSoftKeyboardInput();
@@ -70,9 +72,10 @@ void init(struct android_app* app)
     ImGui::CreateContext();
     ImGuiIO& io = ImGui::GetIO();
 
-    // Disable loading/saving of .ini file from disk.
-    // FIXME: Consider using LoadIniSettingsFromMemory() / SaveIniSettingsToMemory() to save in appropriate location for Android.
-    io.IniFilename = NULL;
+    // Redirect loading/saving of .ini file to our location.
+    // Make sure 'g_IniFilename' persists while we use Dear ImGui.
+    g_IniFilename = std::string(app->activity->internalDataPath) + "/imgui.ini";
+    io.IniFilename = g_IniFilename.c_str();;
 
     // Setup Dear ImGui style
     ImGui::StyleColorsDark();