From 9621cb54287d7e4fa5df3814e002516d50204adc Mon Sep 17 00:00:00 2001
From: goat <16760685+goaaats@users.noreply.github.com>
Date: Mon, 5 Apr 2021 18:22:19 +0200
Subject: [PATCH] feat: add ScaledRelativeSameLine(), ScaledDummy() to
ImGuiHelpers
---
Dalamud/Interface/ImGuiHelpers.cs | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/Dalamud/Interface/ImGuiHelpers.cs b/Dalamud/Interface/ImGuiHelpers.cs
index 57ff6e405..7cedd1a12 100644
--- a/Dalamud/Interface/ImGuiHelpers.cs
+++ b/Dalamud/Interface/ImGuiHelpers.cs
@@ -1,3 +1,4 @@
+using System.Numerics;
using ImGuiNET;
namespace Dalamud.Interface
@@ -9,6 +10,11 @@ namespace Dalamud.Interface
{
private static uint mainViewportId;
+ ///
+ /// Gets the global Dalamud scale.
+ ///
+ public static float GlobalScale { get; private set; }
+
///
/// Force this ImGui window to stay inside the main game window.
///
@@ -25,5 +31,27 @@ namespace Dalamud.Interface
return mainViewportId;
}
+
+ ///
+ /// Create a dummy scaled by the global Dalamud scale.
+ ///
+ /// The size of the dummy.
+ public static void ScaledDummy(Vector2 size) => ImGui.Dummy(size * GlobalScale);
+
+ ///
+ /// Use a relative ImGui.SameLine() from your current cursor position, scaled by the Dalamud global scale.
+ ///
+ /// The offset from your current cursor position.
+ /// The spacing to use.
+ public static void ScaledRelativeSameLine(float offset, float spacing = -1.0f) =>
+ ImGui.SameLine(ImGui.GetCursorPosX() + (offset * GlobalScale));
+
+ ///
+ /// Get data needed for each new frame.
+ ///
+ internal static void NewFrame()
+ {
+ GlobalScale = ImGui.GetIO().FontGlobalScale;
+ }
}
}