Dalamud/Dalamud/Interface/Internal/Windows/Data/Widgets/FontAwesomeTestWidget.cs
Haselnussbomber c93f04f0e4
Code cleanup (#2439)
* Use new Lock objects

* Fix CA1513: Use ObjectDisposedException.ThrowIf

* Fix CA1860: Avoid using 'Enumerable.Any()' extension method

* Fix IDE0028: Use collection initializers or expressions

* Fix CA2263: Prefer generic overload when type is known

* Fix CA1862: Use the 'StringComparison' method overloads to perform case-insensitive string comparisons

* Fix IDE0270: Null check can be simplified

* Fix IDE0280: Use 'nameof'

* Fix IDE0009: Add '.this'

* Fix IDE0007: Use 'var' instead of explicit type

* Fix IDE0062: Make local function static

* Fix CA1859: Use concrete types when possible for improved performance

* Fix IDE0066: Use switch expression

Only applied to where it doesn't look horrendous.

* Use is over switch

* Fix CA1847: Use String.Contains(char) instead of String.Contains(string) with single characters

* Fix SYSLIB1045: Use 'GeneratedRegexAttribute' to generate the regular expression implementation at compile-time.

* Fix CA1866: Use 'string.EndsWith(char)' instead of 'string.EndsWith(string)' when you have a string with a single char

* Fix IDE0057: Substring can be simplified

* Fix IDE0059: Remove unnecessary value assignment

* Fix CA1510: Use ArgumentNullException throw helper

* Fix IDE0300: Use collection expression for array

* Fix IDE0250: Struct can be made 'readonly'

* Fix IDE0018: Inline variable declaration

* Fix CA1850: Prefer static HashData method over ComputeHash

* Fi CA1872: Prefer 'Convert.ToHexString' and 'Convert.ToHexStringLower' over call chains based on 'BitConverter.ToString'

* Update ModuleLog instantiations

* Organize usings
2026-01-06 08:36:55 -08:00

126 lines
4.6 KiB
C#

using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Threading.Tasks;
using Dalamud.Bindings.ImGui;
using Dalamud.Interface.Components;
using Dalamud.Interface.Textures.Internal;
using Dalamud.Interface.Utility;
using Dalamud.Interface.Utility.Internal;
using Lumina.Text.ReadOnly;
namespace Dalamud.Interface.Internal.Windows.Data.Widgets;
/// <summary>
/// Widget to display FontAwesome Symbols.
/// </summary>
internal class FontAwesomeTestWidget : IDataWindowWidget
{
private List<FontAwesomeIcon>? icons;
private List<string>? iconNames;
private string[]? iconCategories;
private int selectedIconCategory;
private string iconSearchInput = string.Empty;
private bool iconSearchChanged = true;
private bool useFixedWidth = false;
/// <inheritdoc/>
public string[]? CommandShortcuts { get; init; } = ["fa", "fatest", "fontawesome"];
/// <inheritdoc/>
public string DisplayName { get; init; } = "Font Awesome Test";
/// <inheritdoc/>
public bool Ready { get; set; }
/// <inheritdoc/>
public void Load()
{
this.Ready = true;
}
/// <inheritdoc/>
public void Draw()
{
ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, Vector2.Zero);
this.iconCategories ??= new[] { "(Show All)", "(Undefined)" }
.Concat(FontAwesomeHelpers.GetCategories().Skip(1))
.ToArray();
if (this.iconSearchChanged)
{
if (this.iconSearchInput == string.Empty && this.selectedIconCategory <= 1)
{
var en = InterfaceManager.IconFont.GlyphsWrapped()
.Select(x => (FontAwesomeIcon)x.Codepoint)
.Where(x => (ushort)x is >= 0xE000 and < 0xF000);
en = this.selectedIconCategory == 0
? en.Concat(FontAwesomeHelpers.SearchIcons(string.Empty, string.Empty))
: en.Except(FontAwesomeHelpers.SearchIcons(string.Empty, string.Empty));
this.icons = en.Distinct().Order().ToList();
}
else
{
this.icons = FontAwesomeHelpers.SearchIcons(
this.iconSearchInput,
this.selectedIconCategory <= 1 ? string.Empty : this.iconCategories[this.selectedIconCategory]);
}
this.iconNames = this.icons.Select(icon => Enum.GetName(icon)!).ToList();
this.iconSearchChanged = false;
}
ImGui.SetNextItemWidth(160f);
var categoryIndex = this.selectedIconCategory;
if (ImGui.Combo("####FontAwesomeCategorySearch", ref categoryIndex, this.iconCategories))
{
this.selectedIconCategory = categoryIndex;
this.iconSearchChanged = true;
}
ImGui.SameLine(170f);
ImGui.SetNextItemWidth(180f);
if (ImGui.InputTextWithHint($"###FontAwesomeInputSearch", "search icons"u8, ref this.iconSearchInput, 50))
{
this.iconSearchChanged = true;
}
ImGui.Checkbox("Use fixed width font"u8, ref this.useFixedWidth);
ImGuiHelpers.ScaledDummy(10f);
for (var i = 0; i < this.icons?.Count; i++)
{
if (this.icons[i] == FontAwesomeIcon.None)
continue;
ImGui.AlignTextToFramePadding();
ImGui.Text($"0x{(int)this.icons[i].ToIconChar():X}");
ImGuiHelpers.ScaledRelativeSameLine(50f);
ImGui.Text($"{this.iconNames?[i]}");
ImGuiHelpers.ScaledRelativeSameLine(280f);
ImGui.PushFont(this.useFixedWidth ? InterfaceManager.IconFontFixedWidth : InterfaceManager.IconFont);
ImGui.Text(this.icons[i].ToIconString());
ImGuiHelpers.ScaledRelativeSameLine(320f);
if (this.useFixedWidth
? ImGui.Button($"{(char)this.icons[i]}##FontAwesomeIconButton{i}")
: ImGuiComponents.IconButton($"##FontAwesomeIconButton{i}", this.icons[i]))
{
_ = Service<DevTextureSaveMenu>.Get().ShowTextureSaveMenuAsync(
this.DisplayName,
this.icons[i].ToString(),
Task.FromResult(
Service<TextureManager>.Get().CreateTextureFromSeString(
ReadOnlySeString.FromText(this.icons[i].ToIconString()),
new() { Font = ImGui.GetFont(), FontSize = ImGui.GetFontSize(), ScreenOffset = Vector2.Zero })));
}
ImGui.PopFont();
ImGuiHelpers.ScaledDummy(2f);
}
ImGui.PopStyleVar();
}
}