diff --git a/MareSynchronos/UI/Components/DrawFolderBase.cs b/MareSynchronos/UI/Components/DrawFolderBase.cs index 8260f68..ac4b71e 100644 --- a/MareSynchronos/UI/Components/DrawFolderBase.cs +++ b/MareSynchronos/UI/Components/DrawFolderBase.cs @@ -17,6 +17,7 @@ public abstract class DrawFolderBase : IDrawFolder private float _menuWidth = -1; public int OnlinePairs => DrawPairs.Count(u => u.Pair.IsOnline); public int TotalPairs => _allPairs.Count; + private bool _wasHovered = false; protected DrawFolderBase(string id, IImmutableList drawPairs, IImmutableList allPairs, TagHandler tagHandler, UiSharedService uiSharedService) @@ -36,33 +37,41 @@ public abstract class DrawFolderBase : IDrawFolder if (!RenderIfEmpty && !DrawPairs.Any()) return; using var id = ImRaii.PushId("folder_" + _id); - - // draw opener - var icon = _tagHandler.IsTagOpen(_id) ? FontAwesomeIcon.CaretDown : FontAwesomeIcon.CaretRight; - - ImGui.AlignTextToFramePadding(); - - _uiSharedService.IconText(icon); - if (ImGui.IsItemClicked()) + var color = ImRaii.PushColor(ImGuiCol.ChildBg, ImGui.GetColorU32(ImGuiCol.FrameBgHovered), _wasHovered); + using (ImRaii.Child("folder__" + _id, new System.Numerics.Vector2(UiSharedService.GetWindowContentRegionWidth() - ImGui.GetCursorPosX(), ImGui.GetFrameHeight()))) { - _tagHandler.SetTagOpen(_id, !_tagHandler.IsTagOpen(_id)); + // draw opener + var icon = _tagHandler.IsTagOpen(_id) ? FontAwesomeIcon.CaretDown : FontAwesomeIcon.CaretRight; + + ImGui.AlignTextToFramePadding(); + + _uiSharedService.IconText(icon); + if (ImGui.IsItemClicked()) + { + _tagHandler.SetTagOpen(_id, !_tagHandler.IsTagOpen(_id)); + } + + ImGui.SameLine(); + var leftSideEnd = DrawIcon(); + + ImGui.SameLine(); + var rightSideStart = DrawRightSideInternal(); + + // draw name + ImGui.SameLine(leftSideEnd); + DrawName(rightSideStart - leftSideEnd); } - ImGui.SameLine(); - var leftSideEnd = DrawIcon(); + _wasHovered = ImGui.IsItemHovered(); - ImGui.SameLine(); - var rightSideStart = DrawRightSideInternal(); + color.Dispose(); - // draw name - ImGui.SameLine(leftSideEnd); - DrawName(rightSideStart - leftSideEnd); ImGui.Separator(); // if opened draw content if (_tagHandler.IsTagOpen(_id)) { - using var indent = ImRaii.PushIndent(_uiSharedService.GetIconData(FontAwesomeIcon.Bars).X + ImGui.GetStyle().ItemSpacing.X, false); + using var indent = ImRaii.PushIndent(_uiSharedService.GetIconData(FontAwesomeIcon.EllipsisV).X + ImGui.GetStyle().ItemSpacing.X, false); if (DrawPairs.Any()) { foreach (var item in DrawPairs) @@ -89,7 +98,7 @@ public abstract class DrawFolderBase : IDrawFolder private float DrawRightSideInternal() { - var barButtonSize = _uiSharedService.IconButtonSize(FontAwesomeIcon.Bars); + var barButtonSize = _uiSharedService.IconButtonSize(FontAwesomeIcon.EllipsisV); var spacingX = ImGui.GetStyle().ItemSpacing.X; var windowEndX = ImGui.GetWindowContentRegionMin().X + UiSharedService.GetWindowContentRegionWidth(); @@ -99,7 +108,7 @@ public abstract class DrawFolderBase : IDrawFolder if (RenderMenu) { ImGui.SameLine(windowEndX - barButtonSize.X); - if (UiSharedService.IconButton(FontAwesomeIcon.Bars)) + if (UiSharedService.IconButton(FontAwesomeIcon.EllipsisV)) { ImGui.OpenPopup("User Flyout Menu"); } diff --git a/MareSynchronos/UI/Components/DrawGroupedGroupFolder.cs b/MareSynchronos/UI/Components/DrawGroupedGroupFolder.cs index 1cd7e3b..d6a1b1e 100644 --- a/MareSynchronos/UI/Components/DrawGroupedGroupFolder.cs +++ b/MareSynchronos/UI/Components/DrawGroupedGroupFolder.cs @@ -12,6 +12,7 @@ public class DrawGroupedGroupFolder : IDrawFolder private readonly IEnumerable _groups; private readonly TagHandler _tagHandler; private readonly UiSharedService _uiSharedService; + private bool _wasHovered = false; public IImmutableList DrawPairs => throw new NotSupportedException(); public int OnlinePairs => _groups.SelectMany(g => g.DrawPairs).Where(g => g.Pair.IsOnline).DistinctBy(g => g.Pair.UserData.UID).Count(); @@ -30,31 +31,40 @@ public class DrawGroupedGroupFolder : IDrawFolder string _id = "__folder_syncshells"; using var id = ImRaii.PushId(_id); - - ImGui.Dummy(new Vector2(0f, ImGui.GetFrameHeight())); - using (ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, new Vector2(0f, 0f))) - ImGui.SameLine(); - - var icon = _tagHandler.IsTagOpen(_id) ? FontAwesomeIcon.CaretDown : FontAwesomeIcon.CaretRight; - _uiSharedService.IconText(icon); - if (ImGui.IsItemClicked()) + var color = ImRaii.PushColor(ImGuiCol.ChildBg, ImGui.GetColorU32(ImGuiCol.FrameBgHovered), _wasHovered); + using (ImRaii.Child("folder__" + _id, new System.Numerics.Vector2(UiSharedService.GetWindowContentRegionWidth() - ImGui.GetCursorPosX(), ImGui.GetFrameHeight()))) { - _tagHandler.SetTagOpen(_id, !_tagHandler.IsTagOpen(_id)); - } + ImGui.Dummy(new Vector2(0f, ImGui.GetFrameHeight())); + using (ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, new Vector2(0f, 0f))) + ImGui.SameLine(); + + var icon = _tagHandler.IsTagOpen(_id) ? FontAwesomeIcon.CaretDown : FontAwesomeIcon.CaretRight; + ImGui.AlignTextToFramePadding(); + + _uiSharedService.IconText(icon); + if (ImGui.IsItemClicked()) + { + _tagHandler.SetTagOpen(_id, !_tagHandler.IsTagOpen(_id)); + } - ImGui.SameLine(); - _uiSharedService.IconText(FontAwesomeIcon.UsersRectangle); - using (ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, ImGui.GetStyle().ItemSpacing with { X = ImGui.GetStyle().ItemSpacing.X / 2f })) - { ImGui.SameLine(); ImGui.AlignTextToFramePadding(); - ImGui.TextUnformatted("[" + OnlinePairs.ToString() + "]"); + _uiSharedService.IconText(FontAwesomeIcon.UsersRectangle); + using (ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, ImGui.GetStyle().ItemSpacing with { X = ImGui.GetStyle().ItemSpacing.X / 2f })) + { + ImGui.SameLine(); + ImGui.AlignTextToFramePadding(); + ImGui.TextUnformatted("[" + OnlinePairs.ToString() + "]"); + } + UiSharedService.AttachToolTip(OnlinePairs + " online in all of your joined syncshells" + Environment.NewLine + + TotalPairs + " pairs combined in all of your joined syncshells"); + ImGui.SameLine(); + ImGui.AlignTextToFramePadding(); + ImGui.TextUnformatted("All Syncshells"); } - UiSharedService.AttachToolTip(OnlinePairs + " online in all of your joined syncshells" + Environment.NewLine + - TotalPairs + " pairs combined in all of your joined syncshells"); - ImGui.SameLine(); - ImGui.AlignTextToFramePadding(); - ImGui.TextUnformatted("All Syncshells"); + color.Dispose(); + _wasHovered = ImGui.IsItemHovered(); + ImGui.Separator(); if (_tagHandler.IsTagOpen(_id)) diff --git a/MareSynchronos/UI/Components/DrawUserPair.cs b/MareSynchronos/UI/Components/DrawUserPair.cs index ff1ba7b..82adee9 100644 --- a/MareSynchronos/UI/Components/DrawUserPair.cs +++ b/MareSynchronos/UI/Components/DrawUserPair.cs @@ -27,6 +27,7 @@ public class DrawUserPair private readonly ServerConfigurationManager _serverConfigurationManager; private readonly UiSharedService _uiSharedService; private float _menuWidth = -1; + private bool _wasHovered = false; public DrawUserPair(string id, Pair entry, List syncedGroups, GroupFullInfoDto? currentGroup, @@ -53,12 +54,17 @@ public class DrawUserPair public void DrawPairedClient() { using var id = ImRaii.PushId(GetType() + _id); - - DrawLeftSide(); - ImGui.SameLine(); - var posX = ImGui.GetCursorPosX(); - var rightSide = DrawRightSide(); - DrawName(posX, rightSide); + var color = ImRaii.PushColor(ImGuiCol.ChildBg, ImGui.GetColorU32(ImGuiCol.FrameBgHovered), _wasHovered); + using (ImRaii.Child(GetType() + _id, new System.Numerics.Vector2(UiSharedService.GetWindowContentRegionWidth() - ImGui.GetCursorPosX(), ImGui.GetFrameHeight()))) + { + DrawLeftSide(); + ImGui.SameLine(); + var posX = ImGui.GetCursorPosX(); + var rightSide = DrawRightSide(); + DrawName(posX, rightSide); + } + _wasHovered = ImGui.IsItemHovered(); + color.Dispose(); } private void DrawCommonClientMenu() @@ -290,14 +296,14 @@ public class DrawUserPair { var pauseIcon = _pair.UserPair!.OwnPermissions.IsPaused() ? FontAwesomeIcon.Play : FontAwesomeIcon.Pause; var pauseIconSize = _uiSharedService.IconButtonSize(pauseIcon); - var barButtonSize = _uiSharedService.IconButtonSize(FontAwesomeIcon.Bars); + var barButtonSize = _uiSharedService.IconButtonSize(FontAwesomeIcon.EllipsisV); var spacingX = ImGui.GetStyle().ItemSpacing.X; var windowEndX = ImGui.GetWindowContentRegionMin().X + UiSharedService.GetWindowContentRegionWidth(); float currentRightSide = windowEndX - barButtonSize.X; ImGui.SameLine(currentRightSide); ImGui.AlignTextToFramePadding(); - if (UiSharedService.IconButton(FontAwesomeIcon.Bars)) + if (UiSharedService.IconButton(FontAwesomeIcon.EllipsisV)) { ImGui.OpenPopup("User Flyout Menu"); } diff --git a/MareSynchronos/UI/TopTabMenu.cs b/MareSynchronos/UI/TopTabMenu.cs index 1408ae1..d8406e1 100644 --- a/MareSynchronos/UI/TopTabMenu.cs +++ b/MareSynchronos/UI/TopTabMenu.cs @@ -467,7 +467,7 @@ public class TopTabMenu using (ImRaii.Disabled(_pairManager.GroupPairs.Select(k => k.Key).Distinct() .Count(g => string.Equals(g.OwnerUID, _apiController.UID, StringComparison.Ordinal)) >= _apiController.ServerInfo.MaxGroupsCreatedByUser)) { - if (UiSharedService.IconTextButton(FontAwesomeIcon.Plus, "Create new Syncshell")) + if (UiSharedService.IconTextButton(FontAwesomeIcon.Plus, "Create new Syncshell", buttonX)) { _mareMediator.Publish(new UiToggleMessage(typeof(CreateSyncshellUI))); } @@ -476,7 +476,7 @@ public class TopTabMenu using (ImRaii.Disabled(_pairManager.GroupPairs.Select(k => k.Key).Distinct().Count() >= _apiController.ServerInfo.MaxGroupsJoinedByUser)) { - if (UiSharedService.IconTextButton(FontAwesomeIcon.Users, "Join existing Syncshell")) + if (UiSharedService.IconTextButton(FontAwesomeIcon.Users, "Join existing Syncshell", buttonX)) { _mareMediator.Publish(new UiToggleMessage(typeof(JoinSyncshellUI))); } diff --git a/MareSynchronos/UI/UISharedService.cs b/MareSynchronos/UI/UISharedService.cs index adefab9..5d50bc7 100644 --- a/MareSynchronos/UI/UISharedService.cs +++ b/MareSynchronos/UI/UISharedService.cs @@ -337,7 +337,8 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase public static bool IconTextButton(FontAwesomeIcon icon, string text, float? width = null, bool isInPopup = false) { return IconTextButtonInternal(icon, text, - isInPopup ? ColorHelpers.RgbaUintToVector4(ImGui.GetColorU32(ImGuiCol.PopupBg)) : null, width); + isInPopup ? ColorHelpers.RgbaUintToVector4(ImGui.GetColorU32(ImGuiCol.PopupBg)) : null, + width <= 0 ? null : width); } public static bool IsDirectoryWritable(string dirPath, bool throwIfFails = false)