using System.Numerics; using ImGuiNET; using ImGuiInternal = ImGuiNET.Internal.ImGui; namespace gaemstone.Client.Utility; public static class ImGuiUtility { public static bool UIButtonToggle(int index, string label, string tooltip, ref bool enabled) { if (UIButton(index, label, tooltip, enabled)) enabled = !enabled; return enabled; } public static bool UIButton(int index, string label, string tooltip, bool active) { var start = new Vector2(4, 4); var buttonSize = new Vector2(32, 32); var pos = start + new Vector2(buttonSize.X + 4, 0) * index; ImGui.SetNextWindowPos(pos, ImGuiCond.Always); ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, Vector2.Zero); ImGui.Begin("UIToggle" + index, ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoBringToFrontOnFocus | ImGuiWindowFlags.NoDocking); ImGui.PopStyleVar(); if (!active) ImGui.PushStyleVar(ImGuiStyleVar.Alpha, 0.6f); var clicked = ImGui.Button(label, buttonSize); if (!active) ImGui.PopStyleVar(); if (ImGui.IsItemHovered()) ImGui.SetTooltip(tooltip); ImGui.End(); return clicked; } // public static void AdvancedTooltip(string brief, string detail) // { // if (!ImGui.IsItemHovered()) return; // ImGui.BeginTooltip(); // ImGui.PushFont(ImGui.GetIO().Fonts.Fonts[1]); // ImGui.TextUnformatted(brief); // ImGui.PopFont(); // ImGui.Text(detail); // ImGui.EndTooltip(); // } public static void TextCentered(string text, Vector2 size) { var pos = ImGui.GetCursorScreenPos(); ImGuiInternal.ItemSize(size, 0); if (!ImGuiInternal.ItemAdd(new() { Min = pos, Max = pos + size }, 0)) return; var textSize = ImGui.CalcTextSize(text); var textPos = pos + (size - textSize) / 2; ImGuiInternal.RenderText(textPos, text); } }