From 45b26030ccb54b5499e50b680a0a851867c6651f Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Fri, 24 Mar 2023 18:33:22 +0100 Subject: [PATCH] Fix button sizing for collapsible groups, fix default tab to be settings, fix bug with item spacing style. --- OtterGui | 2 +- Penumbra/UI/ModsTab/ModPanelEditTab.cs | 2 +- Penumbra/UI/ModsTab/ModPanelSettingsTab.cs | 42 +++++++++++++--------- Penumbra/UI/ModsTab/ModPanelTabBar.cs | 2 +- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/OtterGui b/OtterGui index 2cc26d04..cb99fa45 160000 --- a/OtterGui +++ b/OtterGui @@ -1 +1 @@ -Subproject commit 2cc26d04a0ec162b71544ff164d1ca768fb90c95 +Subproject commit cb99fa45c796cd1385281e3b690151623f4ed549 diff --git a/Penumbra/UI/ModsTab/ModPanelEditTab.cs b/Penumbra/UI/ModsTab/ModPanelEditTab.cs index c3c496cb..9697f162 100644 --- a/Penumbra/UI/ModsTab/ModPanelEditTab.cs +++ b/Penumbra/UI/ModsTab/ModPanelEditTab.cs @@ -221,7 +221,7 @@ public class ModPanelEditTab : ITab public static void Draw(Mod.Manager modManager, Mod mod) { - using var spacing = ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, UiHelpers.ScaleX3); + using var spacing = ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, new Vector2(UiHelpers.ScaleX3)); ImGui.SetNextItemWidth(UiHelpers.InputTextMinusButton3); ImGui.InputTextWithHint("##newGroup", "Add new option group...", ref _newGroupName, 256); ImGui.SameLine(); diff --git a/Penumbra/UI/ModsTab/ModPanelSettingsTab.cs b/Penumbra/UI/ModsTab/ModPanelSettingsTab.cs index 0127e140..adcbbf5d 100644 --- a/Penumbra/UI/ModsTab/ModPanelSettingsTab.cs +++ b/Penumbra/UI/ModsTab/ModPanelSettingsTab.cs @@ -225,7 +225,7 @@ public class ModPanelSettingsTab : ITab { using var id = ImRaii.PushId(groupIdx); var selectedOption = _empty ? (int)group.DefaultSettings : (int)_settings.Settings[groupIdx]; - Widget.BeginFramedGroup(group.Name, group.Description); + var minWidth = Widget.BeginFramedGroup(group.Name, group.Description); void DrawOptions() { @@ -236,21 +236,21 @@ public class ModPanelSettingsTab : ITab if (ImGui.RadioButton(option.Name, selectedOption == idx)) _collectionManager.Current.SetModSetting(_selector.Selected!.Index, groupIdx, (uint)idx); - if (option.Description.Length > 0) - { - ImGui.SameLine(); - ImGuiComponents.HelpMarker(option.Description); - } + if (option.Description.Length <= 0) + continue; + + ImGui.SameLine(); + ImGuiComponents.HelpMarker(option.Description); } } - DrawCollapseHandling(group, DrawOptions); + DrawCollapseHandling(group, minWidth, DrawOptions); Widget.EndFramedGroup(); } - private void DrawCollapseHandling(IModGroup group, Action draw) + private void DrawCollapseHandling(IModGroup group, float minWidth, Action draw) { if (group.Count <= _config.OptionGroupCollapsibleMin) { @@ -258,8 +258,13 @@ public class ModPanelSettingsTab : ITab } else { - var collapseId = ImGui.GetID("Collapse"); - var shown = ImGui.GetStateStorage().GetBool(collapseId, true); + var collapseId = ImGui.GetID("Collapse"); + var shown = ImGui.GetStateStorage().GetBool(collapseId, true); + var buttonTextShow = $"Show {group.Count} Options"; + var buttonTextHide = $"Hide {group.Count} Options"; + var buttonWidth = Math.Max(ImGui.CalcTextSize(buttonTextShow).X, ImGui.CalcTextSize(buttonTextHide).X) + + 2 * ImGui.GetStyle().FramePadding.X; + minWidth = Math.Max(buttonWidth, minWidth); if (shown) { var pos = ImGui.GetCursorPos(); @@ -269,21 +274,24 @@ public class ModPanelSettingsTab : ITab draw(); } - var width = ImGui.GetItemRectSize().X; - var endPos = ImGui.GetCursorPos(); + + + var width = Math.Max(ImGui.GetItemRectSize().X, minWidth); + var endPos = ImGui.GetCursorPos(); ImGui.SetCursorPos(pos); - if (ImGui.Button($"Hide {group.Count} Options", new Vector2(width, 0))) + if (ImGui.Button(buttonTextHide, new Vector2(width, 0))) ImGui.GetStateStorage().SetBool(collapseId, !shown); ImGui.SetCursorPos(endPos); } else { - var max = group.Max(o => ImGui.CalcTextSize(o.Name).X) + var optionWidth = group.Max(o => ImGui.CalcTextSize(o.Name).X) + ImGui.GetStyle().ItemInnerSpacing.X + ImGui.GetFrameHeight() + ImGui.GetStyle().FramePadding.X; - if (ImGui.Button($"Show {group.Count} Options", new Vector2(max, 0))) + var width = Math.Max(optionWidth, minWidth); + if (ImGui.Button(buttonTextShow, new Vector2(width, 0))) ImGui.GetStateStorage().SetBool(collapseId, !shown); } } @@ -297,7 +305,7 @@ public class ModPanelSettingsTab : ITab { using var id = ImRaii.PushId(groupIdx); var flags = _empty ? group.DefaultSettings : _settings.Settings[groupIdx]; - Widget.BeginFramedGroup(group.Name, group.Description); + var minWidth = Widget.BeginFramedGroup(group.Name, group.Description); void DrawOptions() { @@ -322,7 +330,7 @@ public class ModPanelSettingsTab : ITab } } - DrawCollapseHandling(group, DrawOptions); + DrawCollapseHandling(group, minWidth, DrawOptions); Widget.EndFramedGroup(); var label = $"##multi{groupIdx}"; diff --git a/Penumbra/UI/ModsTab/ModPanelTabBar.cs b/Penumbra/UI/ModsTab/ModPanelTabBar.cs index 2ea6e39e..d0006b17 100644 --- a/Penumbra/UI/ModsTab/ModPanelTabBar.cs +++ b/Penumbra/UI/ModsTab/ModPanelTabBar.cs @@ -31,7 +31,7 @@ public class ModPanelTabBar private readonly TutorialService _tutorial; public readonly ITab[] Tabs; - private ModPanelTabType _preferredTab = 0; + private ModPanelTabType _preferredTab = ModPanelTabType.Settings; private Mod? _lastMod = null; public ModPanelTabBar(ModEditWindow modEditWindow, ModPanelSettingsTab settings, ModPanelDescriptionTab description,