Allow "null" to be passed for string parameters.

NOTE: Not all native functions permit a null string to be passed, and may still fail. This change just fixes the null-ref that occurred wheen attempting to marshal the null string to UTF8.

Bumps beta identifier to beta3.
internals
Eric Mellino 6 years ago
parent 9212f835fa
commit 57de7ca047
  1. 16
      src/CodeGenerator/Program.cs
  2. 16
      src/ImGui.NET/Generated/GlyphRangesBuilder.gen.cs
  3. 96
      src/ImGui.NET/Generated/ImFontAtlas.gen.cs
  4. 6736
      src/ImGui.NET/Generated/ImGui.gen.cs
  5. 16
      src/ImGui.NET/Generated/ImGuiIO.gen.cs
  6. 16
      src/ImGui.NET/Generated/ImGuiInputTextCallbackData.gen.cs
  7. 16
      src/ImGui.NET/Generated/ImGuiPayload.gen.cs
  8. 16
      src/ImGui.NET/Generated/ImGuiTextBuffer.gen.cs
  9. 64
      src/ImGui.NET/Generated/ImGuiTextFilter.gen.cs
  10. 2
      src/ImGui.NET/ImGui.NET.csproj

@ -623,13 +623,19 @@ namespace CodeGenerator
} }
else else
{ {
preCallLines.Add($"int {correctedIdentifier}_byteCount = Encoding.UTF8.GetByteCount({textToEncode});"); preCallLines.Add($"byte* {nativeArgName};");
preCallLines.Add($"byte* {nativeArgName} = stackalloc byte[{correctedIdentifier}_byteCount + 1];"); preCallLines.Add($"if ({textToEncode} != null)");
preCallLines.Add($"fixed (char* {correctedIdentifier}_ptr = {textToEncode})");
preCallLines.Add("{"); preCallLines.Add("{");
preCallLines.Add($" int {nativeArgName}_offset = Encoding.UTF8.GetBytes({correctedIdentifier}_ptr, {textToEncode}.Length, {nativeArgName}, {correctedIdentifier}_byteCount);"); preCallLines.Add($" int {correctedIdentifier}_byteCount = Encoding.UTF8.GetByteCount({textToEncode});");
preCallLines.Add($" {nativeArgName}[{nativeArgName}_offset] = 0;"); preCallLines.Add($" byte* {nativeArgName}_stackBytes = stackalloc byte[{correctedIdentifier}_byteCount + 1];");
preCallLines.Add($" {nativeArgName} = {nativeArgName}_stackBytes;");
preCallLines.Add($" fixed (char* {correctedIdentifier}_ptr = {textToEncode})");
preCallLines.Add(" {");
preCallLines.Add($" int {nativeArgName}_offset = Encoding.UTF8.GetBytes({correctedIdentifier}_ptr, {textToEncode}.Length, {nativeArgName}, {correctedIdentifier}_byteCount);");
preCallLines.Add($" {nativeArgName}[{nativeArgName}_offset] = 0;");
preCallLines.Add(" }");
preCallLines.Add("}"); preCallLines.Add("}");
preCallLines.Add($"else {{ {nativeArgName} = null; }}");
} }
} }
else if (tr.Type == "char* []") else if (tr.Type == "char* []")

@ -24,13 +24,19 @@ namespace ImGuiNET
} }
public void AddText(string text) public void AddText(string text)
{ {
int text_byteCount = Encoding.UTF8.GetByteCount(text); byte* native_text;
byte* native_text = stackalloc byte[text_byteCount + 1]; if (text != null)
fixed (char* text_ptr = text)
{ {
int native_text_offset = Encoding.UTF8.GetBytes(text_ptr, text.Length, native_text, text_byteCount); int text_byteCount = Encoding.UTF8.GetByteCount(text);
native_text[native_text_offset] = 0; byte* native_text_stackBytes = stackalloc byte[text_byteCount + 1];
native_text = native_text_stackBytes;
fixed (char* text_ptr = text)
{
int native_text_offset = Encoding.UTF8.GetBytes(text_ptr, text.Length, native_text, text_byteCount);
native_text[native_text_offset] = 0;
}
} }
else { native_text = null; }
byte* native_text_end = null; byte* native_text_end = null;
ImGuiNative.GlyphRangesBuilder_AddText(NativePtr, native_text, native_text_end); ImGuiNative.GlyphRangesBuilder_AddText(NativePtr, native_text, native_text_end);
} }

@ -48,13 +48,19 @@ namespace ImGuiNET
public RangeAccessor<int> CustomRectIds => new RangeAccessor<int>(NativePtr->CustomRectIds, 1); public RangeAccessor<int> CustomRectIds => new RangeAccessor<int>(NativePtr->CustomRectIds, 1);
public ImFontPtr AddFontFromMemoryCompressedBase85TTF(string compressed_font_data_base85, float size_pixels) public ImFontPtr AddFontFromMemoryCompressedBase85TTF(string compressed_font_data_base85, float size_pixels)
{ {
int compressed_font_data_base85_byteCount = Encoding.UTF8.GetByteCount(compressed_font_data_base85); byte* native_compressed_font_data_base85;
byte* native_compressed_font_data_base85 = stackalloc byte[compressed_font_data_base85_byteCount + 1]; if (compressed_font_data_base85 != null)
fixed (char* compressed_font_data_base85_ptr = compressed_font_data_base85)
{ {
int native_compressed_font_data_base85_offset = Encoding.UTF8.GetBytes(compressed_font_data_base85_ptr, compressed_font_data_base85.Length, native_compressed_font_data_base85, compressed_font_data_base85_byteCount); int compressed_font_data_base85_byteCount = Encoding.UTF8.GetByteCount(compressed_font_data_base85);
native_compressed_font_data_base85[native_compressed_font_data_base85_offset] = 0; byte* native_compressed_font_data_base85_stackBytes = stackalloc byte[compressed_font_data_base85_byteCount + 1];
native_compressed_font_data_base85 = native_compressed_font_data_base85_stackBytes;
fixed (char* compressed_font_data_base85_ptr = compressed_font_data_base85)
{
int native_compressed_font_data_base85_offset = Encoding.UTF8.GetBytes(compressed_font_data_base85_ptr, compressed_font_data_base85.Length, native_compressed_font_data_base85, compressed_font_data_base85_byteCount);
native_compressed_font_data_base85[native_compressed_font_data_base85_offset] = 0;
}
} }
else { native_compressed_font_data_base85 = null; }
ImFontConfig* font_cfg = null; ImFontConfig* font_cfg = null;
ushort* glyph_ranges = null; ushort* glyph_ranges = null;
ImFont* ret = ImGuiNative.ImFontAtlas_AddFontFromMemoryCompressedBase85TTF(NativePtr, native_compressed_font_data_base85, size_pixels, font_cfg, glyph_ranges); ImFont* ret = ImGuiNative.ImFontAtlas_AddFontFromMemoryCompressedBase85TTF(NativePtr, native_compressed_font_data_base85, size_pixels, font_cfg, glyph_ranges);
@ -62,13 +68,19 @@ namespace ImGuiNET
} }
public ImFontPtr AddFontFromMemoryCompressedBase85TTF(string compressed_font_data_base85, float size_pixels, ImFontConfigPtr font_cfg) public ImFontPtr AddFontFromMemoryCompressedBase85TTF(string compressed_font_data_base85, float size_pixels, ImFontConfigPtr font_cfg)
{ {
int compressed_font_data_base85_byteCount = Encoding.UTF8.GetByteCount(compressed_font_data_base85); byte* native_compressed_font_data_base85;
byte* native_compressed_font_data_base85 = stackalloc byte[compressed_font_data_base85_byteCount + 1]; if (compressed_font_data_base85 != null)
fixed (char* compressed_font_data_base85_ptr = compressed_font_data_base85)
{ {
int native_compressed_font_data_base85_offset = Encoding.UTF8.GetBytes(compressed_font_data_base85_ptr, compressed_font_data_base85.Length, native_compressed_font_data_base85, compressed_font_data_base85_byteCount); int compressed_font_data_base85_byteCount = Encoding.UTF8.GetByteCount(compressed_font_data_base85);
native_compressed_font_data_base85[native_compressed_font_data_base85_offset] = 0; byte* native_compressed_font_data_base85_stackBytes = stackalloc byte[compressed_font_data_base85_byteCount + 1];
native_compressed_font_data_base85 = native_compressed_font_data_base85_stackBytes;
fixed (char* compressed_font_data_base85_ptr = compressed_font_data_base85)
{
int native_compressed_font_data_base85_offset = Encoding.UTF8.GetBytes(compressed_font_data_base85_ptr, compressed_font_data_base85.Length, native_compressed_font_data_base85, compressed_font_data_base85_byteCount);
native_compressed_font_data_base85[native_compressed_font_data_base85_offset] = 0;
}
} }
else { native_compressed_font_data_base85 = null; }
ImFontConfig* native_font_cfg = font_cfg.NativePtr; ImFontConfig* native_font_cfg = font_cfg.NativePtr;
ushort* glyph_ranges = null; ushort* glyph_ranges = null;
ImFont* ret = ImGuiNative.ImFontAtlas_AddFontFromMemoryCompressedBase85TTF(NativePtr, native_compressed_font_data_base85, size_pixels, native_font_cfg, glyph_ranges); ImFont* ret = ImGuiNative.ImFontAtlas_AddFontFromMemoryCompressedBase85TTF(NativePtr, native_compressed_font_data_base85, size_pixels, native_font_cfg, glyph_ranges);
@ -76,13 +88,19 @@ namespace ImGuiNET
} }
public ImFontPtr AddFontFromMemoryCompressedBase85TTF(string compressed_font_data_base85, float size_pixels, ImFontConfigPtr font_cfg, IntPtr glyph_ranges) public ImFontPtr AddFontFromMemoryCompressedBase85TTF(string compressed_font_data_base85, float size_pixels, ImFontConfigPtr font_cfg, IntPtr glyph_ranges)
{ {
int compressed_font_data_base85_byteCount = Encoding.UTF8.GetByteCount(compressed_font_data_base85); byte* native_compressed_font_data_base85;
byte* native_compressed_font_data_base85 = stackalloc byte[compressed_font_data_base85_byteCount + 1]; if (compressed_font_data_base85 != null)
fixed (char* compressed_font_data_base85_ptr = compressed_font_data_base85)
{ {
int native_compressed_font_data_base85_offset = Encoding.UTF8.GetBytes(compressed_font_data_base85_ptr, compressed_font_data_base85.Length, native_compressed_font_data_base85, compressed_font_data_base85_byteCount); int compressed_font_data_base85_byteCount = Encoding.UTF8.GetByteCount(compressed_font_data_base85);
native_compressed_font_data_base85[native_compressed_font_data_base85_offset] = 0; byte* native_compressed_font_data_base85_stackBytes = stackalloc byte[compressed_font_data_base85_byteCount + 1];
native_compressed_font_data_base85 = native_compressed_font_data_base85_stackBytes;
fixed (char* compressed_font_data_base85_ptr = compressed_font_data_base85)
{
int native_compressed_font_data_base85_offset = Encoding.UTF8.GetBytes(compressed_font_data_base85_ptr, compressed_font_data_base85.Length, native_compressed_font_data_base85, compressed_font_data_base85_byteCount);
native_compressed_font_data_base85[native_compressed_font_data_base85_offset] = 0;
}
} }
else { native_compressed_font_data_base85 = null; }
ImFontConfig* native_font_cfg = font_cfg.NativePtr; ImFontConfig* native_font_cfg = font_cfg.NativePtr;
ushort* native_glyph_ranges = (ushort*)glyph_ranges.ToPointer(); ushort* native_glyph_ranges = (ushort*)glyph_ranges.ToPointer();
ImFont* ret = ImGuiNative.ImFontAtlas_AddFontFromMemoryCompressedBase85TTF(NativePtr, native_compressed_font_data_base85, size_pixels, native_font_cfg, native_glyph_ranges); ImFont* ret = ImGuiNative.ImFontAtlas_AddFontFromMemoryCompressedBase85TTF(NativePtr, native_compressed_font_data_base85, size_pixels, native_font_cfg, native_glyph_ranges);
@ -218,13 +236,19 @@ namespace ImGuiNET
} }
public ImFontPtr AddFontFromFileTTF(string filename, float size_pixels) public ImFontPtr AddFontFromFileTTF(string filename, float size_pixels)
{ {
int filename_byteCount = Encoding.UTF8.GetByteCount(filename); byte* native_filename;
byte* native_filename = stackalloc byte[filename_byteCount + 1]; if (filename != null)
fixed (char* filename_ptr = filename)
{ {
int native_filename_offset = Encoding.UTF8.GetBytes(filename_ptr, filename.Length, native_filename, filename_byteCount); int filename_byteCount = Encoding.UTF8.GetByteCount(filename);
native_filename[native_filename_offset] = 0; byte* native_filename_stackBytes = stackalloc byte[filename_byteCount + 1];
native_filename = native_filename_stackBytes;
fixed (char* filename_ptr = filename)
{
int native_filename_offset = Encoding.UTF8.GetBytes(filename_ptr, filename.Length, native_filename, filename_byteCount);
native_filename[native_filename_offset] = 0;
}
} }
else { native_filename = null; }
ImFontConfig* font_cfg = null; ImFontConfig* font_cfg = null;
ushort* glyph_ranges = null; ushort* glyph_ranges = null;
ImFont* ret = ImGuiNative.ImFontAtlas_AddFontFromFileTTF(NativePtr, native_filename, size_pixels, font_cfg, glyph_ranges); ImFont* ret = ImGuiNative.ImFontAtlas_AddFontFromFileTTF(NativePtr, native_filename, size_pixels, font_cfg, glyph_ranges);
@ -232,13 +256,19 @@ namespace ImGuiNET
} }
public ImFontPtr AddFontFromFileTTF(string filename, float size_pixels, ImFontConfigPtr font_cfg) public ImFontPtr AddFontFromFileTTF(string filename, float size_pixels, ImFontConfigPtr font_cfg)
{ {
int filename_byteCount = Encoding.UTF8.GetByteCount(filename); byte* native_filename;
byte* native_filename = stackalloc byte[filename_byteCount + 1]; if (filename != null)
fixed (char* filename_ptr = filename)
{ {
int native_filename_offset = Encoding.UTF8.GetBytes(filename_ptr, filename.Length, native_filename, filename_byteCount); int filename_byteCount = Encoding.UTF8.GetByteCount(filename);
native_filename[native_filename_offset] = 0; byte* native_filename_stackBytes = stackalloc byte[filename_byteCount + 1];
native_filename = native_filename_stackBytes;
fixed (char* filename_ptr = filename)
{
int native_filename_offset = Encoding.UTF8.GetBytes(filename_ptr, filename.Length, native_filename, filename_byteCount);
native_filename[native_filename_offset] = 0;
}
} }
else { native_filename = null; }
ImFontConfig* native_font_cfg = font_cfg.NativePtr; ImFontConfig* native_font_cfg = font_cfg.NativePtr;
ushort* glyph_ranges = null; ushort* glyph_ranges = null;
ImFont* ret = ImGuiNative.ImFontAtlas_AddFontFromFileTTF(NativePtr, native_filename, size_pixels, native_font_cfg, glyph_ranges); ImFont* ret = ImGuiNative.ImFontAtlas_AddFontFromFileTTF(NativePtr, native_filename, size_pixels, native_font_cfg, glyph_ranges);
@ -246,13 +276,19 @@ namespace ImGuiNET
} }
public ImFontPtr AddFontFromFileTTF(string filename, float size_pixels, ImFontConfigPtr font_cfg, IntPtr glyph_ranges) public ImFontPtr AddFontFromFileTTF(string filename, float size_pixels, ImFontConfigPtr font_cfg, IntPtr glyph_ranges)
{ {
int filename_byteCount = Encoding.UTF8.GetByteCount(filename); byte* native_filename;
byte* native_filename = stackalloc byte[filename_byteCount + 1]; if (filename != null)
fixed (char* filename_ptr = filename)
{ {
int native_filename_offset = Encoding.UTF8.GetBytes(filename_ptr, filename.Length, native_filename, filename_byteCount); int filename_byteCount = Encoding.UTF8.GetByteCount(filename);
native_filename[native_filename_offset] = 0; byte* native_filename_stackBytes = stackalloc byte[filename_byteCount + 1];
native_filename = native_filename_stackBytes;
fixed (char* filename_ptr = filename)
{
int native_filename_offset = Encoding.UTF8.GetBytes(filename_ptr, filename.Length, native_filename, filename_byteCount);
native_filename[native_filename_offset] = 0;
}
} }
else { native_filename = null; }
ImFontConfig* native_font_cfg = font_cfg.NativePtr; ImFontConfig* native_font_cfg = font_cfg.NativePtr;
ushort* native_glyph_ranges = (ushort*)glyph_ranges.ToPointer(); ushort* native_glyph_ranges = (ushort*)glyph_ranges.ToPointer();
ImFont* ret = ImGuiNative.ImFontAtlas_AddFontFromFileTTF(NativePtr, native_filename, size_pixels, native_font_cfg, native_glyph_ranges); ImFont* ret = ImGuiNative.ImFontAtlas_AddFontFromFileTTF(NativePtr, native_filename, size_pixels, native_font_cfg, native_glyph_ranges);

File diff suppressed because it is too large Load Diff

@ -168,13 +168,19 @@ namespace ImGuiNET
public RangeAccessor<float> NavInputsDownDurationPrev => new RangeAccessor<float>(NativePtr->NavInputsDownDurationPrev, 21); public RangeAccessor<float> NavInputsDownDurationPrev => new RangeAccessor<float>(NativePtr->NavInputsDownDurationPrev, 21);
public void AddInputCharactersUTF8(string utf8_chars) public void AddInputCharactersUTF8(string utf8_chars)
{ {
int utf8_chars_byteCount = Encoding.UTF8.GetByteCount(utf8_chars); byte* native_utf8_chars;
byte* native_utf8_chars = stackalloc byte[utf8_chars_byteCount + 1]; if (utf8_chars != null)
fixed (char* utf8_chars_ptr = utf8_chars)
{ {
int native_utf8_chars_offset = Encoding.UTF8.GetBytes(utf8_chars_ptr, utf8_chars.Length, native_utf8_chars, utf8_chars_byteCount); int utf8_chars_byteCount = Encoding.UTF8.GetByteCount(utf8_chars);
native_utf8_chars[native_utf8_chars_offset] = 0; byte* native_utf8_chars_stackBytes = stackalloc byte[utf8_chars_byteCount + 1];
native_utf8_chars = native_utf8_chars_stackBytes;
fixed (char* utf8_chars_ptr = utf8_chars)
{
int native_utf8_chars_offset = Encoding.UTF8.GetBytes(utf8_chars_ptr, utf8_chars.Length, native_utf8_chars, utf8_chars_byteCount);
native_utf8_chars[native_utf8_chars_offset] = 0;
}
} }
else { native_utf8_chars = null; }
ImGuiNative.ImGuiIO_AddInputCharactersUTF8(NativePtr, native_utf8_chars); ImGuiNative.ImGuiIO_AddInputCharactersUTF8(NativePtr, native_utf8_chars);
} }
public void ClearInputCharacters() public void ClearInputCharacters()

@ -51,13 +51,19 @@ namespace ImGuiNET
} }
public void InsertChars(int pos, string text) public void InsertChars(int pos, string text)
{ {
int text_byteCount = Encoding.UTF8.GetByteCount(text); byte* native_text;
byte* native_text = stackalloc byte[text_byteCount + 1]; if (text != null)
fixed (char* text_ptr = text)
{ {
int native_text_offset = Encoding.UTF8.GetBytes(text_ptr, text.Length, native_text, text_byteCount); int text_byteCount = Encoding.UTF8.GetByteCount(text);
native_text[native_text_offset] = 0; byte* native_text_stackBytes = stackalloc byte[text_byteCount + 1];
native_text = native_text_stackBytes;
fixed (char* text_ptr = text)
{
int native_text_offset = Encoding.UTF8.GetBytes(text_ptr, text.Length, native_text, text_byteCount);
native_text[native_text_offset] = 0;
}
} }
else { native_text = null; }
byte* native_text_end = null; byte* native_text_end = null;
ImGuiNative.ImGuiInputTextCallbackData_InsertChars(NativePtr, pos, native_text, native_text_end); ImGuiNative.ImGuiInputTextCallbackData_InsertChars(NativePtr, pos, native_text, native_text_end);
} }

@ -43,13 +43,19 @@ namespace ImGuiNET
} }
public bool IsDataType(string type) public bool IsDataType(string type)
{ {
int type_byteCount = Encoding.UTF8.GetByteCount(type); byte* native_type;
byte* native_type = stackalloc byte[type_byteCount + 1]; if (type != null)
fixed (char* type_ptr = type)
{ {
int native_type_offset = Encoding.UTF8.GetBytes(type_ptr, type.Length, native_type, type_byteCount); int type_byteCount = Encoding.UTF8.GetByteCount(type);
native_type[native_type_offset] = 0; byte* native_type_stackBytes = stackalloc byte[type_byteCount + 1];
native_type = native_type_stackBytes;
fixed (char* type_ptr = type)
{
int native_type_offset = Encoding.UTF8.GetBytes(type_ptr, type.Length, native_type, type_byteCount);
native_type[native_type_offset] = 0;
}
} }
else { native_type = null; }
byte ret = ImGuiNative.ImGuiPayload_IsDataType(NativePtr, native_type); byte ret = ImGuiNative.ImGuiPayload_IsDataType(NativePtr, native_type);
return ret != 0; return ret != 0;
} }

@ -24,13 +24,19 @@ namespace ImGuiNET
} }
public void appendf(string fmt) public void appendf(string fmt)
{ {
int fmt_byteCount = Encoding.UTF8.GetByteCount(fmt); byte* native_fmt;
byte* native_fmt = stackalloc byte[fmt_byteCount + 1]; if (fmt != null)
fixed (char* fmt_ptr = fmt)
{ {
int native_fmt_offset = Encoding.UTF8.GetBytes(fmt_ptr, fmt.Length, native_fmt, fmt_byteCount); int fmt_byteCount = Encoding.UTF8.GetByteCount(fmt);
native_fmt[native_fmt_offset] = 0; byte* native_fmt_stackBytes = stackalloc byte[fmt_byteCount + 1];
native_fmt = native_fmt_stackBytes;
fixed (char* fmt_ptr = fmt)
{
int native_fmt_offset = Encoding.UTF8.GetBytes(fmt_ptr, fmt.Length, native_fmt, fmt_byteCount);
native_fmt[native_fmt_offset] = 0;
}
} }
else { native_fmt = null; }
ImGuiNative.ImGuiTextBuffer_appendf(NativePtr, native_fmt); ImGuiNative.ImGuiTextBuffer_appendf(NativePtr, native_fmt);
} }
public string c_str() public string c_str()

@ -28,39 +28,57 @@ namespace ImGuiNET
} }
public bool Draw() public bool Draw()
{ {
int label_byteCount = Encoding.UTF8.GetByteCount("Filter(inc,-exc)"); byte* native_label;
byte* native_label = stackalloc byte[label_byteCount + 1]; if ("Filter(inc,-exc)" != null)
fixed (char* label_ptr = "Filter(inc,-exc)")
{ {
int native_label_offset = Encoding.UTF8.GetBytes(label_ptr, "Filter(inc,-exc)".Length, native_label, label_byteCount); int label_byteCount = Encoding.UTF8.GetByteCount("Filter(inc,-exc)");
native_label[native_label_offset] = 0; byte* native_label_stackBytes = stackalloc byte[label_byteCount + 1];
native_label = native_label_stackBytes;
fixed (char* label_ptr = "Filter(inc,-exc)")
{
int native_label_offset = Encoding.UTF8.GetBytes(label_ptr, "Filter(inc,-exc)".Length, native_label, label_byteCount);
native_label[native_label_offset] = 0;
}
} }
else { native_label = null; }
float width = 0.0f; float width = 0.0f;
byte ret = ImGuiNative.ImGuiTextFilter_Draw(NativePtr, native_label, width); byte ret = ImGuiNative.ImGuiTextFilter_Draw(NativePtr, native_label, width);
return ret != 0; return ret != 0;
} }
public bool Draw(string label) public bool Draw(string label)
{ {
int label_byteCount = Encoding.UTF8.GetByteCount(label); byte* native_label;
byte* native_label = stackalloc byte[label_byteCount + 1]; if (label != null)
fixed (char* label_ptr = label)
{ {
int native_label_offset = Encoding.UTF8.GetBytes(label_ptr, label.Length, native_label, label_byteCount); int label_byteCount = Encoding.UTF8.GetByteCount(label);
native_label[native_label_offset] = 0; byte* native_label_stackBytes = stackalloc byte[label_byteCount + 1];
native_label = native_label_stackBytes;
fixed (char* label_ptr = label)
{
int native_label_offset = Encoding.UTF8.GetBytes(label_ptr, label.Length, native_label, label_byteCount);
native_label[native_label_offset] = 0;
}
} }
else { native_label = null; }
float width = 0.0f; float width = 0.0f;
byte ret = ImGuiNative.ImGuiTextFilter_Draw(NativePtr, native_label, width); byte ret = ImGuiNative.ImGuiTextFilter_Draw(NativePtr, native_label, width);
return ret != 0; return ret != 0;
} }
public bool Draw(string label, float width) public bool Draw(string label, float width)
{ {
int label_byteCount = Encoding.UTF8.GetByteCount(label); byte* native_label;
byte* native_label = stackalloc byte[label_byteCount + 1]; if (label != null)
fixed (char* label_ptr = label)
{ {
int native_label_offset = Encoding.UTF8.GetBytes(label_ptr, label.Length, native_label, label_byteCount); int label_byteCount = Encoding.UTF8.GetByteCount(label);
native_label[native_label_offset] = 0; byte* native_label_stackBytes = stackalloc byte[label_byteCount + 1];
native_label = native_label_stackBytes;
fixed (char* label_ptr = label)
{
int native_label_offset = Encoding.UTF8.GetBytes(label_ptr, label.Length, native_label, label_byteCount);
native_label[native_label_offset] = 0;
}
} }
else { native_label = null; }
byte ret = ImGuiNative.ImGuiTextFilter_Draw(NativePtr, native_label, width); byte ret = ImGuiNative.ImGuiTextFilter_Draw(NativePtr, native_label, width);
return ret != 0; return ret != 0;
} }
@ -75,13 +93,19 @@ namespace ImGuiNET
} }
public bool PassFilter(string text) public bool PassFilter(string text)
{ {
int text_byteCount = Encoding.UTF8.GetByteCount(text); byte* native_text;
byte* native_text = stackalloc byte[text_byteCount + 1]; if (text != null)
fixed (char* text_ptr = text)
{ {
int native_text_offset = Encoding.UTF8.GetBytes(text_ptr, text.Length, native_text, text_byteCount); int text_byteCount = Encoding.UTF8.GetByteCount(text);
native_text[native_text_offset] = 0; byte* native_text_stackBytes = stackalloc byte[text_byteCount + 1];
native_text = native_text_stackBytes;
fixed (char* text_ptr = text)
{
int native_text_offset = Encoding.UTF8.GetBytes(text_ptr, text.Length, native_text, text_byteCount);
native_text[native_text_offset] = 0;
}
} }
else { native_text = null; }
byte* native_text_end = null; byte* native_text_end = null;
byte ret = ImGuiNative.ImGuiTextFilter_PassFilter(NativePtr, native_text, native_text_end); byte ret = ImGuiNative.ImGuiTextFilter_PassFilter(NativePtr, native_text, native_text_end);
return ret != 0; return ret != 0;

@ -8,7 +8,7 @@
<DebugType>portable</DebugType> <DebugType>portable</DebugType>
<AssemblyName>ImGui.NET</AssemblyName> <AssemblyName>ImGui.NET</AssemblyName>
<PackageId>ImGui.NET</PackageId> <PackageId>ImGui.NET</PackageId>
<PackagePrereleaseIdentifier>-beta2</PackagePrereleaseIdentifier> <PackagePrereleaseIdentifier>-beta3</PackagePrereleaseIdentifier>
<PackageVersion>$(AssemblyVersion)$(PackagePrereleaseIdentifier)</PackageVersion> <PackageVersion>$(AssemblyVersion)$(PackagePrereleaseIdentifier)</PackageVersion>
<PackageTags>ImGui ImGui.NET Immediate Mode GUI</PackageTags> <PackageTags>ImGui ImGui.NET Immediate Mode GUI</PackageTags>
<PackageProjectUrl>https://github.com/mellinoe/imgui.net</PackageProjectUrl> <PackageProjectUrl>https://github.com/mellinoe/imgui.net</PackageProjectUrl>

Loading…
Cancel
Save