ImGui.NET icon indicating copy to clipboard operation
ImGui.NET copied to clipboard

Rename / deactivate imgui.ini

Open shihan42 opened this issue 6 years ago • 3 comments

Expected Behavior

It should be possible to rename the file imgui.ini or deactivate it completely. Native ImGui supports changing the global IniFilename.

Current Behavior

Name can't be changed / generation can't be deactivated, since IniFilename only has a getter, no setter.

Possible Solution

  1. Enable ImGui.GetIO().IniFilename = null; or ImGui.GetIO().IniFilename = "my_config.ini"; or
  2. Expose it through another way

shihan42 avatar Nov 14 '19 13:11 shihan42

I believe you can set it as ImGui.GetIO().NativePtr->IniFilename = "my_config.ini" Haven't tested it though

bootzin avatar Nov 14 '19 14:11 bootzin

Thank you for the suggestion. It works with both renaming and deactivating, but only inside an unsafe context. It is ok, but could be better.

shihan42 avatar Nov 14 '19 15:11 shihan42

I just had the same problem as I'm coding with VB.NET which does not support unsafe context. I solved it with the following work around:

        Dim IO = ImGuiNET.ImGui.GetIO()
        Dim nativePtr = IO.GetType().GetProperty("NativePtr").GetValue(IO)
        Dim getPointerValue = nativePtr.GetType().GetMethod("GetPointerValue", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance)
        Dim ptr = CType(getPointerValue.Invoke(nativePtr, Nothing), IntPtr)
        Dim offset = Runtime.InteropServices.Marshal.OffsetOf(GetType(ImGuiNET.ImGuiIO), "IniFilename")

        Runtime.InteropServices.Marshal.WriteIntPtr(ptr + offset.ToInt32(), IntPtr.Zero)
     

Moe2912 avatar Jan 27 '23 20:01 Moe2912