fix: properly size and position helpers

This commit is contained in:
Anna 2021-11-23 12:54:44 -05:00
parent 1a489d2024
commit c83aa86108
4 changed files with 54 additions and 21 deletions

View File

@ -8,7 +8,8 @@ using Dalamud.Plugin;
namespace Glamaholic {
// ReSharper disable once ClassNeverInstantiated.Global
public class Plugin : IDalamudPlugin {
public string Name => "Glamaholic";
internal const string PluginName = "Glamaholic";
public string Name => PluginName;
[PluginService]
internal DalamudPluginInterface Interface { get; init; }

View File

@ -1,5 +1,4 @@
using Dalamud.Interface;
using FFXIVClientStructs.FFXIV.Component.GUI;
using FFXIVClientStructs.FFXIV.Component.GUI;
using ImGuiNET;
namespace Glamaholic.Ui.Helpers {
@ -28,13 +27,15 @@ namespace Glamaholic.Ui.Helpers {
return;
}
ImGui.SetNextWindowPos(drawPos.Value);
if (!ImGui.Begin("##glamaholic-helper-open", HelperUtil.HelperWindowFlags)) {
ImGui.End();
return;
using (new HelperUtil.HelperStyles()) {
ImGui.SetNextWindowPos(drawPos.Value, ImGuiCond.Appearing);
if (!ImGui.Begin("##glamaholic-helper-open", HelperUtil.HelperWindowFlags)) {
ImGui.End();
return;
}
}
ImGui.SetNextItemWidth(ImGui.CalcTextSize(this.Ui.Plugin.Name).X + ImGui.GetStyle().ItemInnerSpacing.X * 2 + 32 * ImGuiHelpers.GlobalScale);
ImGui.SetNextItemWidth(HelperUtil.DropdownWidth());
if (ImGui.BeginCombo("##glamaholic-helper-examine-combo", this.Ui.Plugin.Name)) {
if (ImGui.Selectable($"Open {this.Ui.Plugin.Name}")) {
this.Ui.OpenMainInterface();
@ -42,6 +43,8 @@ namespace Glamaholic.Ui.Helpers {
ImGui.EndCombo();
}
ImGui.SetNextWindowPos(drawPos.Value);
ImGui.End();
}

View File

@ -1,5 +1,4 @@
using System.Collections.Generic;
using Dalamud.Interface;
using FFXIVClientStructs.FFXIV.Client.Game;
using FFXIVClientStructs.FFXIV.Component.GUI;
using ImGuiNET;
@ -30,13 +29,16 @@ namespace Glamaholic.Ui.Helpers {
return;
}
ImGui.SetNextWindowPos(drawPos.Value);
if (!ImGui.Begin("##glamaholic-helper-examine", HelperUtil.HelperWindowFlags)) {
ImGui.End();
return;
using (new HelperUtil.HelperStyles()) {
// get first frame
ImGui.SetNextWindowPos(drawPos.Value, ImGuiCond.Appearing);
if (!ImGui.Begin("##glamaholic-helper-examine", HelperUtil.HelperWindowFlags)) {
ImGui.End();
return;
}
}
ImGui.SetNextItemWidth(ImGui.CalcTextSize(this.Ui.Plugin.Name).X + ImGui.GetStyle().ItemInnerSpacing.X * 2 + 32 * ImGuiHelpers.GlobalScale);
ImGui.SetNextItemWidth(HelperUtil.DropdownWidth());
if (ImGui.BeginCombo("##glamaholic-helper-examine-combo", this.Ui.Plugin.Name)) {
if (ImGui.Selectable("Create glamour plate")) {
this.CopyToGlamourPlate();
@ -52,6 +54,8 @@ namespace Glamaholic.Ui.Helpers {
ImGui.EndCombo();
}
ImGui.SetWindowPos(drawPos.Value);
ImGui.End();
}

View File

@ -1,4 +1,6 @@
using System.Numerics;
using System;
using System.Numerics;
using Dalamud.Interface;
using FFXIVClientStructs.FFXIV.Component.GUI;
using ImGuiNET;
@ -15,9 +17,10 @@ namespace Glamaholic.Ui.Helpers {
| ImGuiWindowFlags.NoScrollbar
| ImGuiWindowFlags.NoSavedSettings
| ImGuiWindowFlags.NoFocusOnAppearing
| ImGuiWindowFlags.AlwaysAutoResize;
| ImGuiWindowFlags.AlwaysAutoResize
| ImGuiWindowFlags.NoDocking;
internal static unsafe Vector2? DrawPosForAddon(AtkUnitBase* addon) {
internal static unsafe Vector2? DrawPosForAddon(AtkUnitBase* addon, bool right = false) {
if (addon == null) {
return null;
}
@ -27,10 +30,32 @@ namespace Glamaholic.Ui.Helpers {
return null;
}
return new Vector2(addon->X, addon->Y)
- new Vector2(0, ImGui.CalcTextSize("A").Y)
- new Vector2(0, ImGui.GetStyle().ItemInnerSpacing.Y * 2)
- new Vector2(0, ImGui.GetStyle().CellPadding.Y * 2);
var xModifier = right
? root->Width - DropdownWidth()
: 0;
return ImGuiHelpers.MainViewport.Pos
+ new Vector2(addon->X, addon->Y)
+ Vector2.UnitX * xModifier
- Vector2.UnitY * ImGui.CalcTextSize("A")
- Vector2.UnitY * (ImGui.GetStyle().FramePadding.Y + ImGui.GetStyle().FrameBorderSize);
}
internal static float DropdownWidth() {
// arrow size is GetFrameHeight
return (ImGui.CalcTextSize(Plugin.PluginName).X + ImGui.GetStyle().ItemInnerSpacing.X * 2 + ImGui.GetFrameHeight()) * ImGuiHelpers.GlobalScale;
}
internal class HelperStyles : IDisposable {
internal HelperStyles() {
ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, Vector2.Zero);
ImGui.PushStyleVar(ImGuiStyleVar.WindowBorderSize, 0);
ImGui.PushStyleVar(ImGuiStyleVar.WindowMinSize, Vector2.Zero);
}
public void Dispose() {
ImGui.PopStyleVar(3);
}
}
}
}