GetLastItemRectMin/Max, SetWindowFontScale

* Also some improvements in TextInputBuffer"
internals
Eric Mellino 8 years ago
parent 7f1bc8c6f2
commit c09777c4e3
  1. 21
      src/ImGui.NET/ImGui.cs
  2. 56
      src/ImGui.NET/TextInputBuffer.cs
  3. 2
      src/ImGui.NET/project.json

@ -962,11 +962,30 @@ namespace ImGuiNET
ImGuiNative.igTreePop();
}
public static Vector2 GetLastItemRect()
public static Vector2 GetLastItemRectSize()
{
Vector2 result;
ImGuiNative.igGetItemRectSize(out result);
return result;
}
public static Vector2 GetLastItemRectMin()
{
Vector2 result;
ImGuiNative.igGetItemRectMin(out result);
return result;
}
public static Vector2 GetLastItemRectMax()
{
Vector2 result;
ImGuiNative.igGetItemRectMax(out result);
return result;
}
public static void SetWindowFontScale(float scale)
{
ImGuiNative.igSetWindowFontScale(scale);
}
}
}

@ -1,15 +1,39 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace ImGuiNET
{
public class TextInputBuffer : IDisposable
{
private uint _length;
public IntPtr Buffer { get; private set; }
public uint Length { get; private set; }
public uint Length
{
get
{
return _length;
}
set
{
if (value > int.MaxValue)
{
throw new ArgumentOutOfRangeException("Length cannot be greater that Int32.MaxValue.");
}
Resize((int)value);
}
}
public TextInputBuffer(int length)
{
if (length < 0)
{
throw new ArgumentOutOfRangeException(nameof(length));
}
CreateBuffer(length);
}
@ -19,10 +43,13 @@ namespace ImGuiNET
Length = (uint)initialText.Length;
}
public void Resize(int newSize)
private unsafe void Resize(int newSize)
{
FreeNativeBuffer();
CreateBuffer(newSize);
IntPtr newBuffer = Marshal.AllocHGlobal(newSize);
Unsafe.CopyBlock(newBuffer.ToPointer(), Buffer.ToPointer(), Length);
Marshal.FreeHGlobal(Buffer);
Buffer = newBuffer;
_length = (uint)newSize;
}
private unsafe void CreateBuffer(int size)
@ -53,7 +80,7 @@ namespace ImGuiNET
{
Marshal.FreeHGlobal(Buffer);
Buffer = IntPtr.Zero;
Length = 0;
_length = 0;
}
public string StringValue
@ -64,9 +91,22 @@ namespace ImGuiNET
}
set
{
FreeNativeBuffer();
Buffer = Marshal.StringToHGlobalAnsi(value);
Length = (uint)value.Length;
if (value.Length > Length) // Doesn't fit into current buffer
{
FreeNativeBuffer();
Buffer = Marshal.StringToHGlobalAnsi(value);
_length = (uint)value.Length;
}
else // Fits in current buffer, just copy data in.
{
IntPtr tempNativeString = Marshal.StringToHGlobalAnsi(value);
uint bytesToCopy = (uint)Math.Min(Length, value.Length);
unsafe
{
Unsafe.CopyBlock(Buffer.ToPointer(), tempNativeString.ToPointer(), bytesToCopy);
}
Marshal.FreeHGlobal(tempNativeString);
}
}
}

@ -16,6 +16,8 @@
},
"dependencies": {
"System.Numerics.Vectors": "4.1.1",
"System.Runtime.CompilerServices.Unsafe": "4.0.0",
"System.Runtime.Extensions": "4.1.0",
"System.Runtime.InteropServices": "4.1.0"
},
"frameworks": {

Loading…
Cancel
Save