Fix a couple minor issues

* Typo in NativeIO.cs
* TextInputBuffer was not properly initializing its Length property
  in the non-string constructor.
* Cleaned up TextInputBuffer's interface a bit, added some helpful methods
internals
Eric Mellino 9 years ago
parent 10c4c89841
commit bf7aab44e2
  1. 2
      src/ImGui.NET/NativeIO.cs
  2. 33
      src/ImGui.NET/TextInputBuffer.cs

@ -69,7 +69,7 @@ namespace ImGuiNET
public float KeyRepeatRate;
/// <summary>
/// Store your own data for retrieval by callbacks.
/// Default value; IntPtr.Zero.
/// Default value: IntPtr.Zero.
/// </summary>
public IntPtr UserData;

@ -21,29 +21,46 @@ namespace ImGuiNET
public void Resize(int newSize)
{
ClearBuffer();
FreeNativeBuffer();
CreateBuffer(newSize);
}
private void CreateBuffer(int size)
private unsafe void CreateBuffer(int size)
{
Buffer = Marshal.AllocHGlobal(size);
Length = Length;
Length = (uint)size;
ClearData();
}
private void ClearBuffer()
public unsafe void ClearData()
{
Marshal.FreeHGlobal(Buffer);
Buffer = IntPtr.Zero;
Length = 0;
byte* ptr = (byte*)Buffer.ToPointer();
for (int i = 0; i < Length; i++)
{
ptr[i] = 0;
}
}
public void Dispose()
{
if (Buffer != IntPtr.Zero)
{
ClearBuffer();
FreeNativeBuffer();
}
}
private void FreeNativeBuffer()
{
Marshal.FreeHGlobal(Buffer);
Buffer = IntPtr.Zero;
Length = 0;
}
public string GetString()
{
return Marshal.PtrToStringAnsi(Buffer);
}
public override string ToString() => GetString();
}
}

Loading…
Cancel
Save