Skip to content

Commit

Permalink
Added custom overload for BeginPopupModal without p_open parameter (#476
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Veslo5 committed May 16, 2024
1 parent b208052 commit 568c911
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/ImGui.NET/ImGui.Manual.ReadOnlySpan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,36 @@ public static bool Begin(ReadOnlySpan<char> name, ImGuiWindowFlags flags)
public static bool MenuItem(ReadOnlySpan<char> label, bool enabled)
{
return MenuItem(label, string.Empty, false, enabled);
}

public static bool BeginPopupModal(ReadOnlySpan<char> name, ImGuiWindowFlags flags)
{
byte* native_name;
int name_byteCount = 0;
if (name != null)
{
name_byteCount = Encoding.UTF8.GetByteCount(name);
if (name_byteCount > Util.StackAllocationSizeLimit)
{
native_name = Util.Allocate(name_byteCount + 1);
}
else
{
byte* native_name_stackBytes = stackalloc byte[name_byteCount + 1];
native_name = native_name_stackBytes;
}
int native_name_offset = Util.GetUtf8(name, native_name, name_byteCount);
native_name[native_name_offset] = 0;
}
else { native_name = null; }
byte* native_p_open = null;
byte ret = ImGuiNative.igBeginPopupModal(native_name, native_p_open, flags);
if (name_byteCount > Util.StackAllocationSizeLimit)
{
Util.Free(native_name);
}

return ret != 0;
}
}
}
Expand Down
32 changes: 31 additions & 1 deletion src/ImGui.NET/ImGui.Manual.cs
Original file line number Diff line number Diff line change
Expand Up @@ -471,11 +471,41 @@ public static bool Begin(string name, ImGuiWindowFlags flags)
}

return ret != 0;
}
}

public static bool MenuItem(string label, bool enabled)
{
return MenuItem(label, string.Empty, false, enabled);
}

public static bool BeginPopupModal(string name, ImGuiWindowFlags flags)
{
byte* native_name;
int name_byteCount = 0;
if (name != null)
{
name_byteCount = Encoding.UTF8.GetByteCount(name);
if (name_byteCount > Util.StackAllocationSizeLimit)
{
native_name = Util.Allocate(name_byteCount + 1);
}
else
{
byte* native_name_stackBytes = stackalloc byte[name_byteCount + 1];
native_name = native_name_stackBytes;
}
int native_name_offset = Util.GetUtf8(name, native_name, name_byteCount);
native_name[native_name_offset] = 0;
}
else { native_name = null; }
byte* native_p_open = null;
byte ret = ImGuiNative.igBeginPopupModal(native_name, native_p_open, flags);
if (name_byteCount > Util.StackAllocationSizeLimit)
{
Util.Free(native_name);
}

return ret != 0;
}
}
}

0 comments on commit 568c911

Please sign in to comment.