Button size schenanigans

This commit is contained in:
Asriel Camora
2023-07-23 04:19:23 +04:00
parent 1f39be40c8
commit 20e3dcf758
4 changed files with 29 additions and 18 deletions
+3
View File
@@ -9,6 +9,9 @@ namespace Craftimizer.Plugin;
internal static class ImGuiUtils
{
public static float ButtonHeight =>
ImGui.CalcTextSize("A").Y + (ImGui.GetStyle().FramePadding.Y * 2);
private static readonly Stack<(Vector2 Min, Vector2 Max)> GroupPanelLabelStack = new();
// Adapted from https://github.com/ocornut/imgui/issues/1496#issuecomment-655048353
+16 -8
View File
@@ -1,6 +1,7 @@
using Craftimizer.Plugin.Utils;
using Craftimizer.Utils;
using Dalamud.Interface;
using Dalamud.Interface.Components;
using Dalamud.Interface.Windowing;
using FFXIVClientStructs.FFXIV.Client.Game;
using ImGuiNET;
@@ -17,7 +18,9 @@ public sealed unsafe partial class Craft : Window, IDisposable
| ImGuiWindowFlags.NoFocusOnAppearing
| ImGuiWindowFlags.NoNavFocus;
public static readonly Vector2 CraftProgressBarSize = new(300, 15);
private const float WindowWidth = 300;
private const int ActionsPerRow = 5;
private static readonly Vector2 CraftProgressBarSize = new(WindowWidth, 15);
private static Configuration Config => Service.Configuration;
@@ -50,18 +53,23 @@ public sealed unsafe partial class Craft : Window, IDisposable
ImGuiHelpers.ScaledDummy(5);
ImGui.PushFont(UiBuilder.IconFont);
var cogWidth = ImGui.CalcTextSize(FontAwesomeIcon.Cog.ToIconString()).X;
ImGui.PopFont();
ImGui.BeginDisabled(!(SolverTask?.IsCompleted ?? true));
if (ImGui.Button("Retry"))
QueueSolve(GetNextState()!.Value);
if (ImGui.Button("Retry", new(WindowWidth - ImGui.GetStyle().ItemSpacing.X - cogWidth, ImGuiUtils.ButtonHeight)))
QueueSolve(GetNextState()!.Value);
ImGui.EndDisabled();
ImGui.SameLine();
if (ImGuiComponents.IconButton("synthSettingsButton", FontAwesomeIcon.Cog))
Service.Plugin.OpenSettingsWindow();
}
private void DrawActions()
{
var totalWidth = 300f;
var actionsPerRow = 5;
var actionSize = new Vector2((totalWidth / actionsPerRow) - (ImGui.GetStyle().ItemSpacing.X * ((actionsPerRow - 1f) / actionsPerRow)));
var actionSize = new Vector2((WindowWidth / ActionsPerRow) - (ImGui.GetStyle().ItemSpacing.X * ((ActionsPerRow - 1f) / ActionsPerRow)));
ImGui.PushStyleColor(ImGuiCol.Button, Vector4.Zero);
ImGui.PushStyleColor(ImGuiCol.ButtonActive, Vector4.Zero);
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, Vector4.Zero);
@@ -87,7 +95,7 @@ public sealed unsafe partial class Craft : Window, IDisposable
ImGui.EndTooltip();
}
ImGui.PopID();
if (i % actionsPerRow != (actionsPerRow - 1))
if (i % ActionsPerRow != (ActionsPerRow - 1))
ImGui.SameLine();
}
+8 -7
View File
@@ -11,6 +11,9 @@ public class Settings : Window
{
private static Configuration Config => Service.Configuration;
private const int OptionWidth = 200;
private static Vector2 OptionButtonSize => new(OptionWidth, ImGuiUtils.ButtonHeight);
public Settings() : base("Craftimizer Settings")
{
Service.WindowSystem.AddWindow(this);
@@ -37,7 +40,7 @@ public class Settings : Window
private static void DrawOption(string label, string tooltip, int val, Action<int> setter, ref bool isDirty)
{
ImGui.SetNextItemWidth(200);
ImGui.SetNextItemWidth(OptionWidth);
if (ImGui.InputInt(label, ref val))
{
setter(val);
@@ -49,7 +52,7 @@ public class Settings : Window
private static void DrawOption(string label, string tooltip, float val, Action<float> setter, ref bool isDirty)
{
ImGui.SetNextItemWidth(200);
ImGui.SetNextItemWidth(OptionWidth);
if (ImGui.InputFloat(label, ref val))
{
setter(val);
@@ -137,14 +140,13 @@ public class Settings : Window
ImGuiUtils.BeginGroupPanel("General");
ImGui.SetNextItemWidth(200);
if (ImGui.Button("Reset to Default"))
if (ImGui.Button("Reset to Default", OptionButtonSize))
{
config = defaultConfig;
isDirty = true;
}
ImGui.SetNextItemWidth(200);
ImGui.SetNextItemWidth(OptionWidth);
if (ImGui.BeginCombo("Algorithm", GetAlgorithmName(config.Algorithm)))
{
foreach (var alg in Enum.GetValues<SolverAlgorithm>())
@@ -321,8 +323,7 @@ public class Settings : Window
ref isDirty
);
ImGui.SetNextItemWidth(200);
if (ImGui.Button("Normalize Weights"))
if (ImGui.Button("Normalize Weights", OptionButtonSize))
{
var total = config.ScoreProgressBonus +
config.ScoreQualityBonus +
+2 -3
View File
@@ -309,8 +309,8 @@ public sealed partial class Simulator : Window, IDisposable
var totalWidth = drawParams.Total;
var halfWidth = (totalWidth - ImGui.GetStyle().ItemSpacing.X) / 2f;
var quarterWidth = (halfWidth - ImGui.GetStyle().ItemSpacing.X) / 2f;
var halfButtonSize = new Vector2(halfWidth, ImGui.CalcTextSize("A").Y + ImGui.GetStyle().FramePadding.Y * 2);
var quarterButtonSize = new Vector2(quarterWidth, ImGui.CalcTextSize("A").Y + ImGui.GetStyle().FramePadding.Y * 2);
var halfButtonSize = new Vector2(halfWidth, ImGuiUtils.ButtonHeight);
var quarterButtonSize = new Vector2(quarterWidth, ImGuiUtils.ButtonHeight);
var conditionRandomnessText = "Condition Randomness";
var conditionRandomness = Config.ConditionRandomness;
@@ -343,7 +343,6 @@ public sealed partial class Simulator : Window, IDisposable
ImGui.SameLine();
ImGui.SetNextItemWidth(halfWidth);
DrawSimulationGenerateButton(halfButtonSize);
//