notif offset placement, default slider yoinked from abel

This commit is contained in:
choco
2025-10-09 22:53:01 +02:00
parent 85ecea6391
commit f5339dc1d2
3 changed files with 49 additions and 20 deletions

View File

@@ -74,7 +74,6 @@ public class LightlessConfig : ILightlessConfiguration
// Lightless Notification Configuration // Lightless Notification Configuration
// TODO: clean these // TODO: clean these
public bool UseLightlessNotifications { get; set; } = true; public bool UseLightlessNotifications { get; set; } = true;
public bool EnableNotificationSounds { get; set; } = true;
public int DefaultNotificationDurationSeconds { get; set; } = 10; public int DefaultNotificationDurationSeconds { get; set; } = 10;
public bool ShowNotificationProgress { get; set; } = true; public bool ShowNotificationProgress { get; set; } = true;
public NotificationLocation LightlessInfoNotification { get; set; } = NotificationLocation.LightlessUi; public NotificationLocation LightlessInfoNotification { get; set; } = NotificationLocation.LightlessUi;
@@ -89,13 +88,11 @@ public class LightlessConfig : ILightlessConfiguration
public bool AutoDismissOnAction { get; set; } = true; public bool AutoDismissOnAction { get; set; } = true;
public bool DismissNotificationOnClick { get; set; } = false; public bool DismissNotificationOnClick { get; set; } = false;
public bool ShowNotificationTimestamp { get; set; } = false; public bool ShowNotificationTimestamp { get; set; } = false;
public bool EnableNotificationHistory { get; set; } = true; public int NotificationOffsetY { get; set; } = 50;
public int NotificationHistorySize { get; set; } = 50;
public uint CustomInfoSoundId { get; set; } = 2; // Se2 public uint CustomInfoSoundId { get; set; } = 2; // Se2
public uint CustomWarningSoundId { get; set; } = 15; // Se15 public uint CustomWarningSoundId { get; set; } = 15; // Se15
public uint CustomErrorSoundId { get; set; } = 16; // Se16 public uint CustomErrorSoundId { get; set; } = 16; // Se16
public bool UseCustomSounds { get; set; } = false;
public uint PairRequestSoundId { get; set; } = 5; // Se5 public uint PairRequestSoundId { get; set; } = 5; // Se5
public bool DisableInfoSound { get; set; } = false; public bool DisableInfoSound { get; set; } = false;
public bool DisableWarningSound { get; set; } = false; public bool DisableWarningSound { get; set; } = false;

View File

@@ -43,15 +43,9 @@ public class LightlessNotificationUI : WindowMediatorSubscriberBase
ImGuiWindowFlags.NoNav | ImGuiWindowFlags.NoNav |
ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.NoBackground |
ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoCollapse |
ImGuiWindowFlags.AlwaysAutoResize; ImGuiWindowFlags.AlwaysAutoResize;
var viewport = ImGui.GetMainViewport(); PositionCondition = ImGuiCond.Always;
if (viewport.WorkSize.X > 0)
{
Position = new Vector2(viewport.WorkPos.X + viewport.WorkSize.X - NotificationWidth - EdgeXMargin,
viewport.WorkPos.Y + EdgeYMargin);
PositionCondition = ImGuiCond.Always;
}
Size = new Vector2(NotificationWidth, 100); Size = new Vector2(NotificationWidth, 100);
SizeCondition = ImGuiCond.FirstUseEver; SizeCondition = ImGuiCond.FirstUseEver;
@@ -114,22 +108,30 @@ public class LightlessNotificationUI : WindowMediatorSubscriberBase
protected override void DrawInternal() protected override void DrawInternal()
{ {
ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, Vector2.Zero);
lock (_notificationLock) lock (_notificationLock)
{ {
UpdateNotifications(); UpdateNotifications();
if (_notifications.Count == 0) if (_notifications.Count == 0)
{ {
ImGui.PopStyleVar();
IsOpen = false; IsOpen = false;
return; return;
} }
var viewport = ImGui.GetMainViewport(); var viewport = ImGui.GetMainViewport();
var windowPos = new Vector2(
viewport.WorkPos.X + viewport.WorkSize.X - NotificationWidth - EdgeXMargin, // Always position at top (choco doesnt know how to handle top positions how fitting)
viewport.WorkPos.Y + EdgeYMargin var baseX = viewport.WorkPos.X + viewport.WorkSize.X - NotificationWidth;
); var baseY = viewport.WorkPos.Y;
ImGui.SetWindowPos(windowPos);
// Apply Y offset
var finalY = baseY + _configService.Current.NotificationOffsetY;
// Update position
Position = new Vector2(baseX, finalY);
for (int i = 0; i < _notifications.Count; i++) for (int i = 0; i < _notifications.Count; i++)
{ {
@@ -141,6 +143,8 @@ public class LightlessNotificationUI : WindowMediatorSubscriberBase
} }
} }
} }
ImGui.PopStyleVar();
} }
private void UpdateNotifications() private void UpdateNotifications()
@@ -208,6 +212,8 @@ public class LightlessNotificationUI : WindowMediatorSubscriberBase
var notificationHeight = CalculateNotificationHeight(notification); var notificationHeight = CalculateNotificationHeight(notification);
ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, Vector2.Zero);
using var child = ImRaii.Child($"notification_{notification.Id}", using var child = ImRaii.Child($"notification_{notification.Id}",
new Vector2(NotificationWidth - slideOffset, notificationHeight), new Vector2(NotificationWidth - slideOffset, notificationHeight),
false, ImGuiWindowFlags.NoScrollbar); false, ImGuiWindowFlags.NoScrollbar);
@@ -216,6 +222,8 @@ public class LightlessNotificationUI : WindowMediatorSubscriberBase
{ {
DrawNotificationContent(notification, alpha); DrawNotificationContent(notification, alpha);
} }
ImGui.PopStyleVar();
} }
private void DrawNotificationContent(LightlessNotification notification, float alpha) private void DrawNotificationContent(LightlessNotification notification, float alpha)
@@ -266,6 +274,7 @@ public class LightlessNotificationUI : WindowMediatorSubscriberBase
3f 3f
); );
// Draw accent bar on left side of the notif
var accentWidth = 3f; var accentWidth = 3f;
drawList.AddRectFilled( drawList.AddRectFilled(
windowPos, windowPos,
@@ -312,9 +321,10 @@ public class LightlessNotificationUI : WindowMediatorSubscriberBase
private void DrawNotificationText(LightlessNotification notification, float alpha) private void DrawNotificationText(LightlessNotification notification, float alpha)
{ {
var padding = new Vector2(10f, 6f); var padding = new Vector2(10f, 6f);
var contentPos = new Vector2(6f, 0f) + padding;
var contentPos = new Vector2(padding.X, padding.Y);
var windowSize = ImGui.GetWindowSize(); var windowSize = ImGui.GetWindowSize();
var contentSize = windowSize - padding * 2 - new Vector2(6f, 0f); var contentSize = new Vector2(windowSize.X - padding.X, windowSize.Y - padding.Y * 2);
ImGui.SetCursorPos(contentPos); ImGui.SetCursorPos(contentPos);
@@ -358,7 +368,8 @@ public class LightlessNotificationUI : WindowMediatorSubscriberBase
progressColor.W *= alpha; progressColor.W *= alpha;
using (ImRaii.PushColor(ImGuiCol.PlotHistogram, progressColor)) using (ImRaii.PushColor(ImGuiCol.PlotHistogram, progressColor))
{ {
ImGui.ProgressBar(notification.Progress, new Vector2(contentSize.X, 2f), ""); // Use full window width for progress bar
ImGui.ProgressBar(notification.Progress, new Vector2(windowSize.X - padding.X * 2 - 6f, 2f), "");
} }
} }

View File

@@ -3232,6 +3232,27 @@ public class SettingsUi : WindowMediatorSubscriberBase
_uiShared.DrawHelpText("Maximum number of notifications that can be shown at once."); _uiShared.DrawHelpText("Maximum number of notifications that can be shown at once.");
ImGui.Spacing();
ImGui.TextUnformatted("Position");
int offsetY = _configService.Current.NotificationOffsetY;
if (ImGui.SliderInt("Vertical Offset", ref offsetY, 0, 500))
{
_configService.Current.NotificationOffsetY = offsetY;
_configService.Save();
}
if (ImGui.IsItemClicked(ImGuiMouseButton.Right))
{
_configService.Current.NotificationOffsetY = 50;
_configService.Save();
}
if (ImGui.IsItemHovered())
ImGui.SetTooltip("Right click to reset to default (50).");
_uiShared.DrawHelpText("Move notifications down from the top-right corner. 0 aligns to the very top.");
_uiShared.ColoredSeparator(UIColors.Get("LightlessPurple"), 1.5f); _uiShared.ColoredSeparator(UIColors.Get("LightlessPurple"), 1.5f);
ImGui.TreePop(); ImGui.TreePop();
} }