public static bool InputText( string label, IntPtr buf, uint buf_size, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, IntPtr user_data) { int utf8LabelByteCount = Encoding.UTF8.GetByteCount(label); byte *utf8LabelBytes; if (utf8LabelByteCount > Util.StackAllocationSizeLimit) { utf8LabelBytes = Util.Allocate(utf8LabelByteCount + 1); } else { byte *stackPtr = stackalloc byte[utf8LabelByteCount + 1]; utf8LabelBytes = stackPtr; } Util.GetUtf8(label, utf8LabelBytes, utf8LabelByteCount); bool ret = ImGuiNative.igInputText(utf8LabelBytes, (byte *)buf.ToPointer(), buf_size, flags, callback, user_data.ToPointer()) != 0; if (utf8LabelByteCount > Util.StackAllocationSizeLimit) { Util.Free(utf8LabelBytes); } return(ret); }
public void InputTextMultiline(string id, Vector2 size, ImGuiInputTextFlags flags, int sz = -1) { var idBytes = UnsafeHelpers.StringToHGlobalUTF8(id); ImGuiNative.igInputTextMultiline((byte *)idBytes, (byte *)Pointer, (uint)(sz > 0 ? sz : Size), size, flags, Callback, (void *)0); Marshal.FreeHGlobal(idBytes); }
public InputAttribute(float step = 1, float step_fast = 3, string format = "", ImGuiInputTextFlags flags = ImGuiInputTextFlags.None) { this.format = format == "" ? "%.1f" : format; this.step = step; this.step_fast = step_fast; this.flags = flags; }
public static bool InputScalar(string label, ref byte data, byte?step = null, byte?stepFast = null, string format = null, ImGuiInputTextFlags flags = ImGuiInputTextFlags.None) { IntPtr dataPtr; IntPtr stepPtr = IntPtr.Zero; IntPtr stepFastPtr = IntPtr.Zero; fixed(void *fixedData = &data) { dataPtr = new IntPtr(fixedData); } var stepValue = step.HasValue ? step.Value : default; if (step.HasValue) { stepPtr = new IntPtr(&stepValue); } var stepFastValue = stepFast.HasValue ? stepFast.Value : default; if (stepFast.HasValue) { stepFastPtr = new IntPtr(&stepFastValue); } return(InputScalar(label, ImGuiDataType.U8, dataPtr, stepPtr, stepFastPtr, format, flags)); }
public static bool InputTextWithHint( string label, string hint, ref string input, uint maxLength, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback) => InputTextWithHint(label, hint, ref input, maxLength, flags, callback, IntPtr.Zero);
public static bool InputTextMultiline( string label, ref string input, uint maxLength, Vector2 size, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback) => InputTextMultiline(label, ref input, maxLength, size, flags, callback, IntPtr.Zero);
public static bool InputText( ReadOnlySpan <char> label, byte[] buf, uint buf_size, ImGuiInputTextFlags flags) { return(InputText(label, buf, buf_size, flags, null, IntPtr.Zero)); }
protected BaseEditableText(int index, object editObject, MemberInfo info, Type type, ObjectAccessor objectAccessor, ImGuiInputTextFlags flags) { _label = $"{index}: {info.Name}"; _info = info; _flags = flags; }
public static bool InputText( string label, IntPtr buf, uint buf_size, ImGuiInputTextFlags flags) { return(InputText(label, buf, buf_size, flags, null, IntPtr.Zero)); }
public static bool InputText( string label, IntPtr buf, uint buf_size, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback) { return(InputText(label, buf, buf_size, flags, callback, IntPtr.Zero)); }
public static bool InputTextWithHint( string label, string hint, ref string input, uint maxLength, ImGuiInputTextFlags flags) { return(InputTextWithHint(label, hint, ref input, maxLength, flags, null, IntPtr.Zero)); }
public static bool InputText(string label, ref string inputText, ImGuiInputTextFlags flags = 0) { buffer.Clear(); buffer.Append(inputText); bool val = PInputText(label, buffer, buffer.Capacity, flags); inputText = buffer.ToString(); return(val); }
public static string InputText(string label, string currentValue, uint maxLength, ImGuiInputTextFlags flags) { byte[] buff = new byte[maxLength]; if (!String.IsNullOrEmpty(currentValue)) { byte[] currentValueBytes = Encoding.UTF8.GetBytes(currentValue); Array.Copy(currentValueBytes, buff, currentValueBytes.Length); } ImGui.InputText(label, buff, maxLength, flags); return(Encoding.Default.GetString(buff).TrimEnd('\0')); }
public static bool InputFromText(string label, object obj, string properyName, int bufferLength, ImGuiInputTextFlags exflags = ImGuiInputTextFlags.None) { var input = obj.GetType().GetProperty(properyName); var inputValue = (string)input.GetValue(obj); var flags = exflags | ImGuiInputTextFlags.EnterReturnsTrue | ImGuiInputTextFlags.AutoSelectAll; if (ImGui.InputText(label, ref inputValue, (uint)bufferLength + 1, flags)) { UndoStack.Add(new UndoStringOperation("Text Changed", obj, properyName, inputValue)); input.SetValue(obj, inputValue); return(true); } return(false); }
public static bool InputTextMultiline( string label, ref string input, uint maxLength, Vector2 size, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, IntPtr user_data) { int labelByteCount = Encoding.UTF8.GetByteCount(label); byte *labelBytes = stackalloc byte[labelByteCount]; fixed(char *labelPtr = label) { Encoding.UTF8.GetBytes(labelPtr, label.Length, labelBytes, labelByteCount); } int originalByteCount = Encoding.UTF8.GetByteCount(input); int stackBufSize = Math.Max((int)maxLength, originalByteCount); byte *bufBytes = stackalloc byte[stackBufSize]; fixed(char *u16Ptr = input) { Encoding.UTF8.GetBytes(u16Ptr, input.Length, bufBytes, stackBufSize); } byte *originalBufBytes = stackalloc byte[originalByteCount]; Unsafe.CopyBlock(originalBufBytes, bufBytes, (uint)originalByteCount); byte result = ImGuiNative.igInputTextMultiline( labelBytes, bufBytes, (uint)stackBufSize, size, flags, callback, user_data.ToPointer()); if (!Util.AreStringsEqual(originalBufBytes, originalByteCount, bufBytes)) { input = Util.StringFromPtr(bufBytes); } return(result != 0); }
public static bool InputText( string label, IntPtr buf, uint buf_size, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, IntPtr user_data) { int labelByteCount = Encoding.UTF8.GetByteCount(label); byte *labelBytes = stackalloc byte[labelByteCount]; fixed(char *labelPtr = label) { Encoding.UTF8.GetBytes(labelPtr, label.Length, labelBytes, labelByteCount); } return(ImGuiNative.igInputText(labelBytes, (byte *)buf.ToPointer(), buf_size, flags, callback, user_data.ToPointer()) != 0); }
public static unsafe bool InputTextWithHint( string label, string hint, ref string input, uint maxLength, ImGuiInputTextFlags flags, ImGuiInputTextCallback?callback, IntPtr user_data) { maxLength = Math.Max(maxLength, (uint)input.Length); var labelBytes = Encoding.UTF8.GetBytes(label); var hintBytes = Encoding.UTF8.GetBytes(hint); var inputBytes = Encoding.UTF8.GetBytes(input); var outputBytes = new byte[maxLength + 1]; Array.Copy(inputBytes, outputBytes, inputBytes.Length); outputBytes[inputBytes.Length] = 0; byte result = 0; fixed(byte *labelBytePtr = labelBytes) fixed(byte *hintBytePtr = hintBytes) fixed(byte *outputBytePtr = outputBytes) { result = ImGuiNative.igInputTextWithHint( labelBytePtr, hintBytePtr, outputBytePtr, maxLength + 1, flags, callback, user_data.ToPointer()); } if (result != 0) { var terminatorI = outputBytes.IndexOf((byte)0); input = Encoding.UTF8.GetString(outputBytes, 0, terminatorI); } return(result != 0); }
public static bool InputText(string label, ref string str, ImGuiInputTextFlags flags = default, IntPtr callback = default, IntPtr user_data = default) { if (str == null) { str = ""; } int len = Encoding.UTF8.GetByteCount(str); while (len >= buffer.Length) { Array.Resize(ref buffer, buffer.Length * 2); } var buff = (byte *)Unsafe.AsPointer(ref buffer[0]); fixed(char *p_char = str) { len = Encoding.UTF8.GetBytes(p_char, str.Length, buff, len); buff[len] = 0; } var res = InputText(label, buff, (IntPtr)buffer.Length, flags, callback, user_data); if (res) { len = 0; while (*buff++ != 0) { len++; } str = Encoding.UTF8.GetString(buffer, 0, len); } return(res); }
public static unsafe bool InputText(string label, byte[] textBuffer, uint bufferSize, ImGuiInputTextFlags flags, ImGuiTextEditCallback textEditCallback, IntPtr userData) { Debug.Assert(bufferSize <= textBuffer.Length); fixed(byte *ptrBuf = textBuffer) return(InputText(label, new IntPtr(ptrBuf), bufferSize, flags, textEditCallback, userData)); }
public static bool InputText( string label, ref string input, uint maxLength, ImGuiInputTextFlags flags) => InputText(label, ref input, maxLength, flags, null, IntPtr.Zero);
public static bool InputTextWithHint( string label, string hint, ref string input, uint maxLength, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, IntPtr user_data) { int utf8LabelByteCount = Encoding.UTF8.GetByteCount(label); byte *utf8LabelBytes; if (utf8LabelByteCount > Util.StackAllocationSizeLimit) { utf8LabelBytes = Util.Allocate(utf8LabelByteCount + 1); } else { byte *stackPtr = stackalloc byte[utf8LabelByteCount + 1]; utf8LabelBytes = stackPtr; } Util.GetUtf8(label, utf8LabelBytes, utf8LabelByteCount); int utf8HintByteCount = Encoding.UTF8.GetByteCount(hint); byte *utf8HintBytes; if (utf8HintByteCount > Util.StackAllocationSizeLimit) { utf8HintBytes = Util.Allocate(utf8HintByteCount + 1); } else { byte *stackPtr = stackalloc byte[utf8HintByteCount + 1]; utf8HintBytes = stackPtr; } Util.GetUtf8(hint, utf8HintBytes, utf8HintByteCount); int utf8InputByteCount = Encoding.UTF8.GetByteCount(input); int inputBufSize = Math.Max((int)maxLength + 1, utf8InputByteCount + 1); byte *utf8InputBytes; byte *originalUtf8InputBytes; if (inputBufSize > Util.StackAllocationSizeLimit) { utf8InputBytes = Util.Allocate(inputBufSize); originalUtf8InputBytes = Util.Allocate(inputBufSize); } else { byte *inputStackBytes = stackalloc byte[inputBufSize]; utf8InputBytes = inputStackBytes; byte *originalInputStackBytes = stackalloc byte[inputBufSize]; originalUtf8InputBytes = originalInputStackBytes; } Util.GetUtf8(input, utf8InputBytes, inputBufSize); uint clearBytesCount = (uint)(inputBufSize - utf8InputByteCount); Unsafe.InitBlockUnaligned(utf8InputBytes + utf8InputByteCount, 0, clearBytesCount); Unsafe.CopyBlock(originalUtf8InputBytes, utf8InputBytes, (uint)inputBufSize); byte result = ImGuiNative.igInputTextWithHint( utf8LabelBytes, utf8HintBytes, utf8InputBytes, (uint)inputBufSize, flags, callback, user_data.ToPointer()); if (!Util.AreStringsEqual(originalUtf8InputBytes, inputBufSize, utf8InputBytes)) { input = Util.StringFromPtr(utf8InputBytes); } if (utf8LabelByteCount > Util.StackAllocationSizeLimit) { Util.Free(utf8LabelBytes); } if (inputBufSize > Util.StackAllocationSizeLimit) { Util.Free(utf8InputBytes); Util.Free(originalUtf8InputBytes); } return(result != 0); }
public static unsafe void InputTextMultiline(string label, IntPtr textBuffer, uint bufferSize, ImVec2 size, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback) => ImGuiNative.igInputTextMultiline(label, textBuffer, bufferSize, size, flags, callback, null);
public static unsafe void InputTextMultiline(string label, IntPtr textBuffer, uint bufferSize, ImVec2 size, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback, IntPtr userData) { ImGuiNative.igInputTextMultiline(label, textBuffer, bufferSize, size, flags, callback, userData.ToPointer()); }
public static unsafe bool InputText(string label, IntPtr textBuffer, uint bufferSize, ImGuiInputTextFlags flags, ImGuiTextEditCallback textEditCallback, IntPtr userData) { return(ImGuiNative.igInputText(label, textBuffer, bufferSize, flags, textEditCallback, userData.ToPointer())); }
public static bool InputTextMultiline(string label, byte[] buf, ImVec2 size, ImGuiInputTextFlags flags = ImGuiInputTextFlags.None, IntPtr callback = default, IntPtr user_data = default) => InputTextMultiline(label, (byte *)Unsafe.AsPointer(ref buf[0]), (IntPtr)buf.Length, size, flags, callback, user_data);
public static unsafe string MultiLineTextBox(string label, string currentValue, uint maxLength, ImGuiVector2 vect2, ImGuiInputTextFlags flags) { var testString = currentValue; var currentStringBytes = Encoding.Default.GetBytes(currentValue); var buffer = new byte[maxLength]; Array.Copy(currentStringBytes, buffer, Math.Min(currentStringBytes.Length, maxLength)); int Callback(ImGuiInputTextCallbackData *data) { int *p_cursor_pos = (int *)data->UserData; if (ImGuiNative.ImGuiInputTextCallbackData_HasSelection(data) == 0) { *p_cursor_pos = data->CursorPos; } return(0); } ImGui.InputTextMultiline(label, ref currentValue, maxLength, vect2, flags, Callback); return(currentValue.TrimEnd('\0').TrimEnd('\u0000').Replace("\u0000", "")); }
public static unsafe string InputText(string label, string currentValue, uint maxLength, ImGuiInputTextFlags flags) { var currentStringBytes = Encoding.Default.GetBytes(currentValue); var buffer = new byte[maxLength]; Array.Copy(currentStringBytes, buffer, Math.Min(currentStringBytes.Length, maxLength)); int cursor_pos = -1; int Callback(ImGuiInputTextCallbackData *data) { int *p_cursor_pos = (int *)data->UserData; if (ImGuiNative.ImGuiInputTextCallbackData_HasSelection(data) == 0) { *p_cursor_pos = data->CursorPos; } return(0); } ImGui.InputText(label, buffer, maxLength, flags, Callback, (IntPtr)(&cursor_pos)); return(Encoding.Default.GetString(buffer).TrimEnd('\0')); }
void RenderDialog() { var debugFlags = Resolve <ISettings>().Debug.DebugFlags; if ((debugFlags & DebugFlags.ShowConsole) == 0) { _wasShown = false; return; } if (!_wasShown) { _scrollToBottom = true; } var window = Resolve <IWindowManager>(); ImGui.Begin("Console"); ImGui.SetWindowPos(Vector2.Zero, ImGuiCond.FirstUseEver); ImGui.SetWindowSize(new Vector2(window.PixelWidth / 3.0f, window.PixelHeight), ImGuiCond.FirstUseEver); // Reserve enough left-over height for 1 separator + 1 input text float footerHeightToReserve = ImGui.GetStyle().ItemSpacing.Y + ImGui.GetFrameHeightWithSpacing(); ImGui.BeginChild( "ScrollingRegion", new Vector2(0, -footerHeightToReserve), false, ImGuiWindowFlags.HorizontalScrollbar); // Display every line as a separate entry so we can change their color or add custom widgets. // If you only want raw text you can use ImGui.TextUnformatted(log.begin(), log.end()); // NB- if you have thousands of entries this approach may be too inefficient and may require user-side clipping // to only process visible items. The clipper will automatically measure the height of your first item and then // "seek" to display only items in the visible area. // To use the clipper we can replace your standard loop: // for (int i = 0; i < Items.Size; i++) // With: // ImGuiListClipper clipper(Items.Size); // while (clipper.Step()) // for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) // - That your items are evenly spaced (same height) // - That you have cheap random access to your elements (you can access them given their index, // without processing all the ones before) // You cannot this code as-is if a filter is active because it breaks the 'cheap random-access' property. // We would need random-access on the post-filtered list. // A typical application wanting coarse clipping and filtering may want to pre-compute an array of indices // or offsets of items that passed the filtering test, recomputing this array when user changes the filter, // and appending newly elements as they are inserted. This is left as a task to the user until we can manage // to improve this example code! // If your items are of variable height: // - Split them into same height items would be simpler and facilitate random-seeking into your list. // - Consider using manual call to IsRectVisible() and skipping extraneous decoration from your items. ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(4, 1)); // Tighten spacing lock (_syncRoot) { foreach (var log in _history) { //if (!Filter.PassFilter(item)) // continue; // Normally you would store more information in your item than just a string. // (e.g. make Items[] an array of structure, store color/type etc.) ImGui.PushStyleColor(ImGuiCol.Text, ConsoleColorToRgba(log.Color)); ImGui.Indent(log.Nesting); ImGui.TextUnformatted(log.Message); ImGui.Unindent(log.Nesting); ImGui.PopStyleColor(); } } if (_scrollToBottom || (_autoScroll && ImGui.GetScrollY() >= ImGui.GetScrollMaxY())) { ImGui.SetScrollHereY(1.0f); } _scrollToBottom = false; ImGui.PopStyleVar(); ImGui.EndChild(); ImGui.Separator(); // Command-line bool reclaimFocus = false; ImGuiInputTextFlags inputTextFlags = ImGuiInputTextFlags.EnterReturnsTrue; // | ImGuiInputTextFlags.CallbackCompletion // | ImGuiInputTextFlags.CallbackHistory; if (!_wasShown) { ImGui.SetKeyboardFocusHere(0); } if (ImGui.InputText("", _inputBuffer, (uint)_inputBuffer.Length, inputTextFlags)) { var logExchange = Resolve <ILogExchange>(); try { var command = Encoding.ASCII.GetString(_inputBuffer); command = command.Substring(0, command.IndexOf((char)0, StringComparison.Ordinal)); for (int i = 0; i < command.Length; i++) { _inputBuffer[i] = 0; } var @event = Event.Parse(command); if (@event != null) { logExchange.EnqueueEvent(@event); } else { PrintMessage($"Unknown event \"{command}\"", ConsoleColor.Red); } } catch (Exception e) { PrintMessage($"Parse error: {e}", ConsoleColor.Red); } reclaimFocus = true; } ImGui.SetItemDefaultFocus(); if (reclaimFocus) { ImGui.SetKeyboardFocusHere(-1); // Auto focus previous widget } ImGui.SameLine(); ImGui.Checkbox("Scroll", ref _autoScroll); ImGui.End(); _wasShown = true; }
public static unsafe bool InputText(string label, IntPtr textBuffer, uint bufferSize, ImGuiInputTextFlags flags = ImGuiInputTextFlags.Default, ImGuiTextEditCallback textEditCallback = null) { return(InputText(label, textBuffer, bufferSize, flags, textEditCallback, IntPtr.Zero)); }
public static bool InputTextWithHint(string label, string hint, byte[] buf, ImGuiInputTextFlags flags, IntPtr callback, IntPtr user_data) => InputTextWithHint(label, hint, (byte *)Unsafe.AsPointer(ref buf[0]), (IntPtr)buf.Length, flags, callback, user_data);