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

@@ -117,7 +117,7 @@ public class CompactUi : Window, IDisposable
{ {
ImGui.PushStyleColor(ImGuiCol.Button, ImGui.GetStyle().Colors[(int)ImGuiCol.ButtonHovered]); ImGui.PushStyleColor(ImGuiCol.Button, ImGui.GetStyle().Colors[(int)ImGuiCol.ButtonHovered]);
} }
if (ImGui.Button(FontAwesomeIcon.User.ToIconString(), new Vector2((UiShared.GetWindowContentRegionWidth() - ImGui.GetWindowContentRegionMin().X) / 2, 30))) if (ImGui.Button(FontAwesomeIcon.User.ToIconString(), new Vector2((UiShared.GetWindowContentRegionWidth() - ImGui.GetWindowContentRegionMin().X) / 2, 30 * ImGuiHelpers.GlobalScale)))
{ {
showSyncShells = false; showSyncShells = false;
} }
@@ -135,7 +135,7 @@ public class CompactUi : Window, IDisposable
{ {
ImGui.PushStyleColor(ImGuiCol.Button, ImGui.GetStyle().Colors[(int)ImGuiCol.ButtonHovered]); ImGui.PushStyleColor(ImGuiCol.Button, ImGui.GetStyle().Colors[(int)ImGuiCol.ButtonHovered]);
} }
if (ImGui.Button(FontAwesomeIcon.UserFriends.ToIconString(), new Vector2((UiShared.GetWindowContentRegionWidth() - ImGui.GetWindowContentRegionMin().X) / 2, 30))) if (ImGui.Button(FontAwesomeIcon.UserFriends.ToIconString(), new Vector2((UiShared.GetWindowContentRegionWidth() - ImGui.GetWindowContentRegionMin().X) / 2, 30 * ImGuiHelpers.GlobalScale)))
{ {
showSyncShells = true; showSyncShells = true;
} }
@@ -313,12 +313,11 @@ public class CompactUi : Window, IDisposable
{ {
var pauseIcon = entry.IsPaused ? FontAwesomeIcon.Play : FontAwesomeIcon.Pause; var pauseIcon = entry.IsPaused ? FontAwesomeIcon.Play : FontAwesomeIcon.Pause;
var pauseIconSize = UiShared.GetIconButtonSize(pauseIcon); var pauseIconSize = UiShared.GetIconButtonSize(pauseIcon);
var trashButtonSize = UiShared.GetIconButtonSize(FontAwesomeIcon.Trash);
var barButtonSize = UiShared.GetIconButtonSize(FontAwesomeIcon.Bars); var barButtonSize = UiShared.GetIconButtonSize(FontAwesomeIcon.Bars);
var entryUID = string.IsNullOrEmpty(entry.VanityUID) ? entry.OtherUID : entry.VanityUID; var entryUID = string.IsNullOrEmpty(entry.VanityUID) ? entry.OtherUID : entry.VanityUID;
var textSize = ImGui.CalcTextSize(entryUID); var textSize = ImGui.CalcTextSize(entryUID);
var originalY = ImGui.GetCursorPosY(); var originalY = ImGui.GetCursorPosY();
var buttonSizes = pauseIconSize.Y + trashButtonSize.Y + barButtonSize.Y; var buttonSizes = pauseIconSize.Y + barButtonSize.Y;
var spacingX = ImGui.GetStyle().ItemSpacing.X; var spacingX = ImGui.GetStyle().ItemSpacing.X;
var windowEndX = ImGui.GetWindowContentRegionMin().X + UiShared.GetWindowContentRegionWidth(); var windowEndX = ImGui.GetWindowContentRegionMin().X + UiShared.GetWindowContentRegionWidth();
@@ -402,7 +401,7 @@ public class CompactUi : Window, IDisposable
{ {
ImGui.SetCursorPosY(originalY); ImGui.SetCursorPosY(originalY);
ImGui.SetNextItemWidth(UiShared.GetWindowContentRegionWidth() - ImGui.GetCursorPosX() - buttonSizes - ImGui.GetStyle().ItemSpacing.X * 3); ImGui.SetNextItemWidth(UiShared.GetWindowContentRegionWidth() - ImGui.GetCursorPosX() - buttonSizes - ImGui.GetStyle().ItemSpacing.X * 2);
if (ImGui.InputTextWithHint("", "Nick/Notes", ref EditUserComment, 255, ImGuiInputTextFlags.EnterReturnsTrue)) if (ImGui.InputTextWithHint("", "Nick/Notes", ref EditUserComment, 255, ImGuiInputTextFlags.EnterReturnsTrue))
{ {
_configuration.SetCurrentServerUidComment(entry.OtherUID, EditUserComment); _configuration.SetCurrentServerUidComment(entry.OtherUID, EditUserComment);

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Numerics;
using Dalamud.Interface; using Dalamud.Interface;
using Dalamud.Interface.Components; using Dalamud.Interface.Components;
using Dalamud.Utility; using Dalamud.Utility;
@@ -15,12 +16,6 @@ public class SelectGroupForPairUi
/// </summary> /// </summary>
private bool _show; private bool _show;
/// <summary>
/// Has the panel already been opened?
/// This is used to prevent double opening
/// </summary>
private bool _opened;
/// <summary> /// <summary>
/// The group UI is always open for a specific pair. This defines which pair the UI is open for. /// The group UI is always open for a specific pair. This defines which pair the UI is open for.
/// </summary> /// </summary>
@@ -61,29 +56,32 @@ public class SelectGroupForPairUi
return; return;
} }
// Is the popup not supposed to show? Set _opened to false so we can re-open it.
if (!_show)
{
_opened = false;
}
var name = PairName(showUidForEntry, _pair.OtherUID, _pair.VanityUID); var name = PairName(showUidForEntry, _pair.OtherUID, _pair.VanityUID);
var popupName = $"Choose Groups for {name}"; var popupName = $"Choose Groups for {name}";
// Is the popup supposed to show but did not open yet? Open it // Is the popup supposed to show but did not open yet? Open it
if (_show && !_opened) if (_show)
{ {
ImGui.OpenPopup(popupName); ImGui.OpenPopup(popupName);
_opened = true; _show = false;
} }
if (ImGui.BeginPopupModal(popupName, ref _show, UiShared.PopupWindowFlags)) if (ImGui.BeginPopup(popupName))
{ {
var tags = _tagHandler.GetAllTagsSorted();
var childHeight = tags.Count != 0 ? tags.Count * 25 : 1;
var childSize = new Vector2(0, childHeight > 100 ? 100 : childHeight) * ImGuiHelpers.GlobalScale;
UiShared.FontText($"Select the groups you want {name} to be in.", UiBuilder.DefaultFont); UiShared.FontText($"Select the groups you want {name} to be in.", UiBuilder.DefaultFont);
foreach (var tag in _tagHandler.GetAllTagsSorted()) if (ImGui.BeginChild(name + "##listGroups", childSize))
{ {
UiShared.DrawWithID($"groups-pair-{_pair.OtherUID}-{tag}", () => DrawGroupName(_pair, tag)); foreach (var tag in tags)
{
UiShared.DrawWithID($"groups-pair-{_pair.OtherUID}-{tag}", () => DrawGroupName(_pair, tag));
}
ImGui.EndChild();
} }
ImGui.Separator();
UiShared.FontText($"Create a new group for {name}.", UiBuilder.DefaultFont); UiShared.FontText($"Create a new group for {name}.", UiBuilder.DefaultFont);
if (ImGuiComponents.IconButton(FontAwesomeIcon.Plus)) if (ImGuiComponents.IconButton(FontAwesomeIcon.Plus))
{ {
@@ -97,19 +95,14 @@ public class SelectGroupForPairUi
HandleAddTag(); HandleAddTag();
} }
} }
UiShared.SetScaledWindowSize(375);
ImGui.EndPopup(); ImGui.EndPopup();
} }
else
{
_show = false;
}
} }
private void DrawGroupName(ClientPairDto pair, string name) private void DrawGroupName(ClientPairDto pair, string name)
{ {
bool hasTagBefore = _tagHandler.HasTag(pair, name); var hasTagBefore = _tagHandler.HasTag(pair, name);
bool hasTag = hasTagBefore; var hasTag = hasTagBefore;
if (ImGui.Checkbox(name, ref hasTag)) if (ImGui.Checkbox(name, ref hasTag))
{ {
if (hasTag) if (hasTag)

View File

@@ -33,6 +33,10 @@ public class SelectPairForGroupUi
public void Draw(List<ClientPairDto> pairs, Dictionary<string, bool> showUidForEntry) public void Draw(List<ClientPairDto> pairs, Dictionary<string, bool> showUidForEntry)
{ {
var workHeight = ImGui.GetMainViewport().WorkSize.Y / ImGuiHelpers.GlobalScale;
var minSize = new Vector2(300, workHeight < 400 ? workHeight : 400) * ImGuiHelpers.GlobalScale;
var maxSize = new Vector2(300, 1000) * ImGuiHelpers.GlobalScale;
var popupName = $"Choose Users for Group {_tag}"; var popupName = $"Choose Users for Group {_tag}";
if (!_show) if (!_show)
@@ -42,12 +46,13 @@ public class SelectPairForGroupUi
if (_show && !_opened) if (_show && !_opened)
{ {
ImGui.SetNextWindowSize(new Vector2(300, 400)); ImGui.SetNextWindowSize(minSize);
UiShared.CenterNextWindow(minSize.X, minSize.Y, ImGuiCond.Always);
ImGui.OpenPopup(popupName); ImGui.OpenPopup(popupName);
_opened = true; _opened = true;
} }
ImGui.SetNextWindowSizeConstraints(new Vector2(300, 400), new Vector2(300, 1000)); ImGui.SetNextWindowSizeConstraints(minSize, maxSize);
if (ImGui.BeginPopupModal(popupName, ref _show, ImGuiWindowFlags.Popup | ImGuiWindowFlags.Modal)) if (ImGui.BeginPopupModal(popupName, ref _show, ImGuiWindowFlags.Popup | ImGuiWindowFlags.Modal))
{ {
UiShared.FontText($"Select users for group {_tag}", UiBuilder.DefaultFont); UiShared.FontText($"Select users for group {_tag}", UiBuilder.DefaultFont);
@@ -70,6 +75,7 @@ public class SelectPairForGroupUi
} }
} }
} }
ImGui.EndPopup();
} }
else else
{ {

View File

@@ -274,7 +274,8 @@ namespace MareSynchronos.UI
} }
else else
{ {
ImGui.SetNextItemWidth(UiShared.GetWindowContentRegionWidth() - ImGui.GetCursorPosX()); var buttonSizes = UiShared.GetIconButtonSize(FontAwesomeIcon.Bars).X + UiShared.GetIconSize(FontAwesomeIcon.LockOpen).X;
ImGui.SetNextItemWidth(UiShared.GetWindowContentRegionWidth() - ImGui.GetCursorPosX() - buttonSizes - ImGui.GetStyle().ItemSpacing.X * 2);
if (ImGui.InputTextWithHint("", "Comment/Notes", ref _editGroupComment, 255, ImGuiInputTextFlags.EnterReturnsTrue)) if (ImGui.InputTextWithHint("", "Comment/Notes", ref _editGroupComment, 255, ImGuiInputTextFlags.EnterReturnsTrue))
{ {
_configuration.SetCurrentServerGidComment(group.GID, _editGroupComment); _configuration.SetCurrentServerGidComment(group.GID, _editGroupComment);
@@ -560,11 +561,10 @@ namespace MareSynchronos.UI
var entryUID = string.IsNullOrEmpty(entry.UserAlias) ? entry.UserUID : entry.UserAlias; var entryUID = string.IsNullOrEmpty(entry.UserAlias) ? entry.UserUID : entry.UserAlias;
var textSize = ImGui.CalcTextSize(entryUID); var textSize = ImGui.CalcTextSize(entryUID);
var originalY = ImGui.GetCursorPosY(); var originalY = ImGui.GetCursorPosY();
var buttonSizes = plusButtonSize.Y;
var userIsMod = entry.IsModerator ?? false; var userIsMod = entry.IsModerator ?? false;
var userIsOwner = string.Equals(entryUID, ownerUid, StringComparison.Ordinal); var userIsOwner = string.Equals(entryUID, ownerUid, StringComparison.Ordinal);
var textPos = originalY + plusButtonSize.Y / 2 - textSize.Y / 2; var textPos = originalY + barButtonSize.Y / 2 - textSize.Y / 2;
ImGui.SetCursorPosY(textPos); ImGui.SetCursorPosY(textPos);
if (isPausedByYou || (entry.IsPaused ?? false)) if (isPausedByYou || (entry.IsPaused ?? false))
{ {
@@ -628,6 +628,8 @@ namespace MareSynchronos.UI
{ {
playerText = entryUID; playerText = entryUID;
} }
bool plusButtonShown = !_apiController.PairedClients.Any(p => string.Equals(p.OtherUID, entry.UserUID, StringComparison.Ordinal));
ImGui.SameLine(); ImGui.SameLine();
if (!string.Equals(_mainUi.EditNickEntry, entry.UserUID, StringComparison.Ordinal)) if (!string.Equals(_mainUi.EditNickEntry, entry.UserUID, StringComparison.Ordinal))
@@ -662,8 +664,10 @@ namespace MareSynchronos.UI
else else
{ {
ImGui.SetCursorPosY(originalY); ImGui.SetCursorPosY(originalY);
var buttonSizes = (plusButtonShown ? plusButtonSize.X : 0) + barButtonSize.X;
var buttons = plusButtonShown ? 2 : 1;
ImGui.SetNextItemWidth(UiShared.GetWindowContentRegionWidth() - ImGui.GetCursorPosX() - buttonSizes - ImGui.GetStyle().ItemSpacing.X * 2); ImGui.SetNextItemWidth(UiShared.GetWindowContentRegionWidth() - ImGui.GetCursorPosX() - buttonSizes - ImGui.GetStyle().ItemSpacing.X * buttons);
if (ImGui.InputTextWithHint("", "Nick/Notes", ref _mainUi.EditUserComment, 255, ImGuiInputTextFlags.EnterReturnsTrue)) if (ImGui.InputTextWithHint("", "Nick/Notes", ref _mainUi.EditUserComment, 255, ImGuiInputTextFlags.EnterReturnsTrue))
{ {
_configuration.SetCurrentServerUidComment(entry.UserUID, _mainUi.EditUserComment); _configuration.SetCurrentServerUidComment(entry.UserUID, _mainUi.EditUserComment);
@@ -678,15 +682,13 @@ namespace MareSynchronos.UI
UiShared.AttachToolTip("Hit ENTER to save\nRight click to cancel"); UiShared.AttachToolTip("Hit ENTER to save\nRight click to cancel");
} }
bool plusButtonShown = !_apiController.PairedClients.Any(p => string.Equals(p.OtherUID, entry.UserUID, StringComparison.Ordinal));
if (plusButtonShown) if (plusButtonShown)
{ {
ImGui.SetCursorPosY(originalY);
var barWidth = isOwner || (isModerator && !userIsMod && !userIsOwner) var barWidth = isOwner || (isModerator && !userIsMod && !userIsOwner)
? barButtonSize.X + ImGui.GetStyle().ItemSpacing.X ? barButtonSize.X + ImGui.GetStyle().ItemSpacing.X
: 0; : 0;
ImGui.SameLine(ImGui.GetWindowContentRegionMin().X + UiShared.GetWindowContentRegionWidth() - plusButtonSize.X - barWidth); ImGui.SameLine(ImGui.GetWindowContentRegionMin().X + UiShared.GetWindowContentRegionWidth() - plusButtonSize.X - barWidth);
ImGui.SetCursorPosY(originalY);
if (ImGuiComponents.IconButton(FontAwesomeIcon.Plus)) if (ImGuiComponents.IconButton(FontAwesomeIcon.Plus))
{ {
@@ -697,8 +699,8 @@ namespace MareSynchronos.UI
if (isOwner || (isModerator && !userIsMod && !userIsOwner)) if (isOwner || (isModerator && !userIsMod && !userIsOwner))
{ {
ImGui.SetCursorPosY(originalY);
ImGui.SameLine(ImGui.GetWindowContentRegionMin().X + UiShared.GetWindowContentRegionWidth() - barButtonSize.X); ImGui.SameLine(ImGui.GetWindowContentRegionMin().X + UiShared.GetWindowContentRegionWidth() - barButtonSize.X);
ImGui.SetCursorPosY(originalY);
if (ImGuiComponents.IconButton(FontAwesomeIcon.Bars)) if (ImGuiComponents.IconButton(FontAwesomeIcon.Bars))
{ {

View File

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