public void BuildHeader(ImGui gui) { var spacing = innerPadding.left + innerPadding.right; var x = 0f; var topSeparator = gui.AllocateRect(0f, 0.1f); var y = gui.statePosition.Y; using (var group = gui.EnterFixedPositioning(0f, 1f, innerPadding)) { foreach (var column in columns) { if (column.width < column.minWidth) { column.width = column.minWidth; } var rect = new Rect(x, y, column.width, 0f); group.SetManualRectRaw(rect, RectAllocator.LeftRow); gui.BuildText(column.header); rect.Bottom = gui.statePosition.Y; x += column.width + spacing; if (!column.isFixedSize) { BuildHeaderResizer(gui, column, new Rect(x - 0.7f, y, 1f, 2.2f)); } if (column.menuBuilder != null) { var menuRect = new Rect(rect.Right - 1.7f, rect.Y + 0.3f, 1.5f, 1.5f); if (gui.isBuilding) { gui.DrawIcon(menuRect, Icon.DropDown, SchemeColor.BackgroundText); } if (gui.BuildButton(menuRect, SchemeColor.None, SchemeColor.Grey) == ImGuiUtils.Event.Click) { gui.ShowDropDown(menuRect, column.menuBuilder, new Padding(1f)); } } } } width = x + 0.2f - spacing; var separator = gui.AllocateRect(x, 0.1f); if (gui.isBuilding) { topSeparator.Width = separator.Width = width; gui.DrawRectangle(topSeparator, SchemeColor.GreyAlt); gui.DrawRectangle(separator, SchemeColor.GreyAlt); //DrawVerticalGrid(gui, topSeparator.Bottom, separator.Top, SchemeColor.GreyAlt); } }
public static bool BuildSlider(this ImGui gui, float value, out float newValue, float width = 10f) { var sliderRect = gui.AllocateRect(width, 2f, RectAlignment.Full); var handleStart = (sliderRect.Width - 1f) * value; var handleRect = new Rect(sliderRect.X + handleStart, sliderRect.Y, 1f, sliderRect.Height); var update = false; newValue = value; switch (gui.action) { case ImGuiAction.Build: gui.DrawRectangle(handleRect, gui.IsMouseOverOrDown(sliderRect) ? SchemeColor.Background : SchemeColor.PureBackground, RectangleBorder.Thin); sliderRect.Y += (sliderRect.Height - 0.3f) / 2f; sliderRect.Height = 0.3f; gui.DrawRectangle(sliderRect, SchemeColor.Grey); break; case ImGuiAction.MouseMove: if (gui.IsMouseDown(sliderRect)) { update = true; } else { gui.ConsumeMouseOver(sliderRect, RenderingUtils.cursorHand); } break; case ImGuiAction.MouseDown: if (gui.IsMouseOver(sliderRect)) { gui.ConsumeMouseDown(sliderRect); update = true; } break; } if (!update) { return(false); } var positionX = (gui.mousePosition.X - sliderRect.X - 0.5f) / (sliderRect.Width - 1f); newValue = MathUtils.Clamp(positionX, 0f, 1f); gui.Rebuild(); return(true); }
public Rect BuildRow(ImGui gui, TData element, float startX = 0f) { contentGui = gui; var x = innerPadding.left; var rowColor = SchemeColor.None; var textColor = rowColor; using (var group = gui.EnterFixedPositioning(width, 0f, innerPadding, textColor)) { foreach (var column in columns) { if (column.width < column.minWidth) { column.width = column.minWidth; } @group.SetManualRect(new Rect(x, 0, column.width, 0f), RectAllocator.LeftRow); column.build(gui, element); x += column.width + spacing; } } var rect = gui.lastRect; var bottom = gui.lastRect.Bottom; if (gui.isBuilding) { gui.DrawRectangle(new Rect(startX, bottom - 0.1f, x - startX, 0.1f), SchemeColor.Grey); } return(rect); }
public static bool BuildLink(this ImGui gui, string text) { gui.BuildText(text, color: SchemeColor.Link); var rect = gui.lastRect; switch (gui.action) { case ImGuiAction.MouseMove: gui.ConsumeMouseOver(rect, RenderingUtils.cursorHand); break; case ImGuiAction.MouseDown: if (gui.actionParameter == SDL.SDL_BUTTON_LEFT) { gui.ConsumeMouseDown(rect); } break; case ImGuiAction.MouseUp: if (gui.ConsumeMouseUp(rect)) { return(true); } break; case ImGuiAction.Build: if (gui.IsMouseOver(rect)) { gui.DrawRectangle(new Rect(rect.X, rect.Bottom - 0.2f, rect.Width, 0.1f), SchemeColor.Link); } break; } return(false); }
public static Event BuildButton(this ImGui gui, Rect rect, SchemeColor normal, SchemeColor over, SchemeColor down = SchemeColor.None, uint button = SDL.SDL_BUTTON_LEFT) { if (button == 0) { button = (uint)InputSystem.Instance.mouseDownButton; } switch (gui.action) { case ImGuiAction.MouseMove: var wasOver = gui.IsMouseOver(rect); return(gui.ConsumeMouseOver(rect, RenderingUtils.cursorHand) && !wasOver ? Event.MouseOver : Event.None); case ImGuiAction.MouseDown: return(gui.actionParameter == button && gui.ConsumeMouseDown(rect, button) ? Event.MouseDown : Event.None); case ImGuiAction.MouseUp: return(gui.actionParameter == button && gui.ConsumeMouseUp(rect, true, button) ? Event.Click : Event.None); case ImGuiAction.Build: var color = gui.IsMouseOver(rect) ? (down != SchemeColor.None && gui.IsMouseDown(rect, button)) ? down : over : normal; gui.DrawRectangle(rect, color); return(Event.None); default: return(Event.None); } }
public static bool BuildErrorRow(this ImGui gui, string text) { var closed = false; using (gui.EnterRow(allocator: RectAllocator.RightRow, textColor: SchemeColor.ErrorText)) { if (gui.BuildButton(Icon.Close, size: 1f, over: SchemeColor.ErrorAlt)) { closed = true; } gui.RemainingRow().BuildText(text, align: RectAlignment.Middle); } if (gui.isBuilding) { gui.DrawRectangle(gui.lastRect, SchemeColor.Error); } return(closed); }
private void BuildHeaderResizer(ImGui gui, DataColumn <TData> column, Rect rect) { switch (gui.action) { case ImGuiAction.Build: var center = rect.X + rect.Width * 0.5f; if (gui.IsMouseDown(rect, SDL.SDL_BUTTON_LEFT)) { var unclampedWidth = gui.mousePosition.X - rect.Center.X + column.width; var clampedWidth = MathUtils.Clamp(unclampedWidth, column.minWidth, column.maxWidth); center = center - column.width + clampedWidth; } var viewRect = new Rect(center - 0.1f, rect.Y, 0.2f, rect.Height); gui.DrawRectangle(viewRect, SchemeColor.GreyAlt); break; case ImGuiAction.MouseMove: gui.ConsumeMouseOver(rect, RenderingUtils.cursorHorizontalResize); if (gui.IsMouseDown(rect, SDL.SDL_BUTTON_LEFT)) { gui.Rebuild(); } break; case ImGuiAction.MouseDown: gui.ConsumeMouseDown(rect, cursor: RenderingUtils.cursorHorizontalResize); break; case ImGuiAction.MouseUp: if (gui.ConsumeMouseUp(rect, false)) { var unclampedWidth = gui.mousePosition.X - rect.Center.X + column.width; column.width = MathUtils.Clamp(unclampedWidth, column.minWidth, column.maxWidth); contentGui?.Rebuild(); } break; } }
public bool BuildTextInput(string text, out string newText, string placeholder, FontFile.FontSize fontSize, bool delayed, Icon icon, Padding padding, RectAlignment alignment, SchemeColor color) { newText = text; Rect textRect, realTextRect; using (gui.EnterGroup(padding, RectAllocator.LeftRow)) { var lineSize = gui.PixelsToUnits(fontSize.lineSize); if (icon != Icon.None) { gui.BuildIcon(icon, lineSize, color + 3); } textRect = gui.RemainingRow(0.3f).AllocateRect(0, lineSize, RectAlignment.MiddleFullRow); } var boundingRect = gui.lastRect; var focused = rect == boundingRect; if (focused && this.text == null) { this.text = text ?? ""; SetCaret(0, this.text.Length); } switch (gui.action) { case ImGuiAction.MouseDown: if (gui.actionParameter != SDL.SDL_BUTTON_LEFT) { break; } if (gui.ConsumeMouseDown(boundingRect)) { SetFocus(boundingRect, text ?? ""); GetTextParameters(this.text, textRect, fontSize, alignment, out _, out _, out _, out realTextRect); SetCaret(FindCaretIndex(text, gui.mousePosition.X - realTextRect.X, fontSize, textRect.Width)); } break; case ImGuiAction.MouseMove: if (focused && gui.actionParameter == SDL.SDL_BUTTON_LEFT) { GetTextParameters(this.text, textRect, fontSize, alignment, out _, out _, out _, out realTextRect); SetCaret(caret, FindCaretIndex(this.text, gui.mousePosition.X - realTextRect.X, fontSize, textRect.Width)); } gui.ConsumeMouseOver(boundingRect, RenderingUtils.cursorCaret, false); break; case ImGuiAction.Build: var textColor = color + 2; string textToBuild; if (focused) { textToBuild = this.text; } else if (string.IsNullOrEmpty(text)) { textToBuild = placeholder; textColor = color + 3; } else { textToBuild = text; } GetTextParameters(textToBuild, textRect, fontSize, alignment, out var cachedText, out var scale, out var textWidth, out realTextRect); if (cachedText != null) { gui.DrawRenderable(realTextRect, cachedText, textColor); } if (focused) { if (selectionAnchor != caret) { var left = GetCharacterPosition(Math.Min(selectionAnchor, caret), fontSize, textWidth) * scale; var right = GetCharacterPosition(Math.Max(selectionAnchor, caret), fontSize, textWidth) * scale; gui.DrawRectangle(new Rect(left + realTextRect.X, realTextRect.Y, right - left, realTextRect.Height), SchemeColor.TextSelection); } else { if (nextCaretTimer <= Ui.time) { nextCaretTimer = Ui.time + 500; caretVisible = !caretVisible; } gui.SetNextRebuild(nextCaretTimer); if (caretVisible) { var caretPosition = GetCharacterPosition(caret, fontSize, textWidth) * scale; gui.DrawRectangle(new Rect(caretPosition + realTextRect.X - 0.05f, realTextRect.Y, 0.1f, realTextRect.Height), color + 2); } } } gui.DrawRectangle(boundingRect, color); break; } if (boundingRect == prevRect) { var changed = text != prevText; if (changed) { newText = prevText; } prevRect = default; prevText = null; return(changed); } if (focused && !delayed && this.text != text) { newText = this.text; return(true); } return(false); }