From 731a7f6aac25d7a20a961474716a35c4b8671eae Mon Sep 17 00:00:00 2001 From: dpethes Date: Mon, 16 Jan 2017 21:59:06 +0100 Subject: [PATCH 1/4] add a few default parameters (same as in imgui.h) --- src/ImGui.NET/ImGui.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ImGui.NET/ImGui.cs b/src/ImGui.NET/ImGui.cs index c6b5210..4e387e6 100644 --- a/src/ImGui.NET/ImGui.cs +++ b/src/ImGui.NET/ImGui.cs @@ -600,7 +600,7 @@ namespace ImGuiNET return ImGuiNative.igIsKeyDown(keyIndex); } - public static bool IsKeyPressed(int keyIndex, bool repeat) + public static bool IsKeyPressed(int keyIndex, bool repeat = true) { return ImGuiNative.igIsKeyPressed(keyIndex, repeat); } @@ -615,7 +615,7 @@ namespace ImGuiNET return ImGuiNative.igIsMouseDown(button); } - public static bool IsMouseClicked(int button, bool repeat) + public static bool IsMouseClicked(int button, bool repeat = false) { return ImGuiNative.igIsMouseClicked(button, repeat); } @@ -896,7 +896,7 @@ namespace ImGuiNET ImGuiNative.igSameLine(0, 0); } - public static void SameLine(float localPositionX, float spacingW) + public static void SameLine(float localPositionX = 0, float spacingW = -1.0f) { ImGuiNative.igSameLine(localPositionX, spacingW); } From f2d9754ffc4dbebfea3bdf5d922b683f2689714c Mon Sep 17 00:00:00 2001 From: dpethes Date: Mon, 16 Jan 2017 22:01:40 +0100 Subject: [PATCH 2/4] ImGuiTextEditCallbackData helper method --- src/ImGui.NET/TextEditCallbackData.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ImGui.NET/TextEditCallbackData.cs b/src/ImGui.NET/TextEditCallbackData.cs index 24789e4..b67af9a 100644 --- a/src/ImGui.NET/TextEditCallbackData.cs +++ b/src/ImGui.NET/TextEditCallbackData.cs @@ -59,5 +59,7 @@ namespace ImGuiNET /// Read-write. /// public int SelectionEnd; + + public bool HasSelection() { return SelectionStart != SelectionEnd; } } } From d8d2805a1aa0a31ed0118a22cb09431379158e69 Mon Sep 17 00:00:00 2001 From: dpethes Date: Mon, 16 Jan 2017 22:02:23 +0100 Subject: [PATCH 3/4] misc wrappers for native funcs --- src/ImGui.NET/ImGui.cs | 49 ++++++++++++++++++++++++++++++++++++ src/ImGui.NET/ImGuiNative.cs | 6 ++--- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/src/ImGui.NET/ImGui.cs b/src/ImGui.NET/ImGui.cs index 4e387e6..b8784e6 100644 --- a/src/ImGui.NET/ImGui.cs +++ b/src/ImGui.NET/ImGui.cs @@ -1,6 +1,7 @@ using System; using System.Numerics; using System.Runtime.InteropServices; +using System.Diagnostics; namespace ImGuiNET { @@ -92,6 +93,11 @@ namespace ImGuiNET ImGuiNative.igTextWrapped(text); } + public static void TextUnformatted(string message) + { + ImGuiNative.igTextUnformatted(message, null); + } + public static void LabelText(string label, string text) { ImGuiNative.igLabelText(label, text); @@ -451,6 +457,18 @@ namespace ImGuiNET return ImGuiNative.igGetWindowWidth(); } + public static Vector2 GetWindowSize() + { + Vector2 size; + ImGuiNative.igGetWindowSize(out size); + return size; + } + + public static void SetWindowSize(Vector2 size, SetCondition cond) + { + ImGuiNative.igSetWindowSize(size, cond); + } + public static bool BeginWindow(string windowTitle) => BeginWindow(windowTitle, WindowFlags.Default); public static bool BeginWindow(string windowTitle, WindowFlags flags) @@ -534,6 +552,20 @@ namespace ImGuiNET return ImGuiNative.igMenuItem(label, shortcut, selected, enabled); } + public static unsafe bool InputText(string label, byte[] textBuffer, uint bufferSize, InputTextFlags flags, TextEditCallback textEditCallback) + { + return InputText(label, textBuffer, bufferSize, flags, textEditCallback, IntPtr.Zero); + } + + public static unsafe bool InputText(string label, byte[] textBuffer, uint bufferSize, InputTextFlags flags, TextEditCallback textEditCallback, IntPtr userData) + { + Debug.Assert(bufferSize <= textBuffer.Length); + fixed (byte* ptrBuf = textBuffer) + { + return InputText(label, new IntPtr(ptrBuf), bufferSize, flags, textEditCallback, userData); + } + } + public static unsafe bool InputText(string label, IntPtr textBuffer, uint bufferSize, InputTextFlags flags, TextEditCallback textEditCallback) { return InputText(label, textBuffer, bufferSize, flags, textEditCallback, IntPtr.Zero); @@ -688,6 +720,18 @@ namespace ImGuiNET } } + public static Vector2 GetCursorStartPos() + { + Vector2 retVal; + ImGuiNative.igGetCursorStartPos(out retVal); + return retVal; + } + + public static bool BeginChild(string id, bool border = false, WindowFlags flags = 0) + { + return BeginChild(id, new Vector2(0, 0), border, flags); + } + public static bool BeginChild(string id, Vector2 size, bool border, WindowFlags flags) { return ImGuiNative.igBeginChild(id, size, border, flags); @@ -1011,5 +1055,10 @@ namespace ImGuiNET { ImGuiNative.igSetKeyboardFocusHere(offset); } + + public static void CalcListClipping(int itemsCount, float itemsHeight, ref int outItemsDisplayStart, ref int outItemsDisplayEnd) + { + ImGuiNative.igCalcListClipping(itemsCount, itemsHeight, ref outItemsDisplayStart, ref outItemsDisplayEnd); + } } } diff --git a/src/ImGui.NET/ImGuiNative.cs b/src/ImGui.NET/ImGuiNative.cs index d462233..da22ad8 100644 --- a/src/ImGui.NET/ImGuiNative.cs +++ b/src/ImGui.NET/ImGuiNative.cs @@ -225,7 +225,7 @@ namespace ImGuiNET [DllImport(cimguiLib)] public static extern void igSetCursorPosY(float y); [DllImport(cimguiLib)] - public static extern void igGetCursorStartPos(Vector2* pOut); + public static extern void igGetCursorStartPos(out Vector2 pOut); [DllImport(cimguiLib)] public static extern void igGetCursorScreenPos(Vector2* pOut); [DllImport(cimguiLib)] @@ -272,7 +272,7 @@ namespace ImGuiNET public static extern void igTextWrapped(string fmt); [DllImport(cimguiLib)] - public static extern void igTextUnformatted(byte* text, byte* text_end); + public static extern void igTextUnformatted(string text, string text_end); [DllImport(cimguiLib)] public static extern void igLabelText(string label, string fmt); @@ -658,7 +658,7 @@ namespace ImGuiNET [DllImport(cimguiLib)] public static extern void igCalcTextSize(out Vector2 pOut, char* text, char* text_end, bool hide_text_after_double_hash, float wrap_width); [DllImport(cimguiLib)] - public static extern void igCalcListClipping(int items_count, float items_height, int* out_items_display_start, int* out_items_display_end); + public static extern void igCalcListClipping(int items_count, float items_height, ref int out_items_display_start, ref int out_items_display_end); [DllImport(cimguiLib)] [return: MarshalAs(UnmanagedType.I1)] From cf1006e6b038c389d914930d743f24ad9596b48f Mon Sep 17 00:00:00 2001 From: dpethes Date: Fri, 20 Jan 2017 15:01:17 +0100 Subject: [PATCH 4/4] - revert igTextUnformatted signature - remove parameterless SameLine --- src/ImGui.NET/ImGui.cs | 12 +++++------- src/ImGui.NET/ImGuiNative.cs | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/ImGui.NET/ImGui.cs b/src/ImGui.NET/ImGui.cs index b8784e6..37230d6 100644 --- a/src/ImGui.NET/ImGui.cs +++ b/src/ImGui.NET/ImGui.cs @@ -93,9 +93,12 @@ namespace ImGuiNET ImGuiNative.igTextWrapped(text); } - public static void TextUnformatted(string message) + public static unsafe void TextUnformatted(string message) { - ImGuiNative.igTextUnformatted(message, null); + fixed (byte* bytes = System.Text.Encoding.UTF8.GetBytes(message)) + { + ImGuiNative.igTextUnformatted(bytes, null); + } } public static void LabelText(string label, string text) @@ -935,11 +938,6 @@ namespace ImGuiNET ImGuiNative.igOpenPopup(id); } - public static void SameLine() - { - ImGuiNative.igSameLine(0, 0); - } - public static void SameLine(float localPositionX = 0, float spacingW = -1.0f) { ImGuiNative.igSameLine(localPositionX, spacingW); diff --git a/src/ImGui.NET/ImGuiNative.cs b/src/ImGui.NET/ImGuiNative.cs index da22ad8..8f33416 100644 --- a/src/ImGui.NET/ImGuiNative.cs +++ b/src/ImGui.NET/ImGuiNative.cs @@ -272,7 +272,7 @@ namespace ImGuiNET public static extern void igTextWrapped(string fmt); [DllImport(cimguiLib)] - public static extern void igTextUnformatted(string text, string text_end); + public static extern void igTextUnformatted(byte* text, byte* text_end); [DllImport(cimguiLib)] public static extern void igLabelText(string label, string fmt);