From 8fc93c4c525cf377ed16ccb29c72047cb98bf160 Mon Sep 17 00:00:00 2001 From: ItsBexy Date: Thu, 24 Oct 2024 16:37:04 -0600 Subject: [PATCH] Switch to `TextUnformatted()` Plus other noodling with GUI business. I considered adding some of the helper features I use here to `ImGuiComponents`, but it would have quickly started expanding into a separate project of its own, and I didn't really want to entangle that with this PR right now. --- .../Internal/UiDebug2/Browsing/AddonTree.cs | 2 +- .../Internal/UiDebug2/Browsing/Events.cs | 11 +- .../UiDebug2/Browsing/NodeTree.Component.cs | 14 +- .../UiDebug2/Browsing/NodeTree.Editor.cs | 4 +- .../UiDebug2/Browsing/NodeTree.Res.cs | 4 +- .../UiDebug2/Browsing/NodeTree.Text.cs | 8 +- .../Browsing/TimelineTree.KeyGroupColumn.cs | 2 +- .../UiDebug2/Browsing/TimelineTree.cs | 2 +- .../Internal/UiDebug2/ElementSelector.cs | 130 +++++++++--------- .../Internal/UiDebug2/UiDebug2.Sidebar.cs | 2 - .../Internal/UiDebug2/Utility/Gui.cs | 40 ++++-- 11 files changed, 116 insertions(+), 103 deletions(-) diff --git a/Dalamud/Interface/Internal/UiDebug2/Browsing/AddonTree.cs b/Dalamud/Interface/Internal/UiDebug2/Browsing/AddonTree.cs index 6d6377530..2823a2058 100644 --- a/Dalamud/Interface/Internal/UiDebug2/Browsing/AddonTree.cs +++ b/Dalamud/Interface/Internal/UiDebug2/Browsing/AddonTree.cs @@ -114,7 +114,7 @@ public unsafe partial class AddonTree : IDisposable var isVisible = addon->IsVisible; - ImGui.Text($"{this.AddonName}"); + ImGui.TextUnformatted($"{this.AddonName}"); ImGui.SameLine(); ImGui.SameLine(); diff --git a/Dalamud/Interface/Internal/UiDebug2/Browsing/Events.cs b/Dalamud/Interface/Internal/UiDebug2/Browsing/Events.cs index a422e4db6..6869763c8 100644 --- a/Dalamud/Interface/Internal/UiDebug2/Browsing/Events.cs +++ b/Dalamud/Interface/Internal/UiDebug2/Browsing/Events.cs @@ -27,6 +27,7 @@ public static class Events } using var tree = ImRaii.TreeNode($"Events##{(nint)node:X}eventTree"); + if (tree) { using (ImRaii.Table($"##{(nint)node:X}eventTable", 7, Resizable | SizingFixedFit | Borders | RowBg)) @@ -45,15 +46,15 @@ public static class Events while (evt != null) { ImGui.TableNextColumn(); - ImGui.Text($"{i++}"); + ImGui.TextUnformatted($"{i++}"); ImGui.TableNextColumn(); - ImGui.Text($"{evt->Type}"); + ImGui.TextUnformatted($"{evt->Type}"); ImGui.TableNextColumn(); - ImGui.Text($"{evt->Param}"); + ImGui.TextUnformatted($"{evt->Param}"); ImGui.TableNextColumn(); - ImGui.Text($"{evt->Flags}"); + ImGui.TextUnformatted($"{evt->Flags}"); ImGui.TableNextColumn(); - ImGui.Text($"{evt->Unk29}"); + ImGui.TextUnformatted($"{evt->Unk29}"); ImGui.TableNextColumn(); Gui.ClickToCopyText($"{(nint)evt->Target:X}"); ImGui.TableNextColumn(); diff --git a/Dalamud/Interface/Internal/UiDebug2/Browsing/NodeTree.Component.cs b/Dalamud/Interface/Internal/UiDebug2/Browsing/NodeTree.Component.cs index 026933631..d9fcf52cc 100644 --- a/Dalamud/Interface/Internal/UiDebug2/Browsing/NodeTree.Component.cs +++ b/Dalamud/Interface/Internal/UiDebug2/Browsing/NodeTree.Component.cs @@ -81,19 +81,19 @@ internal unsafe class ComponentNodeTree : ResNodeTree { case TextInput: var textInputComponent = (AtkComponentTextInput*)this.Component; - ImGui.Text( + ImGui.TextUnformatted( $"InputBase Text1: {Marshal.PtrToStringAnsi(new(textInputComponent->AtkComponentInputBase.UnkText1.StringPtr))}"); - ImGui.Text( + ImGui.TextUnformatted( $"InputBase Text2: {Marshal.PtrToStringAnsi(new(textInputComponent->AtkComponentInputBase.UnkText2.StringPtr))}"); - ImGui.Text( + ImGui.TextUnformatted( $"Text1: {Marshal.PtrToStringAnsi(new(textInputComponent->UnkText01.StringPtr))}"); - ImGui.Text( + ImGui.TextUnformatted( $"Text2: {Marshal.PtrToStringAnsi(new(textInputComponent->UnkText02.StringPtr))}"); - ImGui.Text( + ImGui.TextUnformatted( $"Text3: {Marshal.PtrToStringAnsi(new(textInputComponent->UnkText03.StringPtr))}"); - ImGui.Text( + ImGui.TextUnformatted( $"Text4: {Marshal.PtrToStringAnsi(new(textInputComponent->UnkText04.StringPtr))}"); - ImGui.Text( + ImGui.TextUnformatted( $"Text5: {Marshal.PtrToStringAnsi(new(textInputComponent->UnkText05.StringPtr))}"); break; case List: diff --git a/Dalamud/Interface/Internal/UiDebug2/Browsing/NodeTree.Editor.cs b/Dalamud/Interface/Internal/UiDebug2/Browsing/NodeTree.Editor.cs index ef30ea151..6cb178bd7 100644 --- a/Dalamud/Interface/Internal/UiDebug2/Browsing/NodeTree.Editor.cs +++ b/Dalamud/Interface/Internal/UiDebug2/Browsing/NodeTree.Editor.cs @@ -370,8 +370,8 @@ internal unsafe partial class TextNodeTree var hAlign = (int)alignment % 3; var vAlign = ((int)alignment - hAlign) / 3; - var hAlignInput = IconSelectInput($"{label}H", ref hAlign, [0, 1, 2], [AlignLeft, AlignCenter, AlignRight]); - var vAlignInput = IconSelectInput($"{label}V", ref vAlign, [0, 1, 2], [ArrowsUpToLine, GripLines, ArrowsDownToLine]); + var hAlignInput = IconButtonSelect($"{label}H", ref hAlign, [0, 1, 2], [AlignLeft, AlignCenter, AlignRight]); + var vAlignInput = IconButtonSelect($"{label}V", ref vAlign, [0, 1, 2], [ArrowsUpToLine, GripLines, ArrowsDownToLine]); if (hAlignInput || vAlignInput) { diff --git a/Dalamud/Interface/Internal/UiDebug2/Browsing/NodeTree.Res.cs b/Dalamud/Interface/Internal/UiDebug2/Browsing/NodeTree.Res.cs index 366e3d36d..a333940c1 100644 --- a/Dalamud/Interface/Internal/UiDebug2/Browsing/NodeTree.Res.cs +++ b/Dalamud/Interface/Internal/UiDebug2/Browsing/NodeTree.Res.cs @@ -90,7 +90,7 @@ internal unsafe partial class ResNodeTree : IDisposable NodeType.ClippingMask => new ClippingMaskNodeTree(node, addonTree), NodeType.Counter => new CounterNodeTree(node, addonTree), NodeType.Collision => new CollisionNodeTree(node, addonTree), - _ => new ResNodeTree(node, addonTree) + _ => new ResNodeTree(node, addonTree), }; /// @@ -163,7 +163,7 @@ internal unsafe partial class ResNodeTree : IDisposable /// internal void WriteTreeHeading() { - ImGui.Text(this.GetHeaderText()); + ImGui.TextUnformatted(this.GetHeaderText()); this.PrintFieldNames(); } diff --git a/Dalamud/Interface/Internal/UiDebug2/Browsing/NodeTree.Text.cs b/Dalamud/Interface/Internal/UiDebug2/Browsing/NodeTree.Text.cs index 257ce5aa3..d9b4e7986 100644 --- a/Dalamud/Interface/Internal/UiDebug2/Browsing/NodeTree.Text.cs +++ b/Dalamud/Interface/Internal/UiDebug2/Browsing/NodeTree.Text.cs @@ -57,7 +57,7 @@ internal unsafe partial class TextNodeTree : ResNodeTree Color = this.TxtNode->TextColor.RGBA, EdgeColor = this.TxtNode->EdgeColor.RGBA, ForceEdgeColor = true, - EdgeStrength = 1f + EdgeStrength = 1f, }; #pragma warning disable SeStringRenderer @@ -66,7 +66,7 @@ internal unsafe partial class TextNodeTree : ResNodeTree } catch { - ImGui.Text(Marshal.PtrToStringAnsi(new(this.NodeText.StringPtr)) ?? ""); + ImGui.TextUnformatted(Marshal.PtrToStringAnsi(new(this.NodeText.StringPtr)) ?? string.Empty); } PrintFieldValuePairs( @@ -98,7 +98,7 @@ internal unsafe partial class TextNodeTree : ResNodeTree for (var i = 0; i < seString.Payloads.Count; i++) { var payload = seString.Payloads[i]; - ImGui.Text($"[{i}]"); + ImGui.TextUnformatted($"[{i}]"); ImGui.SameLine(); switch (payload.Type) { @@ -110,7 +110,7 @@ internal unsafe partial class TextNodeTree : ResNodeTree default: { - ImGui.Text(payload.ToString()); + ImGui.TextUnformatted(payload.ToString()); break; } } diff --git a/Dalamud/Interface/Internal/UiDebug2/Browsing/TimelineTree.KeyGroupColumn.cs b/Dalamud/Interface/Internal/UiDebug2/Browsing/TimelineTree.KeyGroupColumn.cs index e638cca40..2ba416b4f 100644 --- a/Dalamud/Interface/Internal/UiDebug2/Browsing/TimelineTree.KeyGroupColumn.cs +++ b/Dalamud/Interface/Internal/UiDebug2/Browsing/TimelineTree.KeyGroupColumn.cs @@ -66,7 +66,7 @@ public readonly partial struct TimelineTree /// The default print function, if none is specified. /// /// The value to print. - public static void PlainTextCell(T value) => ImGui.Text($"{value}"); + public static void PlainTextCell(T value) => ImGui.TextUnformatted($"{value}"); /// /// Adds a value to this column. diff --git a/Dalamud/Interface/Internal/UiDebug2/Browsing/TimelineTree.cs b/Dalamud/Interface/Internal/UiDebug2/Browsing/TimelineTree.cs index 111b92597..8e21f4030 100644 --- a/Dalamud/Interface/Internal/UiDebug2/Browsing/TimelineTree.cs +++ b/Dalamud/Interface/Internal/UiDebug2/Browsing/TimelineTree.cs @@ -138,7 +138,7 @@ public readonly unsafe partial struct TimelineTree return; } - var rotColumn = new KeyGroupColumn("Rotation", static r => ImGui.Text($"{r * (180d / Math.PI):F1}°")); + var rotColumn = new KeyGroupColumn("Rotation", static r => ImGui.TextUnformatted($"{r * (180d / Math.PI):F1}°")); for (var f = 0; f < keyGroup.KeyFrameCount; f++) { diff --git a/Dalamud/Interface/Internal/UiDebug2/ElementSelector.cs b/Dalamud/Interface/Internal/UiDebug2/ElementSelector.cs index 2c6a16893..7f603fdac 100644 --- a/Dalamud/Interface/Internal/UiDebug2/ElementSelector.cs +++ b/Dalamud/Interface/Internal/UiDebug2/ElementSelector.cs @@ -81,26 +81,26 @@ internal unsafe class ElementSelector : IDisposable { using (ImRaii.Child("###sidebar_elementSelector", new(250, 0), true)) { - using var f = ImRaii.PushFont(IconFont); - using var col = ImRaii.PushColor(Text, new Vector4(1, 1, 0.2f, 1), this.Active); - - if (ImGui.Button($"{(char)ObjectUngroup}")) + using (ImRaii.PushFont(IconFont)) { - this.Active = !this.Active; - } - - if (Countdown > 0) - { - Countdown -= 1; - if (Countdown < 0) + using (ImRaii.PushColor(Text, new Vector4(1, 1, 0.2f, 1), this.Active)) { - Countdown = 0; + if (ImGui.Button($"{(char)ObjectUngroup}")) + { + this.Active = !this.Active; + } + + if (Countdown > 0) + { + Countdown -= 1; + if (Countdown < 0) + { + Countdown = 0; + } + } } } - col.Pop(); - f.Pop(); - if (ImGui.IsItemHovered()) { ImGui.SetTooltip("Element Selector"); @@ -151,67 +151,69 @@ internal unsafe class ElementSelector : IDisposable var mousePos = ImGui.GetMousePos() - MainViewport.Pos; var addonResults = GetAtkUnitBaseAtPosition(mousePos); - using var col = ImRaii.PushColor(WindowBg, new Vector4(0.5f)); - using (ImRaii.Child("noClick", new(800, 2000), false, NoInputs | NoBackground | NoScrollWithMouse)) + using (ImRaii.PushColor(WindowBg, new Vector4(0.5f))) { - using (ImRaii.Group()) + using (ImRaii.Child("noClick", new(800, 2000), false, NoInputs | NoBackground | NoScrollWithMouse)) { - Gui.PrintFieldValuePair("Mouse Position", $"{mousePos.X}, {mousePos.Y}"); - ImGui.Spacing(); - ImGui.Text("RESULTS:\n"); - - var i = 0; - foreach (var a in addonResults) + using (ImRaii.Group()) { - var name = a.Addon->NameString; - ImGui.Text($"[Addon] {name}"); - ImGui.Indent(15); - foreach (var n in a.Nodes) + Gui.PrintFieldValuePair("Mouse Position", $"{mousePos.X}, {mousePos.Y}"); + ImGui.Spacing(); + ImGui.Text("RESULTS:\n"); + + var i = 0; + foreach (var a in addonResults) { - var nSelected = i++ == this.index; - - PrintNodeHeaderOnly(n.Node, nSelected, a.Addon); - - if (nSelected && ImGui.IsMouseClicked(ImGuiMouseButton.Left)) + var name = a.Addon->NameString; + ImGui.TextUnformatted($"[Addon] {name}"); + ImGui.Indent(15); + foreach (var n in a.Nodes) { - this.Active = false; + var nSelected = i++ == this.index; - this.uiDebug2.SelectedAddonName = a.Addon->NameString; + PrintNodeHeaderOnly(n.Node, nSelected, a.Addon); - var ptrList = new List { (nint)n.Node }; - - var nextNode = n.Node->ParentNode; - while (nextNode != null) + if (nSelected && ImGui.IsMouseClicked(ImGuiMouseButton.Left)) { - ptrList.Add((nint)nextNode); - nextNode = nextNode->ParentNode; + this.Active = false; + + this.uiDebug2.SelectedAddonName = a.Addon->NameString; + + var ptrList = new List { (nint)n.Node }; + + var nextNode = n.Node->ParentNode; + while (nextNode != null) + { + ptrList.Add((nint)nextNode); + nextNode = nextNode->ParentNode; + } + + SearchResults = [.. ptrList]; + Countdown = 100; + Scrolled = false; } - SearchResults = [.. ptrList]; - Countdown = 100; - Scrolled = false; + if (nSelected) + { + n.NodeBounds.DrawFilled(new(1, 1, 0.2f, 1)); + } } - if (nSelected) + ImGui.Indent(-15); + } + + if (i != 0) + { + this.index -= (int)ImGui.GetIO().MouseWheel; + while (this.index < 0) { - n.NodeBounds.DrawFilled(new(1, 1, 0.2f, 1)); + this.index += i; } - } - ImGui.Indent(-15); - } - - if (i != 0) - { - this.index -= (int)ImGui.GetIO().MouseWheel; - while (this.index < 0) - { - this.index += i; - } - - while (this.index >= i) - { - this.index -= i; + while (this.index >= i) + { + this.index -= i; + } } } } @@ -393,8 +395,10 @@ internal unsafe class ElementSelector : IDisposable return; } - using var col = ImRaii.PushColor(Text, selected ? new Vector4(1, 1, 0.2f, 1) : new(0.6f, 0.6f, 0.6f, 1)); - ResNodeTree.GetOrCreate(node, tree).WriteTreeHeading(); + using (ImRaii.PushColor(Text, selected ? new Vector4(1, 1, 0.2f, 1) : new(0.6f, 0.6f, 0.6f, 1))) + { + ResNodeTree.GetOrCreate(node, tree).WriteTreeHeading(); + } } private void PerformSearch(nint address) diff --git a/Dalamud/Interface/Internal/UiDebug2/UiDebug2.Sidebar.cs b/Dalamud/Interface/Internal/UiDebug2/UiDebug2.Sidebar.cs index 4c6e08409..4253f13bc 100644 --- a/Dalamud/Interface/Internal/UiDebug2/UiDebug2.Sidebar.cs +++ b/Dalamud/Interface/Internal/UiDebug2/UiDebug2.Sidebar.cs @@ -98,8 +98,6 @@ internal unsafe partial class UiDebug2 { this.DrawUnitListOption(unitListBaseAddr, unit); } - - ; } } diff --git a/Dalamud/Interface/Internal/UiDebug2/Utility/Gui.cs b/Dalamud/Interface/Internal/UiDebug2/Utility/Gui.cs index c203090ec..954e5cb72 100644 --- a/Dalamud/Interface/Internal/UiDebug2/Utility/Gui.cs +++ b/Dalamud/Interface/Internal/UiDebug2/Utility/Gui.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Numerics; using Dalamud.Interface.Components; -using Dalamud.Interface.Utility; using Dalamud.Interface.Utility.Raii; using FFXIVClientStructs.FFXIV.Client.Graphics; @@ -27,20 +26,19 @@ internal static class Gui /// A list of all options. /// A list of icons corresponding to the options. /// true if a button is clicked. - internal static unsafe bool IconSelectInput(string label, ref T val, List options, List icons) + internal static unsafe bool IconButtonSelect(string label, ref T val, List options, List icons) { var ret = false; + for (var i = 0; i < options.Count; i++) { - var option = options[i]; - var icon = icons[i]; - if (i > 0) { - ImGui.SameLine(); - ImGui.SetCursorPosX(ImGui.GetCursorPosX() - ((ImGui.GetFontSize() / -6f) + 7f)); + ImGui.SameLine(0, ImGui.GetStyle().ItemInnerSpacing.X); } + var option = options[i]; + var icon = icons.Count > i ? icons[i] : FontAwesomeIcon.Question; var color = *ImGui.GetStyleColorVec4(val is not null && val.Equals(option) ? ButtonActive : Button); if (ImGuiComponents.IconButton($"{label}{option}{i}", icon, color)) @@ -61,7 +59,7 @@ internal static class Gui /// Whether to enable click-to-copy. internal static void PrintFieldValuePair(string fieldName, string value, bool copy = true) { - ImGui.Text($"{fieldName}:"); + ImGui.TextUnformatted($"{fieldName}:"); ImGui.SameLine(); if (copy) { @@ -119,25 +117,37 @@ internal static class Gui 0.5f) * vector4.W; } - /// + /// + /// Print out text that can be copied when clicked. + /// + /// The text to show. + /// The text to copy when clicked. internal static void ClickToCopyText(string text, string? textCopy = null) { using (ImRaii.PushColor(Text, new Vector4(0.6f, 0.6f, 0.6f, 1))) { - ImGuiHelpers.ClickToCopyText(text, textCopy); + textCopy ??= text; + ImGui.TextUnformatted($"{text}"); } if (ImGui.IsItemHovered()) { using (ImRaii.Tooltip()) { - using var f = ImRaii.PushFont(UiBuilder.IconFont); - ImGui.Text(FontAwesomeIcon.Copy.ToIconString()); - f.Pop(); + using (ImRaii.PushFont(UiBuilder.IconFont)) + { + ImGui.TextUnformatted(FontAwesomeIcon.Copy.ToIconString()); + } + ImGui.SameLine(); - ImGui.Text($"{textCopy ?? text}"); + ImGui.TextUnformatted($"{textCopy}"); } } + + if (ImGui.IsItemClicked()) + { + ImGui.SetClipboardText($"{textCopy}"); + } } /// @@ -161,7 +171,7 @@ internal static class Gui using (ImRaii.Tooltip()) { - ImGui.Text(tooltips[index]); + ImGui.TextUnformatted(tooltips[index]); } return true;