Respect GlobalScale (finally)

MacroEditor MinSize.X is imgui-caused spaghetti and should not be looked at
This commit is contained in:
Asriel Camora
2024-07-03 23:17:00 -07:00
parent 7520305824
commit 9d343b5e4d
11 changed files with 61 additions and 26 deletions
+2 -2
View File
@@ -27,8 +27,8 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="../icon.png" /> <EmbeddedResource Include="Graphics\icon.png" />
<EmbeddedResource Include="../horse_icon.png" /> <EmbeddedResource Include="Graphics\horse_icon.png" />
<EmbeddedResource Include="Graphics\collectible_badge.png" /> <EmbeddedResource Include="Graphics\collectible_badge.png" />
<EmbeddedResource Include="Graphics\expert.png" /> <EmbeddedResource Include="Graphics\expert.png" />
<EmbeddedResource Include="Graphics\expert_badge.png" /> <EmbeddedResource Include="Graphics\expert_badge.png" />
Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

+4 -4
View File
@@ -1,6 +1,7 @@
using Craftimizer.Utils; using Craftimizer.Utils;
using Dalamud.Interface; using Dalamud.Interface;
using Dalamud.Interface.ManagedFontAtlas; using Dalamud.Interface.ManagedFontAtlas;
using Dalamud.Interface.Utility;
using Dalamud.Interface.Utility.Raii; using Dalamud.Interface.Utility.Raii;
using ImGuiNET; using ImGuiNET;
using ImPlotNET; using ImPlotNET;
@@ -12,7 +13,6 @@ using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Numerics; using System.Numerics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -534,7 +534,7 @@ internal static class ImGuiUtils
iconOffset = Vector2.Zero; iconOffset = Vector2.Zero;
} }
ImGui.GetWindowDrawList().AddText(UiBuilder.IconFont, UiBuilder.IconFont.FontSize * scale, offset + iconOffset, ImGui.GetColorU32(!isDisabled ? ImGuiCol.Text : ImGuiCol.TextDisabled), icon.ToIconString()); ImGui.GetWindowDrawList().AddText(UiBuilder.IconFont, UiBuilder.IconFont.FontSize * ImGuiHelpers.GlobalScale * scale, offset + iconOffset, ImGui.GetColorU32(!isDisabled ? ImGuiCol.Text : ImGuiCol.TextDisabled), icon.ToIconString());
} }
public static bool IconButtonSquare(FontAwesomeIcon icon, float size = -1) public static bool IconButtonSquare(FontAwesomeIcon icon, float size = -1)
@@ -592,7 +592,7 @@ internal static class ImGuiUtils
{ {
using var _font = ImRaii.PushFont(UiBuilder.DefaultFont); using var _font = ImRaii.PushFont(UiBuilder.DefaultFont);
using var _tooltip = ImRaii.Tooltip(); using var _tooltip = ImRaii.Tooltip();
using var _wrap = ImRaii2.TextWrapPos(width); using var _wrap = ImRaii2.TextWrapPos(width * ImGuiHelpers.GlobalScale);
ImGui.TextUnformatted(text); ImGui.TextUnformatted(text);
} }
@@ -612,7 +612,7 @@ internal static class ImGuiUtils
currentWrapWidth = wrapPosX - currentPos; currentWrapWidth = wrapPosX - currentPos;
var textBuf = text.AsSpan(); var textBuf = text.AsSpan();
var lineSize = font.CalcWordWrapPositionA(1, textBuf, currentWrapWidth) ?? textBuf.Length; var lineSize = font.CalcWordWrapPositionA(ImGuiHelpers.GlobalScale, textBuf, currentWrapWidth) ?? textBuf.Length;
var lineBuf = textBuf[..lineSize]; var lineBuf = textBuf[..lineSize];
ImGui.TextUnformatted(lineBuf.ToString()); ImGui.TextUnformatted(lineBuf.ToString());
var remainingBuf = textBuf[lineSize..].TrimStart(); var remainingBuf = textBuf[lineSize..].TrimStart();
+2 -2
View File
@@ -51,9 +51,9 @@ public sealed class Plugin : IDalamudPlugin
Author = assembly.GetCustomAttribute<AssemblyCompanyAttribute>()!.Company; Author = assembly.GetCustomAttribute<AssemblyCompanyAttribute>()!.Company;
BuildConfiguration = assembly.GetCustomAttribute<AssemblyConfigurationAttribute>()!.Configuration; BuildConfiguration = assembly.GetCustomAttribute<AssemblyConfigurationAttribute>()!.Configuration;
if (DateTime.Now is { Day: 1, Month: 4 }) if (DateTime.Now is { Day: 1, Month: 4 })
Icon = IconManager.GetAssemblyTexture("horse_icon.png"); Icon = IconManager.GetAssemblyTexture("Graphics.horse_icon.png");
else else
Icon = IconManager.GetAssemblyTexture("icon.png"); Icon = IconManager.GetAssemblyTexture("Graphics.icon.png");
SettingsWindow = new(); SettingsWindow = new();
RecipeNoteWindow = new(); RecipeNoteWindow = new();
+46 -10
View File
@@ -1,5 +1,4 @@
using Craftimizer.Plugin; using Craftimizer.Plugin;
using Craftimizer.Plugin.Utils;
using Craftimizer.Simulator; using Craftimizer.Simulator;
using Craftimizer.Simulator.Actions; using Craftimizer.Simulator.Actions;
using Craftimizer.Utils; using Craftimizer.Utils;
@@ -9,10 +8,8 @@ using Dalamud.Interface;
using Dalamud.Interface.Colors; using Dalamud.Interface.Colors;
using Dalamud.Interface.GameFonts; using Dalamud.Interface.GameFonts;
using Dalamud.Interface.ImGuiNotification; using Dalamud.Interface.ImGuiNotification;
using Dalamud.Interface.Internal;
using Dalamud.Interface.ManagedFontAtlas; using Dalamud.Interface.ManagedFontAtlas;
using Dalamud.Interface.Textures; using Dalamud.Interface.Utility;
using Dalamud.Interface.Textures.TextureWraps;
using Dalamud.Interface.Utility.Raii; using Dalamud.Interface.Utility.Raii;
using Dalamud.Interface.Windowing; using Dalamud.Interface.Windowing;
using Dalamud.Utility; using Dalamud.Utility;
@@ -143,8 +140,6 @@ public sealed class MacroEditor : Window, IDisposable
CollapsedCondition = ImGuiCond.Appearing; CollapsedCondition = ImGuiCond.Appearing;
Collapsed = false; Collapsed = false;
SizeConstraints = new() { MinimumSize = new(821, 750), MaximumSize = new(float.PositiveInfinity) };
TitleBarButtons = TitleBarButtons =
[ [
new() new()
@@ -156,9 +151,50 @@ public sealed class MacroEditor : Window, IDisposable
} }
]; ];
MinWindowHeight = float.PositiveInfinity;
Service.WindowSystem.AddWindow(this); Service.WindowSystem.AddWindow(this);
} }
private float MinWindowHeight { get; set; }
private static ReadOnlySpan<(float Scale, int MinWidth)> MinWindowWidths =>
new[]
{
(0.80f, 715),
(0.90f, 745),
(0.95f, 775),
(1.00f, 805),
(1.10f, 865),
(1.25f, 944),
(1.50f, 1128),
(2.00f, 1504),
(3.00f, 2184),
};
public override void PreDraw()
{
base.PreDraw();
var scale = ImGuiHelpers.GlobalScale;
var widths = MinWindowWidths;
var height = MinWindowWidths[^1].MinWidth;
for (var i = 0; i < widths.Length; ++i)
{
if (scale <= widths[i].Scale)
{
if (i == 0)
height = widths[i].MinWidth;
else
height = (int)float.Lerp(
widths[i - 1].MinWidth, widths[i].MinWidth,
(scale - widths[i - 1].Scale) / (widths[i].Scale - widths[i - 1].Scale)
);
break;
}
}
ImGui.SetNextWindowSizeConstraints(new Vector2(height, MinWindowHeight), new Vector2(float.PositiveInfinity));
}
public override void OnClose() public override void OnClose()
{ {
SolverTokenSource?.Cancel(); SolverTokenSource?.Cancel();
@@ -960,7 +996,7 @@ public sealed class MacroEditor : Window, IDisposable
Vector2 v1 = ImGui.GetItemRectMin(), v2 = ImGui.GetItemRectMax(); Vector2 v1 = ImGui.GetItemRectMin(), v2 = ImGui.GetItemRectMax();
ImGui.PushClipRect(v1, v2, true); ImGui.PushClipRect(v1, v2, true);
(v1.X, v2.X) = (v2.X, v1.X); (v1.X, v2.X) = (v2.X, v1.X);
ImGui.GetWindowDrawList().AddLine(v1, v2, ImGui.GetColorU32(new Vector4(1, 0, 0, ImGui.GetStyle().DisabledAlpha / 2)), 5); ImGui.GetWindowDrawList().AddLine(v1, v2, ImGui.GetColorU32(new Vector4(1, 0, 0, ImGui.GetStyle().DisabledAlpha / 2)), 5 * ImGuiHelpers.GlobalScale);
ImGui.PopClipRect(); ImGui.PopClipRect();
} }
if (ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled)) if (ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled))
@@ -982,8 +1018,8 @@ public sealed class MacroEditor : Window, IDisposable
} }
var minY = ImGui.GetCursorPosY() + ImGui.GetStyle().WindowPadding.Y - ImGui.GetStyle().CellPadding.Y; var minY = ImGui.GetCursorPosY() + ImGui.GetStyle().WindowPadding.Y - ImGui.GetStyle().CellPadding.Y;
if (SizeConstraints!.Value.MinimumSize.Y != minY) if (MinWindowHeight != minY)
SizeConstraints = SizeConstraints.Value with { MinimumSize = SizeConstraints.Value.MinimumSize with { Y = minY } }; MinWindowHeight = minY;
} }
private void DrawMacroInfo() private void DrawMacroInfo()
@@ -1151,7 +1187,7 @@ public sealed class MacroEditor : Window, IDisposable
Vector2 v1 = ImGui.GetItemRectMin(), v2 = ImGui.GetItemRectMax(); Vector2 v1 = ImGui.GetItemRectMin(), v2 = ImGui.GetItemRectMax();
ImGui.PushClipRect(v1, v2, true); ImGui.PushClipRect(v1, v2, true);
(v1.X, v2.X) = (v2.X, v1.X); (v1.X, v2.X) = (v2.X, v1.X);
ImGui.GetWindowDrawList().AddLine(v1, v2, ImGui.GetColorU32(new Vector4(1, 0, 0, ImGui.GetStyle().DisabledAlpha / 2)), 5); ImGui.GetWindowDrawList().AddLine(v1, v2, ImGui.GetColorU32(new Vector4(1, 0, 0, ImGui.GetStyle().DisabledAlpha / 2)), 5 * ImGuiHelpers.GlobalScale);
ImGui.PopClipRect(); ImGui.PopClipRect();
} }
if (ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled)) if (ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled))
+5 -5
View File
@@ -365,8 +365,8 @@ public sealed unsafe class RecipeNote : Window, IDisposable
{ {
if (StatsChanged) if (StatsChanged)
{ {
ImGui.TableSetupColumn("", ImGuiTableColumnFlags.WidthFixed, 150); ImGui.TableSetupColumn("", ImGuiTableColumnFlags.WidthFixed, 150 * ImGuiHelpers.GlobalScale);
ImGui.TableSetupColumn("", ImGuiTableColumnFlags.WidthFixed, 150); ImGui.TableSetupColumn("", ImGuiTableColumnFlags.WidthFixed, 150 * ImGuiHelpers.GlobalScale);
} }
ImGui.TableNextColumn(); ImGui.TableNextColumn();
@@ -624,7 +624,7 @@ public sealed unsafe class RecipeNote : Window, IDisposable
using var table = ImRaii.Table("characterStats", 2); using var table = ImRaii.Table("characterStats", 2);
if (table) if (table)
{ {
ImGui.TableSetupColumn("", ImGuiTableColumnFlags.WidthFixed, 100); ImGui.TableSetupColumn("", ImGuiTableColumnFlags.WidthFixed, 100 * ImGuiHelpers.GlobalScale);
ImGui.TableSetupColumn("", ImGuiTableColumnFlags.WidthStretch); ImGui.TableSetupColumn("", ImGuiTableColumnFlags.WidthStretch);
ImGui.TableNextColumn(); ImGui.TableNextColumn();
@@ -715,7 +715,7 @@ public sealed unsafe class RecipeNote : Window, IDisposable
using var table = ImRaii.Table("recipeStats", 2); using var table = ImRaii.Table("recipeStats", 2);
if (table) if (table)
{ {
ImGui.TableSetupColumn("", ImGuiTableColumnFlags.WidthFixed, 100); ImGui.TableSetupColumn("", ImGuiTableColumnFlags.WidthFixed, 100 * ImGuiHelpers.GlobalScale);
ImGui.TableSetupColumn("", ImGuiTableColumnFlags.WidthStretch); ImGui.TableSetupColumn("", ImGuiTableColumnFlags.WidthStretch);
ImGui.TableNextColumn(); ImGui.TableNextColumn();
@@ -1036,7 +1036,7 @@ public sealed unsafe class RecipeNote : Window, IDisposable
using var table = ImRaii.Table("requiredStats", 2); using var table = ImRaii.Table("requiredStats", 2);
if (table) if (table)
{ {
ImGui.TableSetupColumn("", ImGuiTableColumnFlags.WidthFixed, 100); ImGui.TableSetupColumn("", ImGuiTableColumnFlags.WidthFixed, 100 * ImGuiHelpers.GlobalScale);
ImGui.TableSetupColumn("", ImGuiTableColumnFlags.WidthStretch); ImGui.TableSetupColumn("", ImGuiTableColumnFlags.WidthStretch);
ImGui.TableNextColumn(); ImGui.TableNextColumn();
+2 -3
View File
@@ -1,7 +1,6 @@
using Craftimizer.Simulator; using Craftimizer.Simulator;
using Craftimizer.Simulator.Actions; using Craftimizer.Simulator.Actions;
using Craftimizer.Solver; using Craftimizer.Solver;
using Craftimizer.Utils;
using Dalamud.Interface; using Dalamud.Interface;
using Dalamud.Interface.Colors; using Dalamud.Interface.Colors;
using Dalamud.Interface.ManagedFontAtlas; using Dalamud.Interface.ManagedFontAtlas;
@@ -24,7 +23,7 @@ public sealed class Settings : Window, IDisposable
private static Configuration Config => Service.Configuration; private static Configuration Config => Service.Configuration;
private const int OptionWidth = 200; private static float OptionWidth => 200 * ImGuiHelpers.GlobalScale;
private static Vector2 OptionButtonSize => new(OptionWidth, ImGui.GetFrameHeight()); private static Vector2 OptionButtonSize => new(OptionWidth, ImGui.GetFrameHeight());
private string? SelectedTab { get; set; } private string? SelectedTab { get; set; }
@@ -922,7 +921,7 @@ public sealed class Settings : Window, IDisposable
var plugin = Service.Plugin; var plugin = Service.Plugin;
var icon = plugin.Icon; var icon = plugin.Icon;
var iconDim = icon.Dimensions ?? new(128); var iconDim = new Vector2(128) * ImGuiHelpers.GlobalScale;
using (var table = ImRaii.Table("settingsAboutTable", 2)) using (var table = ImRaii.Table("settingsAboutTable", 2))
{ {
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB