Better handling of the "p_opened" parameter in ImGui.Begin overloads.

* Previously, there would always be a "close window" button in the corner, because internally ImGui.cs was passing a non-null pointer to the underlying function. Now, it only does so if you call an overload with the "ref bool" parameter.
internals
Eric Mellino 7 years ago
parent f66223e5ca
commit 1f35b5ae9b
  1. 33
      src/ImGui.NET/ImGui.cs
  2. 4
      src/ImGui.NET/ImGuiNative.cs

@ -520,30 +520,41 @@ namespace ImGuiNET
public static bool BeginWindow(string windowTitle) => BeginWindow(windowTitle, WindowFlags.Default);
public static bool BeginWindow(string windowTitle, WindowFlags flags)
public static unsafe bool BeginWindow(string windowTitle, WindowFlags flags)
{
bool opened = true;
return ImGuiNative.igBegin(windowTitle, ref opened, flags);
return ImGuiNative.igBegin(windowTitle, null, flags);
}
public static bool BeginWindow(string windowTitle, ref bool opened, WindowFlags flags)
public static unsafe bool BeginWindow(string windowTitle, ref bool opened, WindowFlags flags)
{
return ImGuiNative.igBegin(windowTitle, ref opened, flags);
byte openedLocal = opened ? (byte)1 : (byte)0;
bool ret = ImGuiNative.igBegin(windowTitle, &openedLocal, flags);
opened = openedLocal != 0;
return ret;
}
public static bool BeginWindow(string windowTitle, ref bool opened, float backgroundAlpha, WindowFlags flags)
public static unsafe bool BeginWindow(string windowTitle, ref bool opened, float backgroundAlpha, WindowFlags flags)
{
return ImGuiNative.igBegin2(windowTitle, ref opened, new Vector2(), backgroundAlpha, flags);
byte openedLocal = opened ? (byte)1 : (byte)0;
bool ret = ImGuiNative.igBegin2(windowTitle, &openedLocal, new Vector2(), backgroundAlpha, flags);
opened = openedLocal != 0;
return ret;
}
public static bool BeginWindow(string windowTitle, ref bool opened, Vector2 startingSize, WindowFlags flags)
public static unsafe bool BeginWindow(string windowTitle, ref bool opened, Vector2 startingSize, WindowFlags flags)
{
return ImGuiNative.igBegin2(windowTitle, ref opened, startingSize, 1f, flags);
byte openedLocal = opened ? (byte)1 : (byte)0;
bool ret = ImGuiNative.igBegin2(windowTitle, &openedLocal, startingSize, 1f, flags);
opened = openedLocal != 0;
return ret;
}
public static bool BeginWindow(string windowTitle, ref bool opened, Vector2 startingSize, float backgroundAlpha, WindowFlags flags)
public static unsafe bool BeginWindow(string windowTitle, ref bool opened, Vector2 startingSize, float backgroundAlpha, WindowFlags flags)
{
return ImGuiNative.igBegin2(windowTitle, ref opened, startingSize, backgroundAlpha, flags);
byte openedLocal = opened ? (byte)1 : (byte)0;
bool ret = ImGuiNative.igBegin2(windowTitle, &openedLocal, startingSize, backgroundAlpha, flags);
opened = openedLocal != 0;
return ret;
}
public static bool BeginMenu(string label)

@ -47,10 +47,10 @@ namespace ImGuiNET
// Window
[DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool igBegin(string name, ref bool p_opened, WindowFlags flags);
public static extern bool igBegin(string name, byte* p_opened, WindowFlags flags);
[DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool igBegin2(string name, ref bool p_opened, Vector2 size_on_first_use, float bg_alpha, WindowFlags flags);
public static extern bool igBegin2(string name, byte* p_opened, Vector2 size_on_first_use, float bg_alpha, WindowFlags flags);
[DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)]
public static extern void igEnd();
[DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)]

Loading…
Cancel
Save