Skip to content

Commit 568c911

Browse files
authored
Added custom overload for BeginPopupModal without p_open parameter (#476)
1 parent b208052 commit 568c911

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

src/ImGui.NET/ImGui.Manual.ReadOnlySpan.cs

+30
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,36 @@ public static bool Begin(ReadOnlySpan<char> name, ImGuiWindowFlags flags)
479479
public static bool MenuItem(ReadOnlySpan<char> label, bool enabled)
480480
{
481481
return MenuItem(label, string.Empty, false, enabled);
482+
}
483+
484+
public static bool BeginPopupModal(ReadOnlySpan<char> name, ImGuiWindowFlags flags)
485+
{
486+
byte* native_name;
487+
int name_byteCount = 0;
488+
if (name != null)
489+
{
490+
name_byteCount = Encoding.UTF8.GetByteCount(name);
491+
if (name_byteCount > Util.StackAllocationSizeLimit)
492+
{
493+
native_name = Util.Allocate(name_byteCount + 1);
494+
}
495+
else
496+
{
497+
byte* native_name_stackBytes = stackalloc byte[name_byteCount + 1];
498+
native_name = native_name_stackBytes;
499+
}
500+
int native_name_offset = Util.GetUtf8(name, native_name, name_byteCount);
501+
native_name[native_name_offset] = 0;
502+
}
503+
else { native_name = null; }
504+
byte* native_p_open = null;
505+
byte ret = ImGuiNative.igBeginPopupModal(native_name, native_p_open, flags);
506+
if (name_byteCount > Util.StackAllocationSizeLimit)
507+
{
508+
Util.Free(native_name);
509+
}
510+
511+
return ret != 0;
482512
}
483513
}
484514
}

src/ImGui.NET/ImGui.Manual.cs

+31-1
Original file line numberDiff line numberDiff line change
@@ -471,11 +471,41 @@ public static bool Begin(string name, ImGuiWindowFlags flags)
471471
}
472472

473473
return ret != 0;
474-
}
474+
}
475475

476476
public static bool MenuItem(string label, bool enabled)
477477
{
478478
return MenuItem(label, string.Empty, false, enabled);
479+
}
480+
481+
public static bool BeginPopupModal(string name, ImGuiWindowFlags flags)
482+
{
483+
byte* native_name;
484+
int name_byteCount = 0;
485+
if (name != null)
486+
{
487+
name_byteCount = Encoding.UTF8.GetByteCount(name);
488+
if (name_byteCount > Util.StackAllocationSizeLimit)
489+
{
490+
native_name = Util.Allocate(name_byteCount + 1);
491+
}
492+
else
493+
{
494+
byte* native_name_stackBytes = stackalloc byte[name_byteCount + 1];
495+
native_name = native_name_stackBytes;
496+
}
497+
int native_name_offset = Util.GetUtf8(name, native_name, name_byteCount);
498+
native_name[native_name_offset] = 0;
499+
}
500+
else { native_name = null; }
501+
byte* native_p_open = null;
502+
byte ret = ImGuiNative.igBeginPopupModal(native_name, native_p_open, flags);
503+
if (name_byteCount > Util.StackAllocationSizeLimit)
504+
{
505+
Util.Free(native_name);
506+
}
507+
508+
return ret != 0;
479509
}
480510
}
481511
}

0 commit comments

Comments
 (0)