Popup optimisation
This commit is contained in:
@@ -41,6 +41,10 @@ public class UiShared : IDisposable
|
||||
public bool UidFontBuilt { get; private set; }
|
||||
public static bool CtrlPressed() => (GetKeyState(0xA2) & 0x8000) != 0 || (GetKeyState(0xA3) & 0x8000) != 0;
|
||||
public static bool ShiftPressed() => (GetKeyState(0xA1) & 0x8000) != 0 || (GetKeyState(0xA0) & 0x8000) != 0;
|
||||
|
||||
public static ImGuiWindowFlags PopupWindowFlags = ImGuiWindowFlags.NoResize |
|
||||
ImGuiWindowFlags.NoScrollbar |
|
||||
ImGuiWindowFlags.NoScrollWithMouse;
|
||||
|
||||
public ApiController ApiController => _apiController;
|
||||
|
||||
@@ -98,6 +102,38 @@ public class UiShared : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetScaledWindowSize(float width, bool centerWindow = true)
|
||||
{
|
||||
var newLineHeight = ImGui.GetCursorPosY();
|
||||
ImGui.NewLine();
|
||||
newLineHeight = ImGui.GetCursorPosY() - newLineHeight;
|
||||
var x = width * ImGuiHelpers.GlobalScale;
|
||||
var y = ImGui.GetCursorPos().Y + ImGui.GetWindowContentRegionMin().Y - newLineHeight * 2 - ImGui.GetStyle().ItemSpacing.Y;
|
||||
|
||||
if (centerWindow)
|
||||
{
|
||||
var center = ImGui.GetMainViewport().GetCenter();
|
||||
ImGui.SetWindowPos(new Vector2(center.X - x / 2, center.Y - y / 2));
|
||||
}
|
||||
|
||||
ImGui.SetWindowSize(new Vector2(x, y));
|
||||
}
|
||||
|
||||
public static void SetScaledWindowSize(float width, float height, bool centerWindow = true)
|
||||
{
|
||||
ImGui.SameLine();
|
||||
var x = width * ImGuiHelpers.GlobalScale;
|
||||
var y = height * ImGuiHelpers.GlobalScale;
|
||||
|
||||
if (centerWindow)
|
||||
{
|
||||
var center = ImGui.GetMainViewport().GetCenter();
|
||||
ImGui.SetWindowPos(new Vector2(center.X - x / 2, center.Y - y / 2));
|
||||
}
|
||||
|
||||
ImGui.SetWindowSize(new Vector2(x, y));
|
||||
}
|
||||
|
||||
public static void DrawWithID(string id, Action drawSubSection)
|
||||
{
|
||||
ImGui.PushID(id);
|
||||
|
||||
Reference in New Issue
Block a user