add mouseover in main ui

This commit is contained in:
rootdarkarchon
2024-03-18 12:39:02 +01:00
parent 7baca3565a
commit d136a70711
5 changed files with 76 additions and 50 deletions

View File

@@ -17,6 +17,7 @@ public abstract class DrawFolderBase : IDrawFolder
private float _menuWidth = -1; private float _menuWidth = -1;
public int OnlinePairs => DrawPairs.Count(u => u.Pair.IsOnline); public int OnlinePairs => DrawPairs.Count(u => u.Pair.IsOnline);
public int TotalPairs => _allPairs.Count; public int TotalPairs => _allPairs.Count;
private bool _wasHovered = false;
protected DrawFolderBase(string id, IImmutableList<DrawUserPair> drawPairs, protected DrawFolderBase(string id, IImmutableList<DrawUserPair> drawPairs,
IImmutableList<Pair> allPairs, TagHandler tagHandler, UiSharedService uiSharedService) IImmutableList<Pair> allPairs, TagHandler tagHandler, UiSharedService uiSharedService)
@@ -36,7 +37,9 @@ public abstract class DrawFolderBase : IDrawFolder
if (!RenderIfEmpty && !DrawPairs.Any()) return; if (!RenderIfEmpty && !DrawPairs.Any()) return;
using var id = ImRaii.PushId("folder_" + _id); using var id = ImRaii.PushId("folder_" + _id);
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())))
{
// draw opener // draw opener
var icon = _tagHandler.IsTagOpen(_id) ? FontAwesomeIcon.CaretDown : FontAwesomeIcon.CaretRight; var icon = _tagHandler.IsTagOpen(_id) ? FontAwesomeIcon.CaretDown : FontAwesomeIcon.CaretRight;
@@ -57,12 +60,18 @@ public abstract class DrawFolderBase : IDrawFolder
// draw name // draw name
ImGui.SameLine(leftSideEnd); ImGui.SameLine(leftSideEnd);
DrawName(rightSideStart - leftSideEnd); DrawName(rightSideStart - leftSideEnd);
}
_wasHovered = ImGui.IsItemHovered();
color.Dispose();
ImGui.Separator(); ImGui.Separator();
// if opened draw content // if opened draw content
if (_tagHandler.IsTagOpen(_id)) 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()) if (DrawPairs.Any())
{ {
foreach (var item in DrawPairs) foreach (var item in DrawPairs)
@@ -89,7 +98,7 @@ public abstract class DrawFolderBase : IDrawFolder
private float DrawRightSideInternal() private float DrawRightSideInternal()
{ {
var barButtonSize = _uiSharedService.IconButtonSize(FontAwesomeIcon.Bars); var barButtonSize = _uiSharedService.IconButtonSize(FontAwesomeIcon.EllipsisV);
var spacingX = ImGui.GetStyle().ItemSpacing.X; var spacingX = ImGui.GetStyle().ItemSpacing.X;
var windowEndX = ImGui.GetWindowContentRegionMin().X + UiSharedService.GetWindowContentRegionWidth(); var windowEndX = ImGui.GetWindowContentRegionMin().X + UiSharedService.GetWindowContentRegionWidth();
@@ -99,7 +108,7 @@ public abstract class DrawFolderBase : IDrawFolder
if (RenderMenu) if (RenderMenu)
{ {
ImGui.SameLine(windowEndX - barButtonSize.X); ImGui.SameLine(windowEndX - barButtonSize.X);
if (UiSharedService.IconButton(FontAwesomeIcon.Bars)) if (UiSharedService.IconButton(FontAwesomeIcon.EllipsisV))
{ {
ImGui.OpenPopup("User Flyout Menu"); ImGui.OpenPopup("User Flyout Menu");
} }

View File

@@ -12,6 +12,7 @@ public class DrawGroupedGroupFolder : IDrawFolder
private readonly IEnumerable<IDrawFolder> _groups; private readonly IEnumerable<IDrawFolder> _groups;
private readonly TagHandler _tagHandler; private readonly TagHandler _tagHandler;
private readonly UiSharedService _uiSharedService; private readonly UiSharedService _uiSharedService;
private bool _wasHovered = false;
public IImmutableList<DrawUserPair> DrawPairs => throw new NotSupportedException(); public IImmutableList<DrawUserPair> DrawPairs => throw new NotSupportedException();
public int OnlinePairs => _groups.SelectMany(g => g.DrawPairs).Where(g => g.Pair.IsOnline).DistinctBy(g => g.Pair.UserData.UID).Count(); public int OnlinePairs => _groups.SelectMany(g => g.DrawPairs).Where(g => g.Pair.IsOnline).DistinctBy(g => g.Pair.UserData.UID).Count();
@@ -30,12 +31,16 @@ public class DrawGroupedGroupFolder : IDrawFolder
string _id = "__folder_syncshells"; string _id = "__folder_syncshells";
using var id = ImRaii.PushId(_id); using var id = ImRaii.PushId(_id);
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())))
{
ImGui.Dummy(new Vector2(0f, ImGui.GetFrameHeight())); ImGui.Dummy(new Vector2(0f, ImGui.GetFrameHeight()));
using (ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, new Vector2(0f, 0f))) using (ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, new Vector2(0f, 0f)))
ImGui.SameLine(); ImGui.SameLine();
var icon = _tagHandler.IsTagOpen(_id) ? FontAwesomeIcon.CaretDown : FontAwesomeIcon.CaretRight; var icon = _tagHandler.IsTagOpen(_id) ? FontAwesomeIcon.CaretDown : FontAwesomeIcon.CaretRight;
ImGui.AlignTextToFramePadding();
_uiSharedService.IconText(icon); _uiSharedService.IconText(icon);
if (ImGui.IsItemClicked()) if (ImGui.IsItemClicked())
{ {
@@ -43,6 +48,7 @@ public class DrawGroupedGroupFolder : IDrawFolder
} }
ImGui.SameLine(); ImGui.SameLine();
ImGui.AlignTextToFramePadding();
_uiSharedService.IconText(FontAwesomeIcon.UsersRectangle); _uiSharedService.IconText(FontAwesomeIcon.UsersRectangle);
using (ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, ImGui.GetStyle().ItemSpacing with { X = ImGui.GetStyle().ItemSpacing.X / 2f })) using (ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, ImGui.GetStyle().ItemSpacing with { X = ImGui.GetStyle().ItemSpacing.X / 2f }))
{ {
@@ -55,6 +61,10 @@ public class DrawGroupedGroupFolder : IDrawFolder
ImGui.SameLine(); ImGui.SameLine();
ImGui.AlignTextToFramePadding(); ImGui.AlignTextToFramePadding();
ImGui.TextUnformatted("All Syncshells"); ImGui.TextUnformatted("All Syncshells");
}
color.Dispose();
_wasHovered = ImGui.IsItemHovered();
ImGui.Separator(); ImGui.Separator();
if (_tagHandler.IsTagOpen(_id)) if (_tagHandler.IsTagOpen(_id))

View File

@@ -27,6 +27,7 @@ public class DrawUserPair
private readonly ServerConfigurationManager _serverConfigurationManager; private readonly ServerConfigurationManager _serverConfigurationManager;
private readonly UiSharedService _uiSharedService; private readonly UiSharedService _uiSharedService;
private float _menuWidth = -1; private float _menuWidth = -1;
private bool _wasHovered = false;
public DrawUserPair(string id, Pair entry, List<GroupFullInfoDto> syncedGroups, public DrawUserPair(string id, Pair entry, List<GroupFullInfoDto> syncedGroups,
GroupFullInfoDto? currentGroup, GroupFullInfoDto? currentGroup,
@@ -53,13 +54,18 @@ public class DrawUserPair
public void DrawPairedClient() public void DrawPairedClient()
{ {
using var id = ImRaii.PushId(GetType() + _id); using var id = ImRaii.PushId(GetType() + _id);
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(); DrawLeftSide();
ImGui.SameLine(); ImGui.SameLine();
var posX = ImGui.GetCursorPosX(); var posX = ImGui.GetCursorPosX();
var rightSide = DrawRightSide(); var rightSide = DrawRightSide();
DrawName(posX, rightSide); DrawName(posX, rightSide);
} }
_wasHovered = ImGui.IsItemHovered();
color.Dispose();
}
private void DrawCommonClientMenu() private void DrawCommonClientMenu()
{ {
@@ -290,14 +296,14 @@ public class DrawUserPair
{ {
var pauseIcon = _pair.UserPair!.OwnPermissions.IsPaused() ? FontAwesomeIcon.Play : FontAwesomeIcon.Pause; var pauseIcon = _pair.UserPair!.OwnPermissions.IsPaused() ? FontAwesomeIcon.Play : FontAwesomeIcon.Pause;
var pauseIconSize = _uiSharedService.IconButtonSize(pauseIcon); var pauseIconSize = _uiSharedService.IconButtonSize(pauseIcon);
var barButtonSize = _uiSharedService.IconButtonSize(FontAwesomeIcon.Bars); var barButtonSize = _uiSharedService.IconButtonSize(FontAwesomeIcon.EllipsisV);
var spacingX = ImGui.GetStyle().ItemSpacing.X; var spacingX = ImGui.GetStyle().ItemSpacing.X;
var windowEndX = ImGui.GetWindowContentRegionMin().X + UiSharedService.GetWindowContentRegionWidth(); var windowEndX = ImGui.GetWindowContentRegionMin().X + UiSharedService.GetWindowContentRegionWidth();
float currentRightSide = windowEndX - barButtonSize.X; float currentRightSide = windowEndX - barButtonSize.X;
ImGui.SameLine(currentRightSide); ImGui.SameLine(currentRightSide);
ImGui.AlignTextToFramePadding(); ImGui.AlignTextToFramePadding();
if (UiSharedService.IconButton(FontAwesomeIcon.Bars)) if (UiSharedService.IconButton(FontAwesomeIcon.EllipsisV))
{ {
ImGui.OpenPopup("User Flyout Menu"); ImGui.OpenPopup("User Flyout Menu");
} }

View File

@@ -467,7 +467,7 @@ public class TopTabMenu
using (ImRaii.Disabled(_pairManager.GroupPairs.Select(k => k.Key).Distinct() using (ImRaii.Disabled(_pairManager.GroupPairs.Select(k => k.Key).Distinct()
.Count(g => string.Equals(g.OwnerUID, _apiController.UID, StringComparison.Ordinal)) >= _apiController.ServerInfo.MaxGroupsCreatedByUser)) .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))); _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)) 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))); _mareMediator.Publish(new UiToggleMessage(typeof(JoinSyncshellUI)));
} }

View File

@@ -337,7 +337,8 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
public static bool IconTextButton(FontAwesomeIcon icon, string text, float? width = null, bool isInPopup = false) public static bool IconTextButton(FontAwesomeIcon icon, string text, float? width = null, bool isInPopup = false)
{ {
return IconTextButtonInternal(icon, text, 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) public static bool IsDirectoryWritable(string dirPath, bool throwIfFails = false)