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

View File

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