Popupmodal to normal popup and some UI shenanigans (#37)

* Button height now adjusts to the font size

* Popup now adjusts to the font size
Popup is now centered when opened

* ui shenanigans

* PopupModal to normal Popup
This commit is contained in:
xPumaa
2023-01-22 23:36:27 +01:00
committed by GitHub
parent 45cacc1080
commit 1c95a6d40e
5 changed files with 59 additions and 55 deletions

View File

@@ -107,31 +107,35 @@ public class UiShared : IDisposable
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;
SetScaledWindowSize(width, y, centerWindow, scaledHeight: true);
}
public static void SetScaledWindowSize(float width, float height, bool centerWindow = true, bool scaledHeight = false)
{
ImGui.SameLine();
var x = width * ImGuiHelpers.GlobalScale;
var y = scaledHeight ? height : height * ImGuiHelpers.GlobalScale;
if (centerWindow)
{
var center = ImGui.GetMainViewport().GetCenter();
ImGui.SetWindowPos(new Vector2(center.X - x / 2, center.Y - y / 2));
CenterWindow(x, y);
}
ImGui.SetWindowSize(new Vector2(x, y));
}
public static void SetScaledWindowSize(float width, float height, bool centerWindow = true)
private static void CenterWindow(float width, float height, ImGuiCond cond = ImGuiCond.None)
{
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));
var center = ImGui.GetMainViewport().GetCenter();
ImGui.SetWindowPos(new Vector2(center.X - width / 2, center.Y - height / 2), cond);
}
public static void CenterNextWindow(float width, float height, ImGuiCond cond = ImGuiCond.None)
{
var center = ImGui.GetMainViewport().GetCenter();
ImGui.SetNextWindowPos(new Vector2(center.X - width / 2, center.Y - height / 2), cond);
}
public static void DrawWithID(string id, Action drawSubSection)