mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-27 19:09:18 +01:00
52 lines
1.9 KiB
C#
52 lines
1.9 KiB
C#
using System.Numerics;
|
|
using ImGuiNET;
|
|
|
|
namespace Dalamud.Interface
|
|
{
|
|
/// <summary>
|
|
/// Class containing various helper methods for use with ImGui inside Dalamud.
|
|
/// </summary>
|
|
public static class ImGuiHelpers
|
|
{
|
|
/// <summary>
|
|
/// Gets the main viewport.
|
|
/// </summary>
|
|
public static ImGuiViewportPtr MainViewport { get; internal set; }
|
|
|
|
/// <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>
|
|
public static void ForceMainViewport() => ImGui.SetNextWindowViewport(MainViewport.ID);
|
|
|
|
/// <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));
|
|
|
|
public static void SetNextWindowPosRelativeMainViewport(
|
|
Vector2 position, ImGuiCond condition = ImGuiCond.None, Vector2 pivot = default)
|
|
=> ImGui.SetNextWindowPos(position + MainViewport.Pos, condition, pivot);
|
|
|
|
/// <summary>
|
|
/// Get data needed for each new frame.
|
|
/// </summary>
|
|
internal static void NewFrame()
|
|
{
|
|
GlobalScale = ImGui.GetIO().FontGlobalScale;
|
|
}
|
|
}
|
|
}
|