feat: add ScaledRelativeSameLine(), ScaledDummy() to ImGuiHelpers

This commit is contained in:
goat 2021-04-05 18:22:19 +02:00
parent 63a289f769
commit 9621cb5428

View file

@ -1,3 +1,4 @@
using System.Numerics;
using ImGuiNET;
namespace Dalamud.Interface
@ -9,6 +10,11 @@ namespace Dalamud.Interface
{
private static uint mainViewportId;
/// <summary>
/// Gets the global Dalamud scale.
/// </summary>
public static float GlobalScale { get; private set; }
/// <summary>
/// Force this ImGui window to stay inside the main game window.
/// </summary>
@ -25,5 +31,27 @@ namespace Dalamud.Interface
return mainViewportId;
}
/// <summary>
/// Create a dummy scaled by the global Dalamud scale.
/// </summary>
/// <param name="size">The size of the dummy.</param>
public static void ScaledDummy(Vector2 size) => ImGui.Dummy(size * GlobalScale);
/// <summary>
/// Use a relative ImGui.SameLine() from your current cursor position, scaled by the Dalamud global scale.
/// </summary>
/// <param name="offset">The offset from your current cursor position.</param>
/// <param name="spacing">The spacing to use.</param>
public static void ScaledRelativeSameLine(float offset, float spacing = -1.0f) =>
ImGui.SameLine(ImGui.GetCursorPosX() + (offset * GlobalScale));
/// <summary>
/// Get data needed for each new frame.
/// </summary>
internal static void NewFrame()
{
GlobalScale = ImGui.GetIO().FontGlobalScale;
}
}
}