2
0
mirror of https://github.com/9ParsonsB/Pulsar.git synced 2025-04-05 17:39:39 -04:00

allow multiple simultaneous popup notifications to vertically stack

This commit is contained in:
Xjph 2021-10-23 15:47:38 -02:30
parent 08a8aa3156
commit 310287b0af
3 changed files with 40 additions and 4 deletions

View File

@ -22,6 +22,12 @@ namespace Observatory.NativeNotification
{
var notifyWindow = new NotificationView(notificationGuid) { DataContext = new NotificationViewModel(notificationArgs) };
notifyWindow.Closed += NotifyWindow_Closed;
foreach (var notification in notifications)
{
notification.Value.AdjustOffset(true);
}
notifications.Add(notificationGuid, notifyWindow);
notifyWindow.Show();
});
@ -31,10 +37,12 @@ namespace Observatory.NativeNotification
private void NotifyWindow_Closed(object sender, EventArgs e)
{
var notification = (NotificationView)sender;
var currentNotification = (NotificationView)sender;
if (notifications.ContainsKey(notification.Guid))
notifications.Remove(notification.Guid);
if (notifications.ContainsKey(currentNotification.Guid))
{
notifications.Remove(currentNotification.Guid);
}
}
public void CloseNotification(Guid guid)

View File

@ -21,10 +21,12 @@ namespace Observatory.UI.Views
public class BasicUIView : UserControl
{
private DataGrid dataGrid;
private NativeNotification.NativePopup nativePopup;
public BasicUIView()
{
InitializeComponent();
nativePopup = new();
}
private void InitializeComponent()
@ -274,7 +276,7 @@ namespace Observatory.UI.Views
Detail = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras suscipit hendrerit libero ac scelerisque."
};
new NativeNotification.NativePopup().InvokeNativeNotification(notificationArgs);
nativePopup.InvokeNativeNotification(notificationArgs);
});
};

View File

@ -14,6 +14,8 @@ namespace Observatory.UI.Views
private readonly double scale;
private readonly Timer timer;
private readonly Guid guid;
private bool defaultPosition = true;
private PixelPoint originalPosition;
public NotificationView() : this(default)
{ }
@ -48,6 +50,27 @@ namespace Observatory.UI.Views
public Guid Guid { get => guid; }
public void AdjustOffset(bool increase)
{
if (defaultPosition)
{
if (increase || Position != originalPosition)
{
var corner = Properties.Core.Default.NativeNotifyCorner;
if ((corner >= 2 && increase) || (corner <= 1 && !increase))
{
Position += new PixelPoint(0, Convert.ToInt32(Height));
}
else
{
Position -= new PixelPoint(0, Convert.ToInt32(Height));
}
}
}
}
private void NotificationView_DataContextChanged(object sender, EventArgs e)
{
var notification = ((NotificationViewModel)DataContext).Notification;
@ -117,10 +140,12 @@ namespace Observatory.UI.Views
if (xOverride >= 0 && yOverride >= 0)
{
defaultPosition = false;
Position = screenBounds.TopLeft + new PixelPoint(Convert.ToInt32(screenBounds.Width * xOverride), Convert.ToInt32(screenBounds.Height * yOverride));
}
else
{
defaultPosition = true;
switch (corner)
{
default:
@ -137,6 +162,7 @@ namespace Observatory.UI.Views
Position = screenBounds.TopLeft + new PixelPoint(50, 50);
break;
}
originalPosition = Position;
}
}