IconButtonSquare properly centers and aligns FA icons
This commit is contained in:
@@ -507,10 +507,50 @@ internal static class ImGuiUtils
|
|||||||
return ImGuiExtras.InputTextEx(label, hint, ref input, maxLength, size, flags | Multiline, callback, user_data);
|
return ImGuiExtras.InputTextEx(label, hint, ref input, maxLength, size, flags | Multiline, callback, user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IconButtonSized(FontAwesomeIcon icon, Vector2 size)
|
private static Vector2 GetIconSize(FontAwesomeIcon icon)
|
||||||
{
|
{
|
||||||
using var font = ImRaii.PushFont(UiBuilder.IconFont);
|
using var font = ImRaii.PushFont(UiBuilder.IconFont);
|
||||||
var ret = ImGui.Button(icon.ToIconString(), size);
|
return ImGui.CalcTextSize(icon.ToIconString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void DrawCenteredIcon(FontAwesomeIcon icon, Vector2 offset, Vector2 size)
|
||||||
|
{
|
||||||
|
var iconSize = GetIconSize(icon);
|
||||||
|
|
||||||
|
float scale;
|
||||||
|
Vector2 iconOffset;
|
||||||
|
if (iconSize.X > iconSize.Y)
|
||||||
|
{
|
||||||
|
scale = size.X / iconSize.X;
|
||||||
|
iconOffset = new(0, (size.Y - (iconSize.Y * scale)) / 2f);
|
||||||
|
}
|
||||||
|
else if (iconSize.Y > iconSize.X)
|
||||||
|
{
|
||||||
|
scale = size.Y / iconSize.Y;
|
||||||
|
iconOffset = new((size.X - (iconSize.X * scale)) / 2f, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
scale = size.X / iconSize.X;
|
||||||
|
iconOffset = Vector2.Zero;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.GetWindowDrawList().AddText(UiBuilder.IconFont, UiBuilder.IconFont.FontSize * scale, offset + iconOffset, ImGui.GetColorU32(ImGuiCol.Text), icon.ToIconString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool IconButtonSquare(FontAwesomeIcon icon, float size = -1)
|
||||||
|
{
|
||||||
|
var ret = false;
|
||||||
|
|
||||||
|
var buttonSize = new Vector2(size == -1 ? ImGui.GetFrameHeight() : size);
|
||||||
|
var pos = ImGui.GetCursorScreenPos();
|
||||||
|
var spacing = new Vector2(ImGui.GetStyle().FramePadding.Y);
|
||||||
|
|
||||||
|
if (ImGui.Button($"###{icon.ToIconString()}", buttonSize))
|
||||||
|
ret = true;
|
||||||
|
|
||||||
|
DrawCenteredIcon(icon, pos + spacing, buttonSize - spacing * 2);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public sealed class MacroClipboard : Window, IDisposable
|
|||||||
ImGui.SetCursorPos(buttonCursor);
|
ImGui.SetCursorPos(buttonCursor);
|
||||||
{
|
{
|
||||||
using var color = ImRaii.PushColor(ImGuiCol.Button, ImGui.GetColorU32(buttonActive ? ImGuiCol.ButtonActive : ImGuiCol.ButtonHovered), buttonHovered);
|
using var color = ImRaii.PushColor(ImGuiCol.Button, ImGui.GetColorU32(buttonActive ? ImGuiCol.ButtonActive : ImGuiCol.ButtonHovered), buttonHovered);
|
||||||
ImGuiUtils.IconButtonSized(FontAwesomeIcon.Paste, new(ImGui.GetFrameHeight()));
|
ImGuiUtils.IconButtonSquare(FontAwesomeIcon.Paste);
|
||||||
if (buttonClicked)
|
if (buttonClicked)
|
||||||
{
|
{
|
||||||
ImGui.SetClipboardText(macro);
|
ImGui.SetClipboardText(macro);
|
||||||
|
|||||||
@@ -1314,14 +1314,14 @@ public sealed class MacroEditor : Window, IDisposable
|
|||||||
"can vary wildly depending on the solver's settings.");
|
"can vary wildly depending on the solver's settings.");
|
||||||
}
|
}
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
if (ImGuiUtils.IconButtonSized(FontAwesomeIcon.Paste, new(height)))
|
if (ImGuiUtils.IconButtonSquare(FontAwesomeIcon.Paste))
|
||||||
Service.Plugin.CopyMacro(Macro.Select(s => s.Action).ToArray());
|
Service.Plugin.CopyMacro(Macro.Select(s => s.Action).ToArray());
|
||||||
if (ImGui.IsItemHovered())
|
if (ImGui.IsItemHovered())
|
||||||
ImGui.SetTooltip("Copy to Clipboard");
|
ImGui.SetTooltip("Copy to Clipboard");
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
using (var _disabled = ImRaii.Disabled(SolverRunning))
|
using (var _disabled = ImRaii.Disabled(SolverRunning))
|
||||||
{
|
{
|
||||||
if (ImGuiUtils.IconButtonSized(FontAwesomeIcon.FileImport, new(height)))
|
if (ImGuiUtils.IconButtonSquare(FontAwesomeIcon.FileImport))
|
||||||
ShowImportPopup();
|
ShowImportPopup();
|
||||||
}
|
}
|
||||||
if (ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled))
|
if (ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled))
|
||||||
@@ -1332,7 +1332,7 @@ public sealed class MacroEditor : Window, IDisposable
|
|||||||
{
|
{
|
||||||
using (var _disabled = ImRaii.Disabled(SolverRunning))
|
using (var _disabled = ImRaii.Disabled(SolverRunning))
|
||||||
{
|
{
|
||||||
if (ImGuiUtils.IconButtonSized(FontAwesomeIcon.Undo, new(height)))
|
if (ImGuiUtils.IconButtonSquare(FontAwesomeIcon.Undo))
|
||||||
{
|
{
|
||||||
SolverStartStepCount = null;
|
SolverStartStepCount = null;
|
||||||
Macro.Clear();
|
Macro.Clear();
|
||||||
@@ -1346,7 +1346,7 @@ public sealed class MacroEditor : Window, IDisposable
|
|||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
using (var _disabled = ImRaii.Disabled(SolverRunning))
|
using (var _disabled = ImRaii.Disabled(SolverRunning))
|
||||||
{
|
{
|
||||||
if (ImGuiUtils.IconButtonSized(FontAwesomeIcon.Trash, new(height)))
|
if (ImGuiUtils.IconButtonSquare(FontAwesomeIcon.Trash))
|
||||||
{
|
{
|
||||||
SolverStartStepCount = null;
|
SolverStartStepCount = null;
|
||||||
Macro.Clear();
|
Macro.Clear();
|
||||||
|
|||||||
@@ -197,23 +197,23 @@ public sealed class MacroList : Window, IDisposable
|
|||||||
|
|
||||||
ImGui.TableNextColumn();
|
ImGui.TableNextColumn();
|
||||||
{
|
{
|
||||||
if (ImGuiUtils.IconButtonSized(FontAwesomeIcon.Paste, new(miniRowHeight)))
|
if (ImGuiUtils.IconButtonSquare(FontAwesomeIcon.Paste, miniRowHeight))
|
||||||
Service.Plugin.CopyMacro(macro.Actions);
|
Service.Plugin.CopyMacro(macro.Actions);
|
||||||
if (ImGui.IsItemHovered())
|
if (ImGui.IsItemHovered())
|
||||||
ImGui.SetTooltip("Copy to Clipboard");
|
ImGui.SetTooltip("Copy to Clipboard");
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
if (ImGuiUtils.IconButtonSized(FontAwesomeIcon.Trash, new(miniRowHeight)) && ImGui.GetIO().KeyShift)
|
if (ImGuiUtils.IconButtonSquare(FontAwesomeIcon.Trash, miniRowHeight) && ImGui.GetIO().KeyShift)
|
||||||
Service.Configuration.RemoveMacro(macro);
|
Service.Configuration.RemoveMacro(macro);
|
||||||
if (ImGui.IsItemHovered())
|
if (ImGui.IsItemHovered())
|
||||||
ImGui.SetTooltip("Delete (Hold Shift)");
|
ImGui.SetTooltip("Delete (Hold Shift)");
|
||||||
|
|
||||||
if (ImGuiUtils.IconButtonSized(FontAwesomeIcon.PencilAlt, new(miniRowHeight)))
|
if (ImGuiUtils.IconButtonSquare(FontAwesomeIcon.PencilAlt, miniRowHeight))
|
||||||
ShowRenamePopup(macro);
|
ShowRenamePopup(macro);
|
||||||
DrawRenamePopup(macro);
|
DrawRenamePopup(macro);
|
||||||
if (ImGui.IsItemHovered())
|
if (ImGui.IsItemHovered())
|
||||||
ImGui.SetTooltip("Rename");
|
ImGui.SetTooltip("Rename");
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
if (ImGuiUtils.IconButtonSized(FontAwesomeIcon.Edit, new(miniRowHeight)))
|
if (ImGuiUtils.IconButtonSquare(FontAwesomeIcon.Edit, miniRowHeight))
|
||||||
OpenEditor(macro);
|
OpenEditor(macro);
|
||||||
if (ImGui.IsItemHovered())
|
if (ImGui.IsItemHovered())
|
||||||
ImGui.SetTooltip("Open in Simulator");
|
ImGui.SetTooltip("Open in Simulator");
|
||||||
|
|||||||
@@ -644,11 +644,11 @@ public sealed unsafe class RecipeNote : Window, IDisposable
|
|||||||
|
|
||||||
ImGui.TableNextColumn();
|
ImGui.TableNextColumn();
|
||||||
{
|
{
|
||||||
if (ImGuiUtils.IconButtonSized(FontAwesomeIcon.Edit, new(miniRowHeight)))
|
if (ImGuiUtils.IconButtonSquare(FontAwesomeIcon.Edit, miniRowHeight))
|
||||||
Service.Plugin.OpenMacroEditor(CharacterStats!, RecipeData!, new(Service.ClientState.LocalPlayer!.StatusList), macro.Actions, setter);
|
Service.Plugin.OpenMacroEditor(CharacterStats!, RecipeData!, new(Service.ClientState.LocalPlayer!.StatusList), macro.Actions, setter);
|
||||||
if (ImGui.IsItemHovered())
|
if (ImGui.IsItemHovered())
|
||||||
ImGui.SetTooltip("Open in Simulator");
|
ImGui.SetTooltip("Open in Simulator");
|
||||||
if (ImGuiUtils.IconButtonSized(FontAwesomeIcon.Paste, new(miniRowHeight)))
|
if (ImGuiUtils.IconButtonSquare(FontAwesomeIcon.Paste, miniRowHeight))
|
||||||
Service.Plugin.CopyMacro(macro.Actions);
|
Service.Plugin.CopyMacro(macro.Actions);
|
||||||
if (ImGui.IsItemHovered())
|
if (ImGui.IsItemHovered())
|
||||||
ImGui.SetTooltip("Copy to Clipboard");
|
ImGui.SetTooltip("Copy to Clipboard");
|
||||||
|
|||||||
Reference in New Issue
Block a user