From dac91cb5eef17921e1303b491597c3439249cdb8 Mon Sep 17 00:00:00 2001 From: Anna Date: Thu, 8 Apr 2021 00:53:19 -0400 Subject: [PATCH] feat: update elements and swaps to use tables --- HUD Manager/HUD Manager.csproj | 12 +-- .../Structs/Options/TargetBarOptions.cs | 2 +- HUD Manager/Ui/Editor/Tabs/HudElements.cs | 95 +++++++++++-------- HUD Manager/Ui/Swaps.cs | 47 +++++---- 4 files changed, 85 insertions(+), 71 deletions(-) diff --git a/HUD Manager/HUD Manager.csproj b/HUD Manager/HUD Manager.csproj index cbebcb9..36195fb 100755 --- a/HUD Manager/HUD Manager.csproj +++ b/HUD Manager/HUD Manager.csproj @@ -8,27 +8,27 @@ enable - + $(AppData)\XIVLauncher\addon\Hooks\dev\Dalamud.dll False - + $(AppData)\XIVLauncher\addon\Hooks\dev\ImGui.NET.dll False - + $(AppData)\XIVLauncher\addon\Hooks\dev\ImGuiScene.dll False - + $(AppData)\XIVLauncher\addon\Hooks\dev\Lumina.dll False - + $(AppData)\XIVLauncher\addon\Hooks\dev\Lumina.Excel.dll False - + $(AppData)\XIVLauncher\addon\Hooks\dev\Newtonsoft.Json.dll False diff --git a/HUD Manager/Structs/Options/TargetBarOptions.cs b/HUD Manager/Structs/Options/TargetBarOptions.cs index 7efb614..d05777d 100755 --- a/HUD Manager/Structs/Options/TargetBarOptions.cs +++ b/HUD Manager/Structs/Options/TargetBarOptions.cs @@ -4,7 +4,7 @@ public bool ShowIndependently { get => this._options[0] == 1; - set => this._options[0] = value ? 1 : 0; + set => this._options[0] = value ? (byte) 1 : (byte) 0; } public TargetBarOptions(byte[] options) { diff --git a/HUD Manager/Ui/Editor/Tabs/HudElements.cs b/HUD Manager/Ui/Editor/Tabs/HudElements.cs index f6f477b..0dc4e19 100755 --- a/HUD Manager/Ui/Editor/Tabs/HudElements.cs +++ b/HUD Manager/Ui/Editor/Tabs/HudElements.cs @@ -84,23 +84,23 @@ namespace HUD_Manager.Ui.Editor.Tabs { continue; } - var maxSettingWidth = 0f; - void DrawSettingName(string name) { - maxSettingWidth = Math.Max(maxSettingWidth, ImGui.CalcTextSize(name).X); ImGui.TextUnformatted(name); - ImGui.NextColumn(); + ImGui.TableNextColumn(); } - ImGui.Columns(3); - ImGui.SetColumnWidth(0, ImGui.CalcTextSize("Enabled").X + ImGui.GetStyle().ItemSpacing.X * 2); + const ImGuiTableFlags flags = ImGuiTableFlags.BordersInner + | ImGuiTableFlags.PadOuterX + | ImGuiTableFlags.SizingFixedFit + | ImGuiTableFlags.RowBg; + if (!ImGui.BeginTable($"uimanager-element-table-{kind}", 3, flags)) { + continue; + } - ImGui.TextUnformatted("Enabled"); - ImGui.NextColumn(); - - DrawSettingName("Setting"); - - ImGui.TextUnformatted("Control"); + ImGui.TableSetupColumn("Enabled"); + ImGui.TableSetupColumn("Setting"); + ImGui.TableSetupColumn("Control", ImGuiTableColumnFlags.WidthStretch); + ImGui.TableHeadersRow(); ImGui.SameLine(ImGui.GetContentRegionAvail().X - ImGui.GetStyle().ItemInnerSpacing.X - ImGui.GetStyle().ItemSpacing.X * 6); if (ImGuiExt.IconButton(FontAwesomeIcon.Search, $"uimanager-preview-element-{kind}")) { @@ -120,10 +120,12 @@ namespace HUD_Manager.Ui.Editor.Tabs { ImGuiExt.HoverTooltip("Remove this element from this layout"); - ImGui.Separator(); + ImGui.TableNextRow(); - void DrawEnabledCheckbox(ElementKind kind, ElementComponent component, ref bool update) { - ImGui.NextColumn(); + void DrawEnabledCheckbox(ElementKind kind, ElementComponent component, ref bool update, bool nextCol = true) { + if (nextCol) { + ImGui.TableNextColumn(); + } var enabled = element[component]; if (ImGui.Checkbox($"###{component}-enabled-{kind}", ref enabled)) { @@ -133,11 +135,13 @@ namespace HUD_Manager.Ui.Editor.Tabs { update = true; } - ImGui.NextColumn(); + ImGui.TableNextColumn(); } + ImGui.TableSetColumnIndex(0); + if (!kind.IsJobGauge()) { - DrawEnabledCheckbox(element.Id, ElementComponent.Visibility, ref update); + DrawEnabledCheckbox(element.Id, ElementComponent.Visibility, ref update, false); DrawSettingName("Visibility"); var keyboard = element[VisibilityFlags.Keyboard]; @@ -152,10 +156,12 @@ namespace HUD_Manager.Ui.Editor.Tabs { element[VisibilityFlags.Gamepad] = gamepad; update = true; } + + ImGui.TableNextRow(); + ImGui.TableSetColumnIndex(0); } - ImGui.NextColumn(); - ImGui.NextColumn(); + ImGui.TableNextColumn(); DrawSettingName("Measured from"); @@ -175,6 +181,7 @@ namespace HUD_Manager.Ui.Editor.Tabs { } ImGui.PopItemWidth(); + ImGui.TableNextRow(); DrawEnabledCheckbox(element.Id, ElementComponent.X, ref update); DrawSettingName("X"); @@ -191,6 +198,7 @@ namespace HUD_Manager.Ui.Editor.Tabs { } ImGui.PopItemWidth(); + ImGui.TableNextRow(); DrawEnabledCheckbox(element.Id, ElementComponent.Y, ref update); DrawSettingName("Y"); @@ -220,6 +228,7 @@ namespace HUD_Manager.Ui.Editor.Tabs { } ImGui.PopItemWidth(); + ImGui.TableNextRow(); DrawEnabledCheckbox(element.Id, ElementComponent.Y, ref update); DrawSettingName("Y"); @@ -237,6 +246,8 @@ namespace HUD_Manager.Ui.Editor.Tabs { ImGui.PopItemWidth(); } + ImGui.TableNextRow(); + DrawEnabledCheckbox(element.Id, ElementComponent.Scale, ref update); DrawSettingName("Scale"); @@ -256,6 +267,7 @@ namespace HUD_Manager.Ui.Editor.Tabs { } ImGui.PopItemWidth(); + ImGui.TableNextRow(); if (!kind.IsJobGauge()) { DrawEnabledCheckbox(element.Id, ElementComponent.Opacity, ref update); @@ -269,13 +281,14 @@ namespace HUD_Manager.Ui.Editor.Tabs { } ImGui.PopItemWidth(); + ImGui.TableNextRow(); } if (kind == ElementKind.TargetBar) { var targetBarOpts = new TargetBarOptions(element.Options); - ImGui.NextColumn(); - ImGui.NextColumn(); + ImGui.TableNextColumn(); + ImGui.TableNextColumn(); DrawSettingName("Display target information independently"); ImGui.PushItemWidth(-1); @@ -286,13 +299,14 @@ namespace HUD_Manager.Ui.Editor.Tabs { } ImGui.PopItemWidth(); + ImGui.TableNextRow(); } if (kind == ElementKind.StatusEffects) { var statusOpts = new StatusOptions(element.Options); - ImGui.NextColumn(); - ImGui.NextColumn(); + ImGui.TableNextColumn(); + ImGui.TableNextColumn(); DrawSettingName("Style"); ImGui.PushItemWidth(-1); @@ -310,13 +324,14 @@ namespace HUD_Manager.Ui.Editor.Tabs { } ImGui.PopItemWidth(); + ImGui.TableNextRow(); } if (kind == ElementKind.StatusInfoEnhancements || kind == ElementKind.StatusInfoEnfeeblements || kind == ElementKind.StatusInfoOther) { var statusOpts = new StatusInfoOptions(kind, element.Options); - ImGui.NextColumn(); - ImGui.NextColumn(); + ImGui.TableNextColumn(); + ImGui.TableNextColumn(); DrawSettingName("Layout"); ImGui.PushItemWidth(-1); @@ -334,9 +349,10 @@ namespace HUD_Manager.Ui.Editor.Tabs { } ImGui.PopItemWidth(); + ImGui.TableNextRow(); - ImGui.NextColumn(); - ImGui.NextColumn(); + ImGui.TableNextColumn(); + ImGui.TableNextColumn(); DrawSettingName("Alignment"); ImGui.PushItemWidth(-1); @@ -354,9 +370,10 @@ namespace HUD_Manager.Ui.Editor.Tabs { } ImGui.PopItemWidth(); + ImGui.TableNextRow(); - ImGui.NextColumn(); - ImGui.NextColumn(); + ImGui.TableNextColumn(); + ImGui.TableNextColumn(); DrawSettingName("Focusable by gamepad"); ImGui.PushItemWidth(-1); @@ -373,8 +390,8 @@ namespace HUD_Manager.Ui.Editor.Tabs { var hotbarOpts = new HotbarOptions(element); if (kind != ElementKind.PetHotbar) { - ImGui.NextColumn(); - ImGui.NextColumn(); + ImGui.TableNextColumn(); + ImGui.TableNextColumn(); DrawSettingName("Hotbar number"); ImGui.PushItemWidth(-1); @@ -385,13 +402,13 @@ namespace HUD_Manager.Ui.Editor.Tabs { } ImGui.PopItemWidth(); + ImGui.TableNextRow(); } - ImGui.NextColumn(); - ImGui.NextColumn(); + ImGui.TableNextColumn(); + ImGui.TableNextColumn(); DrawSettingName("Hotbar layout"); - ImGui.PushItemWidth(-1); if (ImGui.BeginCombo($"##hotbar-layout-{kind}", hotbarOpts.Layout.Name())) { foreach (var hotbarLayout in (HotbarLayout[]) Enum.GetValues(typeof(HotbarLayout))) { @@ -407,13 +424,14 @@ namespace HUD_Manager.Ui.Editor.Tabs { } ImGui.PopItemWidth(); + ImGui.TableNextRow(); } if (kind.IsJobGauge()) { var gaugeOpts = new GaugeOptions(element.Options); - ImGui.NextColumn(); - ImGui.NextColumn(); + ImGui.TableNextColumn(); + ImGui.TableNextColumn(); DrawSettingName("Simple"); ImGui.PushItemWidth(-1); @@ -424,11 +442,10 @@ namespace HUD_Manager.Ui.Editor.Tabs { } ImGui.PopItemWidth(); + ImGui.TableNextRow(); } - ImGui.SetColumnWidth(1, maxSettingWidth + ImGui.GetStyle().ItemSpacing.X * 2); - - ImGui.Columns(); + ImGui.EndTable(); } foreach (var remove in toRemove) { diff --git a/HUD Manager/Ui/Swaps.cs b/HUD Manager/Ui/Swaps.cs index d3f5fe7..140668f 100755 --- a/HUD Manager/Ui/Swaps.cs +++ b/HUD Manager/Ui/Swaps.cs @@ -72,31 +72,32 @@ namespace HUD_Manager.Ui { return; } - ImGui.Columns(4); + const ImGuiTableFlags flags = ImGuiTableFlags.Borders + & ~ImGuiTableFlags.BordersOuterV + | ImGuiTableFlags.PadOuterX + | ImGuiTableFlags.RowBg; + if (!ImGui.BeginTable("uimanager-swaps-table", 4, flags)) { + return; + } var conditions = new List(this.Plugin.Config.HudConditionMatches); if (this._editingConditionIndex == conditions.Count) { conditions.Add(new HudConditionMatch()); } - ImGui.TextUnformatted("Job"); - ImGui.NextColumn(); - - ImGui.TextUnformatted("State"); - ImGui.NextColumn(); - - ImGui.TextUnformatted("Layout"); - ImGui.NextColumn(); - - ImGui.TextUnformatted("Options"); - ImGui.NextColumn(); - - ImGui.Separator(); + ImGui.TableSetupColumn("Job"); + ImGui.TableSetupColumn("State"); + ImGui.TableSetupColumn("Layout"); + ImGui.TableSetupColumn("Options"); + ImGui.TableHeadersRow(); var addCondition = false; var actionedItemIndex = -1; var action = 0; // 0 for delete, otherwise move. foreach (var item in conditions.Select((cond, i) => new {cond, i})) { + ImGui.TableNextRow(); + ImGui.TableSetColumnIndex(0); + if (this._editingConditionIndex == item.i) { this._editingCondition ??= new HudConditionMatch(); ImGui.PushItemWidth(-1); @@ -115,7 +116,7 @@ namespace HUD_Manager.Ui { } ImGui.PopItemWidth(); - ImGui.NextColumn(); + ImGui.TableNextColumn(); ImGui.PushItemWidth(-1); if (ImGui.BeginCombo("##condition-edit-status", this._editingCondition.Status?.Name() ?? "Any")) { @@ -133,7 +134,7 @@ namespace HUD_Manager.Ui { } ImGui.PopItemWidth(); - ImGui.NextColumn(); + ImGui.TableNextColumn(); ImGui.PushItemWidth(-1); var comboPreview = this._editingCondition.LayoutId == Guid.Empty ? string.Empty : this.Plugin.Config.Layouts[this._editingCondition.LayoutId].Name; @@ -148,7 +149,7 @@ namespace HUD_Manager.Ui { } ImGui.PopItemWidth(); - ImGui.NextColumn(); + ImGui.TableNextColumn(); if (this._editingCondition.LayoutId != Guid.Empty) { if (ImGuiExt.IconButton(FontAwesomeIcon.Check, "condition-edit")) { @@ -168,14 +169,14 @@ namespace HUD_Manager.Ui { } } else { ImGui.TextUnformatted(item.cond.ClassJob ?? string.Empty); - ImGui.NextColumn(); + ImGui.TableNextColumn(); ImGui.TextUnformatted(item.cond.Status?.Name() ?? string.Empty); - ImGui.NextColumn(); + ImGui.TableNextColumn(); this.Plugin.Config.Layouts.TryGetValue(item.cond.LayoutId, out var condLayout); ImGui.TextUnformatted(condLayout?.Name ?? string.Empty); - ImGui.NextColumn(); + ImGui.TableNextColumn(); if (ImGuiExt.IconButton(FontAwesomeIcon.PencilAlt, $"{item.i}")) { this._editingConditionIndex = item.i; @@ -199,13 +200,9 @@ namespace HUD_Manager.Ui { action = 1; } } - - ImGui.NextColumn(); } - ImGui.Columns(1); - - ImGui.Separator(); + ImGui.EndTable(); ImGui.EndChild();