Make Design Combo bigger for full paths.

This commit is contained in:
Ottermandias 2023-08-04 01:13:25 +02:00
parent fe3ce166e3
commit e804e7e1e8

View file

@ -1,64 +1,82 @@
using System.Linq; using System;
using System.Linq;
using Dalamud.Interface;
using Glamourer.Automation; using Glamourer.Automation;
using Glamourer.Designs; using Glamourer.Designs;
using Glamourer.Events; using Glamourer.Events;
using Glamourer.Services; using Glamourer.Services;
using ImGuiNET; using ImGuiNET;
using OtterGui; using OtterGui;
using OtterGui.Raii;
using OtterGui.Widgets; using OtterGui.Widgets;
namespace Glamourer.Gui.Tabs.AutomationTab; namespace Glamourer.Gui.Tabs.AutomationTab;
public sealed class DesignCombo : FilterComboCache<Design> public sealed class DesignCombo : FilterComboCache<(Design, string)>
{ {
public const int RevertDesignIndex = -1228; public const int RevertDesignIndex = -1228;
public readonly Design RevertDesign; public readonly Design RevertDesign;
private readonly AutoDesignManager _manager; private readonly AutoDesignManager _manager;
private readonly DesignFileSystem _fileSystem;
private readonly TabSelected _tabSelected; private readonly TabSelected _tabSelected;
private float _innerWidth;
public DesignCombo(AutoDesignManager manager, DesignManager designs, DesignFileSystem fileSystem, TabSelected tabSelected, public DesignCombo(AutoDesignManager manager, DesignManager designs, DesignFileSystem fileSystem, TabSelected tabSelected,
ItemManager items) ItemManager items)
: base(() => designs.Designs.OrderBy(d => d.Name).Prepend(CreateRevertDesign(items)).ToList()) : this(manager, designs, fileSystem, tabSelected, CreateRevertDesign(items))
{ }
private DesignCombo(AutoDesignManager manager, DesignManager designs, DesignFileSystem fileSystem, TabSelected tabSelected,
Design revertDesign)
: base(() => designs.Designs.Select(d => (d, fileSystem.FindLeaf(d, out var l) ? l.FullName() : string.Empty)).OrderBy(d => d.Item2)
.Prepend((revertDesign, string.Empty)).ToList())
{ {
_manager = manager; _manager = manager;
_fileSystem = fileSystem;
_tabSelected = tabSelected; _tabSelected = tabSelected;
RevertDesign = Items[0]; RevertDesign = revertDesign;
} }
protected override bool DrawSelectable(int globalIdx, bool selected) protected override bool DrawSelectable(int globalIdx, bool selected)
{ {
var ret = base.DrawSelectable(globalIdx, selected); var ret = base.DrawSelectable(globalIdx, selected);
var (design, path) = Items[globalIdx];
if (ImGui.IsItemHovered() && _fileSystem.FindLeaf(Items[globalIdx], out var leaf)) if (path.Length > 0 && design.Name != path)
{ {
var fullName = leaf.FullName(); var start = ImGui.GetItemRectMin();
if (!fullName.StartsWith(Items[globalIdx].Name)) var pos = start.X + ImGui.CalcTextSize(design.Name).X;
{ var maxSize = ImGui.GetWindowPos().X + ImGui.GetWindowContentRegionMax().X;
using var tt = ImRaii.Tooltip(); var remainingSpace = maxSize - pos;
ImGui.TextUnformatted(fullName); var requiredSize = ImGui.CalcTextSize(path).X + ImGui.GetStyle().ItemInnerSpacing.X;
} var offset = remainingSpace - requiredSize;
if (ImGui.GetScrollMaxY() == 0)
offset -= ImGui.GetStyle().ItemInnerSpacing.X;
if (offset < ImGui.GetStyle().ItemSpacing.X)
ImGuiUtil.HoverTooltip(path);
else
ImGui.GetWindowDrawList().AddText(start with { X = pos + offset },
ImGui.GetColorU32(ImGuiCol.TextDisabled), path);
} }
return ret; return ret;
} }
protected override float GetFilterWidth()
=> _innerWidth - 2 * ImGui.GetStyle().FramePadding.X;
public void Draw(AutoDesignSet set, AutoDesign? design, int autoDesignIndex, bool incognito) public void Draw(AutoDesignSet set, AutoDesign? design, int autoDesignIndex, bool incognito)
{ {
CurrentSelection = design?.Design ?? RevertDesign; _innerWidth = 400 * ImGuiHelpers.GlobalScale;
CurrentSelectionIdx = (design?.Design?.Index ?? -1) + 1; CurrentSelectionIdx = Math.Max(Items.IndexOf(p => design?.Design == p.Item1), 0);
CurrentSelection = Items[CurrentSelectionIdx];
var name = design?.Name(incognito) ?? string.Empty; var name = design?.Name(incognito) ?? string.Empty;
if (Draw("##design", name, string.Empty, ImGui.GetContentRegionAvail().X, if (Draw("##design", name, string.Empty, ImGui.GetContentRegionAvail().X,
ImGui.GetTextLineHeightWithSpacing()) ImGui.GetTextLineHeightWithSpacing())
&& CurrentSelection != null) && CurrentSelection.Item1 != null)
{ {
if (autoDesignIndex >= 0) if (autoDesignIndex >= 0)
_manager.ChangeDesign(set, autoDesignIndex, CurrentSelection == RevertDesign ? null : CurrentSelection); _manager.ChangeDesign(set, autoDesignIndex, CurrentSelection.Item1 == RevertDesign ? null : CurrentSelection.Item1);
else else
_manager.AddDesign(set, CurrentSelection == RevertDesign ? null : CurrentSelection); _manager.AddDesign(set, CurrentSelection.Item1 == RevertDesign ? null : CurrentSelection.Item1);
} }
if (design?.Design != null) if (design?.Design != null)
@ -69,8 +87,8 @@ public sealed class DesignCombo : FilterComboCache<Design>
} }
} }
protected override string ToString(Design obj) protected override string ToString((Design, string) obj)
=> obj.Name.Text; => obj.Item1.Name.Text;
private static Design CreateRevertDesign(ItemManager items) private static Design CreateRevertDesign(ItemManager items)
=> new(items) => new(items)