Shell title bar buttons adjustments.

This commit is contained in:
Burak Kaan Köse
2025-10-04 13:40:35 +02:00
parent 20ee4c3567
commit 2f5d4dad9a
3 changed files with 90 additions and 2 deletions
@@ -32,6 +32,9 @@ public interface INewThemeService : IInitializeAsync
// Improved accent color management
Task SetAccentColorAsync(string hexColor, bool preserveTheme = true);
// Title bar color management
void UpdateSystemCaptionButtonColors();
// Backdrop management
List<BackdropTypeWrapper> GetAvailableBackdropTypes();
}
+34 -1
View File
@@ -13,6 +13,7 @@ using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Markup;
using Microsoft.UI.Xaml.Media;
using Windows.Storage;
using Windows.UI;
using Windows.UI.ViewManagement;
using Wino.Core.Domain;
using Wino.Core.Domain.Enums;
@@ -274,7 +275,39 @@ public class NewThemeService : INewThemeService
{
GetShellRootContent().DispatcherQueue.TryEnqueue(() =>
{
Debug.WriteLine("TODO: Updating caption button colors for NewThemeService");
if (WinoApplication.MainWindow is not WindowEx mainWindow) return;
var titleBar = mainWindow.AppWindow.TitleBar;
if (titleBar == null) return;
// Determine if current theme is dark
bool isDarkTheme = _underlyingThemeService.IsUnderlyingThemeDark();
// Set button colors based on theme
// Background is always transparent for all buttons
titleBar.ButtonBackgroundColor = Color.FromArgb(0, 0, 0, 0); // Transparent
titleBar.ButtonInactiveBackgroundColor = Color.FromArgb(0, 0, 0, 0); // Transparent
titleBar.ButtonHoverBackgroundColor = Color.FromArgb(0, 0, 0, 0); // Transparent
titleBar.ButtonPressedBackgroundColor = Color.FromArgb(0, 0, 0, 0); // Transparent
if (isDarkTheme)
{
// Dark theme: use light text/icons for better contrast
titleBar.ButtonForegroundColor = Color.FromArgb(255, 255, 255, 255); // White
titleBar.ButtonInactiveForegroundColor = Color.FromArgb(128, 255, 255, 255); // Semi-transparent white
titleBar.ButtonHoverForegroundColor = Color.FromArgb(255, 255, 255, 255); // White
titleBar.ButtonPressedForegroundColor = Color.FromArgb(200, 255, 255, 255); // Slightly dimmed white
}
else
{
// Light theme: use dark text/icons for better contrast
titleBar.ButtonForegroundColor = Color.FromArgb(255, 0, 0, 0); // Black
titleBar.ButtonInactiveForegroundColor = Color.FromArgb(128, 0, 0, 0); // Semi-transparent black
titleBar.ButtonHoverForegroundColor = Color.FromArgb(255, 0, 0, 0); // Black
titleBar.ButtonPressedForegroundColor = Color.FromArgb(200, 0, 0, 0); // Slightly dimmed black
}
Debug.WriteLine($"Updated title bar button colors for {(isDarkTheme ? "dark" : "light")} theme");
});
}
+53 -1
View File
@@ -3,17 +3,19 @@ using CommunityToolkit.Mvvm.Messaging;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Windows.UI;
using Wino.Core.Domain.Interfaces;
using Wino.Core.WinUI;
using Wino.Core.WinUI.Interfaces;
using Wino.Messaging.Client.Mails;
using Wino.Messaging.Client.Shell;
using Wino.Messaging.UI;
using Wino.Views;
using WinUIEx;
namespace Wino.Mail.WinUI;
public sealed partial class ShellWindow : WindowEx, IWinoShellWindow
public sealed partial class ShellWindow : WindowEx, IWinoShellWindow, IRecipient<ApplicationThemeChanged>
{
public IStatePersistanceService StatePersistanceService { get; } = WinoApplication.Current.Services.GetService<IStatePersistanceService>() ?? throw new Exception("StatePersistanceService not registered in DI container.");
public IPreferencesService PreferencesService { get; } = WinoApplication.Current.Services.GetService<IPreferencesService>() ?? throw new Exception("PreferencesService not registered in DI container.");
@@ -21,6 +23,7 @@ public sealed partial class ShellWindow : WindowEx, IWinoShellWindow
public ShellWindow()
{
WeakReferenceMessenger.Default.Register<TitleBarShellContentUpdated>(this);
WeakReferenceMessenger.Default.Register<ApplicationThemeChanged>(this);
InitializeComponent();
@@ -32,6 +35,17 @@ public sealed partial class ShellWindow : WindowEx, IWinoShellWindow
private void ConfigureTitleBar()
{
AppWindow.TitleBar.ExtendsContentIntoTitleBar = true;
// Apply initial theme colors
var themeService = WinoApplication.Current.Services.GetService<INewThemeService>();
if (themeService != null)
{
var underlyingThemeService = WinoApplication.Current.Services.GetService<IUnderlyingThemeService>();
if (underlyingThemeService != null)
{
UpdateTitleBarColors(underlyingThemeService.IsUnderlyingThemeDark());
}
}
}
public void HandleAppActivation(LaunchActivatedEventArgs args)
@@ -67,4 +81,42 @@ public sealed partial class ShellWindow : WindowEx, IWinoShellWindow
ShellTitleBar.Content = shellPage.TopShellContent;
}
}
public void Receive(ApplicationThemeChanged message)
{
UpdateTitleBarColors(message.IsUnderlyingThemeDark);
}
private void UpdateTitleBarColors(bool isDarkTheme)
{
DispatcherQueue.TryEnqueue(() =>
{
var titleBar = AppWindow.TitleBar;
if (titleBar == null) return;
// Set button colors based on theme
// Background is always transparent for all buttons
titleBar.ButtonBackgroundColor = Color.FromArgb(0, 0, 0, 0); // Transparent
titleBar.ButtonInactiveBackgroundColor = Color.FromArgb(0, 0, 0, 0); // Transparent
titleBar.ButtonHoverBackgroundColor = Color.FromArgb(0, 0, 0, 0); // Transparent
titleBar.ButtonPressedBackgroundColor = Color.FromArgb(0, 0, 0, 0); // Transparent
if (isDarkTheme)
{
// Dark theme: use light text/icons for better contrast
titleBar.ButtonForegroundColor = Color.FromArgb(255, 255, 255, 255); // White
titleBar.ButtonInactiveForegroundColor = Color.FromArgb(128, 255, 255, 255); // Semi-transparent white
titleBar.ButtonHoverForegroundColor = Color.FromArgb(255, 255, 255, 255); // White
titleBar.ButtonPressedForegroundColor = Color.FromArgb(200, 255, 255, 255); // Slightly dimmed white
}
else
{
// Light theme: use dark text/icons for better contrast
titleBar.ButtonForegroundColor = Color.FromArgb(255, 0, 0, 0); // Black
titleBar.ButtonInactiveForegroundColor = Color.FromArgb(128, 0, 0, 0); // Semi-transparent black
titleBar.ButtonHoverForegroundColor = Color.FromArgb(255, 0, 0, 0); // Black
titleBar.ButtonPressedForegroundColor = Color.FromArgb(200, 0, 0, 0); // Slightly dimmed black
}
});
}
}