mirror of
https://github.com/Ottermandias/Glamourer.git
synced 2025-12-12 18:27:24 +01:00
Make Design Combo bigger for full paths.
This commit is contained in:
parent
fe3ce166e3
commit
e804e7e1e8
1 changed files with 40 additions and 22 deletions
|
|
@ -1,64 +1,82 @@
|
|||
using System.Linq;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Dalamud.Interface;
|
||||
using Glamourer.Automation;
|
||||
using Glamourer.Designs;
|
||||
using Glamourer.Events;
|
||||
using Glamourer.Services;
|
||||
using ImGuiNET;
|
||||
using OtterGui;
|
||||
using OtterGui.Raii;
|
||||
using OtterGui.Widgets;
|
||||
|
||||
namespace Glamourer.Gui.Tabs.AutomationTab;
|
||||
|
||||
public sealed class DesignCombo : FilterComboCache<Design>
|
||||
public sealed class DesignCombo : FilterComboCache<(Design, string)>
|
||||
{
|
||||
public const int RevertDesignIndex = -1228;
|
||||
public readonly Design RevertDesign;
|
||||
|
||||
private readonly AutoDesignManager _manager;
|
||||
private readonly DesignFileSystem _fileSystem;
|
||||
private readonly TabSelected _tabSelected;
|
||||
private float _innerWidth;
|
||||
|
||||
public DesignCombo(AutoDesignManager manager, DesignManager designs, DesignFileSystem fileSystem, TabSelected tabSelected,
|
||||
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;
|
||||
_fileSystem = fileSystem;
|
||||
_tabSelected = tabSelected;
|
||||
RevertDesign = Items[0];
|
||||
RevertDesign = revertDesign;
|
||||
}
|
||||
|
||||
protected override bool DrawSelectable(int globalIdx, bool selected)
|
||||
{
|
||||
var ret = base.DrawSelectable(globalIdx, selected);
|
||||
|
||||
if (ImGui.IsItemHovered() && _fileSystem.FindLeaf(Items[globalIdx], out var leaf))
|
||||
var (design, path) = Items[globalIdx];
|
||||
if (path.Length > 0 && design.Name != path)
|
||||
{
|
||||
var fullName = leaf.FullName();
|
||||
if (!fullName.StartsWith(Items[globalIdx].Name))
|
||||
{
|
||||
using var tt = ImRaii.Tooltip();
|
||||
ImGui.TextUnformatted(fullName);
|
||||
}
|
||||
var start = ImGui.GetItemRectMin();
|
||||
var pos = start.X + ImGui.CalcTextSize(design.Name).X;
|
||||
var maxSize = ImGui.GetWindowPos().X + ImGui.GetWindowContentRegionMax().X;
|
||||
var remainingSpace = maxSize - pos;
|
||||
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;
|
||||
}
|
||||
|
||||
protected override float GetFilterWidth()
|
||||
=> _innerWidth - 2 * ImGui.GetStyle().FramePadding.X;
|
||||
|
||||
public void Draw(AutoDesignSet set, AutoDesign? design, int autoDesignIndex, bool incognito)
|
||||
{
|
||||
CurrentSelection = design?.Design ?? RevertDesign;
|
||||
CurrentSelectionIdx = (design?.Design?.Index ?? -1) + 1;
|
||||
_innerWidth = 400 * ImGuiHelpers.GlobalScale;
|
||||
CurrentSelectionIdx = Math.Max(Items.IndexOf(p => design?.Design == p.Item1), 0);
|
||||
CurrentSelection = Items[CurrentSelectionIdx];
|
||||
var name = design?.Name(incognito) ?? string.Empty;
|
||||
if (Draw("##design", name, string.Empty, ImGui.GetContentRegionAvail().X,
|
||||
ImGui.GetTextLineHeightWithSpacing())
|
||||
&& CurrentSelection != null)
|
||||
&& CurrentSelection.Item1 != null)
|
||||
{
|
||||
if (autoDesignIndex >= 0)
|
||||
_manager.ChangeDesign(set, autoDesignIndex, CurrentSelection == RevertDesign ? null : CurrentSelection);
|
||||
_manager.ChangeDesign(set, autoDesignIndex, CurrentSelection.Item1 == RevertDesign ? null : CurrentSelection.Item1);
|
||||
else
|
||||
_manager.AddDesign(set, CurrentSelection == RevertDesign ? null : CurrentSelection);
|
||||
_manager.AddDesign(set, CurrentSelection.Item1 == RevertDesign ? null : CurrentSelection.Item1);
|
||||
}
|
||||
|
||||
if (design?.Design != null)
|
||||
|
|
@ -69,8 +87,8 @@ public sealed class DesignCombo : FilterComboCache<Design>
|
|||
}
|
||||
}
|
||||
|
||||
protected override string ToString(Design obj)
|
||||
=> obj.Name.Text;
|
||||
protected override string ToString((Design, string) obj)
|
||||
=> obj.Item1.Name.Text;
|
||||
|
||||
private static Design CreateRevertDesign(ItemManager items)
|
||||
=> new(items)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue