Skip to content

Commit

Permalink
Store FontAwesomeIcon string representation instead of creating it …
Browse files Browse the repository at this point in the history
…every frame.
  • Loading branch information
Kurochi51 committed Mar 19, 2024
1 parent 668233f commit 774dbb8
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions PetScale/Windows/ConfigWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public sealed class ConfigWindow : Window, IDisposable
{ PetSize.MediumModelScale, "Medium"},
{ PetSize.LargeModelScale, "Large" },
};
private readonly string buttonIcon;
private readonly string deleteButtonIcon, addButtonIcon;
private readonly CancellationTokenSource cts;
private readonly CancellationToken cToken;
private readonly Notification notification = new();

Check failure on line 43 in PetScale/Windows/ConfigWindow.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'Notification' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 43 in PetScale/Windows/ConfigWindow.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'Notification' could not be found (are you missing a using directive or an assembly reference?)
Expand Down Expand Up @@ -73,7 +73,8 @@ public sealed class ConfigWindow : Window, IDisposable
cts = new CancellationTokenSource();
cToken = cts.Token;

buttonIcon = FontAwesomeIcon.Trash.ToIconString();
deleteButtonIcon = FontAwesomeIcon.Trash.ToIconString();
addButtonIcon = FontAwesomeIcon.Plus.ToIconString();
pluginInterface.UiBuilder.DefaultFontHandle.ImFontChanged += QueueColumnWidthChange;
}

Expand Down Expand Up @@ -102,7 +103,7 @@ public override void Draw()
ImGui.SameLine();
DrawComboBox("Sizes", sizeSelection, sizesWidth, out sizeSelection, sizeMap.Values, filter: false);
ImGui.SameLine();
if (DrawIconButton(fontHandle: null, FontAwesomeIcon.Plus.ToIconString(), "AddButton", 1))
if (DrawIconButton(fontHandle: null, addButtonIcon, "AddButton", 1))
{
buttonPressed = true;
}
Expand Down Expand Up @@ -149,10 +150,10 @@ private unsafe void DisplayEntries()
ImGui.TableSetupColumn("Character", ImGuiTableColumnFlags.WidthFixed, charaWidth);
ImGui.TableSetupColumn("Pet", ImGuiTableColumnFlags.WidthFixed, petWidth);
ImGui.TableSetupColumn("PetSize", ImGuiTableColumnFlags.WidthFixed, sizesWidth);
ImGui.TableSetupColumn("DeleteButton", ImGuiTableColumnFlags.WidthFixed, GetIconButtonSize(fontHandle: null, buttonIcon).X);
ImGui.TableSetupColumn("DeleteButton", ImGuiTableColumnFlags.WidthFixed, GetIconButtonSize(fontHandle: null, deleteButtonIcon).X);
var itemRemoved = false;
var clipper = new ImGuiListClipperPtr(ImGuiNative.ImGuiListClipper_ImGuiListClipper());
var clipperHeight = GetIconButtonSize(fontHandle: null, buttonIcon).Y + (ImGui.GetStyle().FramePadding.Y * 2);
var clipperHeight = GetIconButtonSize(fontHandle: null, deleteButtonIcon).Y + (ImGui.GetStyle().FramePadding.Y * 2);
clipper.Begin(petData.Count, clipperHeight);

var clipperBreak = false;
Expand Down Expand Up @@ -181,7 +182,7 @@ private unsafe void DisplayEntries()
ImGui.TextUnformatted(sizeMap[item.PetSize]);
ImGui.TableSetColumnIndex(3);
ImGui.SetCursorPosX(tableButtonAlignmentOffset);
if (DrawIconButton(fontHandle: null, buttonIcon, buttonId + buttonIcon))
if (DrawIconButton(fontHandle: null, deleteButtonIcon, buttonId + deleteButtonIcon))
{
petData.RemoveAt(i);
CreateNotification("Entry " + item.CharacterName + ", " + petSelection + ", " + sizeMap[item.PetSize] + " was removed.", PetScale.PluginName);
Expand Down Expand Up @@ -390,7 +391,7 @@ private void ResizeIfNeeded()
tableButtonAlignmentOffset = charaWidth + petWidth + sizesWidth + (ImGui.GetStyle().ItemSpacing.X * 3);
if (SizeConstraints.HasValue)
{
var newWidth = tableButtonAlignmentOffset + GetIconButtonSize(fontHandle: null, buttonIcon).X + (ImGui.GetStyle().WindowPadding.X * 2) + ImGui.GetStyle().ScrollbarSize;
var newWidth = tableButtonAlignmentOffset + GetIconButtonSize(fontHandle: null, deleteButtonIcon).X + (ImGui.GetStyle().WindowPadding.X * 2) + ImGui.GetStyle().ScrollbarSize;
SizeConstraints = new WindowSizeConstraints()
{
MinimumSize = new Vector2(newWidth / ImGuiHelpers.GlobalScale, SizeConstraints.Value.MinimumSize.Y),
Expand Down

0 comments on commit 774dbb8

Please sign in to comment.