Fix button sizing for collapsible groups, fix default tab to be settings, fix bug with item spacing style.

This commit is contained in:
Ottermandias 2023-03-24 18:33:22 +01:00
parent 5cad575c2e
commit 45b26030cc
4 changed files with 28 additions and 20 deletions

@ -1 +1 @@
Subproject commit 2cc26d04a0ec162b71544ff164d1ca768fb90c95
Subproject commit cb99fa45c796cd1385281e3b690151623f4ed549

View file

@ -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();

View file

@ -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}";

View file

@ -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,