fix(ui): toasts render; RTL-aware icons, charts and media; keyboard and screen-reader support in the kit
- ToastHost gets its template (nothing drew before); toasts are announced, pause while hovered or focused, Esc dismisses the focused one, the action closes it, FocusNewest brings the keyboard to them. - Windows take the UI language's direction when created and follow every switch. - Icons mirror only when the glyph is directional (IconData.IsDirectional, Bidi.IsDirectional override); the brand mark never mirrors; icons centre in stretched slots (ComboBox chevron). - Card photos, scrub position, preview surface and shot data, mono templates, paths are left-to-right islands; the preview tool row follows the layout direction. - Chart words (categories, legends, summaries) read in the UI direction and legends start on its side. - Automation peers: charts as named images, filmstrip as a slider, curve editor value, preview image, split button, AutoSlider group; localized names for caption, reset, remove, dismiss and drop-down buttons. - Focus visible on list and table rows and the preview; curve editor fully operable by keyboard. - Rail item collapsed layout fixed; job bar trims its text only once the bar is at its minimum. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
29 files changed
+711
-144
No files matched your search
@@ -1,6 +1,9 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Automation;
|
||||
using System.Windows.Automation.Peers;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Threading;
|
||||
using Titano.Ui.Mvvm;
|
||||
@@ -18,10 +21,16 @@ public sealed class Toast : ObservableObject
|
||||
public TimeSpan Lifetime { get; init; } = TimeSpan.FromSeconds(8);
|
||||
}
|
||||
|
||||
/// <summary>Bottom-right stack of <see cref="Toast"/>s with auto-dismiss.</summary>
|
||||
/// <summary>
|
||||
/// Bottom-right stack of <see cref="Toast"/>s with auto-dismiss. Screen readers hear each toast as it appears; the
|
||||
/// timers pause while the pointer or the keyboard focus is on a toast; <see cref="FocusNewest"/> brings the keyboard
|
||||
/// to the newest one, Esc dismisses the focused one and focus then returns where it came from; running a toast's
|
||||
/// action closes it.
|
||||
/// </summary>
|
||||
public class ToastHost : ItemsControl
|
||||
{
|
||||
private readonly Dictionary<Toast, DispatcherTimer> _timers = [];
|
||||
private IInputElement? _returnFocus;
|
||||
|
||||
static ToastHost()
|
||||
{
|
||||
@@ -35,12 +44,15 @@ public class ToastHost : ItemsControl
|
||||
{
|
||||
if (e.Parameter is Toast t) Dismiss(t);
|
||||
}));
|
||||
AddHandler(ButtonBase.ClickEvent, new RoutedEventHandler(OnButtonClick));
|
||||
}
|
||||
|
||||
public static RoutedCommand DismissCommand { get; } = new(nameof(DismissCommand), typeof(ToastHost));
|
||||
|
||||
public ObservableCollection<Toast> Toasts { get; } = [];
|
||||
|
||||
private bool IsHeld => IsMouseOver || IsKeyboardFocusWithin;
|
||||
|
||||
public void Show(Toast toast)
|
||||
{
|
||||
Toasts.Add(toast);
|
||||
@@ -48,32 +60,81 @@ public class ToastHost : ItemsControl
|
||||
var timer = new DispatcherTimer { Interval = toast.Lifetime };
|
||||
timer.Tick += (_, _) => Dismiss(toast);
|
||||
_timers[toast] = timer;
|
||||
timer.Start();
|
||||
}
|
||||
|
||||
/// <summary>Pauses or resumes the dismissal timer (hover pauses).</summary>
|
||||
public void SetPaused(Toast toast, bool paused)
|
||||
{
|
||||
if (!_timers.TryGetValue(toast, out var timer)) return;
|
||||
if (paused) timer.Stop();
|
||||
else timer.Start();
|
||||
timer.IsEnabled = !IsHeld;
|
||||
Announce(toast);
|
||||
}
|
||||
|
||||
public void Dismiss(Toast toast)
|
||||
{
|
||||
if (_timers.Remove(toast, out var timer)) timer.Stop();
|
||||
var hadFocus = IsKeyboardFocusWithin;
|
||||
Toasts.Remove(toast);
|
||||
if (hadFocus && !IsKeyboardFocusWithin && _returnFocus is UIElement { IsVisible: true } previous) previous.Focus();
|
||||
}
|
||||
|
||||
protected override void OnPreviewMouseMove(MouseEventArgs e)
|
||||
/// <summary>Moves the keyboard to the newest toast's first control; false when no toast is shown.</summary>
|
||||
public bool FocusNewest()
|
||||
{
|
||||
base.OnPreviewMouseMove(e);
|
||||
foreach (var t in Toasts.ToList()) SetPaused(t, true);
|
||||
if (Toasts.Count == 0) return false;
|
||||
UpdateLayout();
|
||||
return ItemContainerGenerator.ContainerFromIndex(Toasts.Count - 1) is UIElement container
|
||||
&& container.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));
|
||||
}
|
||||
|
||||
protected override void OnPreviewGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
|
||||
{
|
||||
base.OnPreviewGotKeyboardFocus(e);
|
||||
if (e.OldFocus is not DependencyObject old || !IsAncestorOf(old)) _returnFocus = e.OldFocus;
|
||||
}
|
||||
|
||||
protected override void OnIsKeyboardFocusWithinChanged(DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
base.OnIsKeyboardFocusWithinChanged(e);
|
||||
UpdateTimers();
|
||||
}
|
||||
|
||||
protected override void OnMouseEnter(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseEnter(e);
|
||||
UpdateTimers();
|
||||
}
|
||||
|
||||
protected override void OnMouseLeave(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseLeave(e);
|
||||
foreach (var t in Toasts.ToList()) SetPaused(t, false);
|
||||
UpdateTimers();
|
||||
}
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
base.OnKeyDown(e);
|
||||
if (e.Handled || e.Key != Key.Escape || (e.OriginalSource as FrameworkElement)?.DataContext is not Toast toast) return;
|
||||
Dismiss(toast);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
/// <summary>Hovering or focusing any toast holds them all; leaving restarts their full lifetime.</summary>
|
||||
private void UpdateTimers()
|
||||
{
|
||||
var held = IsHeld;
|
||||
foreach (var timer in _timers.Values)
|
||||
{
|
||||
timer.Stop();
|
||||
if (!held) timer.Start();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The action executes right after its Click event; the toast closes once it has run.</summary>
|
||||
private void OnButtonClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (e.OriginalSource is ButtonBase { DataContext: Toast toast, Command: { } command } && ReferenceEquals(command, toast.ActionCommand))
|
||||
Dispatcher.BeginInvoke(() => Dismiss(toast));
|
||||
}
|
||||
|
||||
private void Announce(Toast toast)
|
||||
{
|
||||
var text = string.IsNullOrEmpty(toast.Message) ? toast.Title : toast.Title + " " + toast.Message;
|
||||
UIElementAutomationPeer.CreatePeerForElement(this)?.RaiseNotificationEvent(
|
||||
AutomationNotificationKind.Other, AutomationNotificationProcessing.ImportantMostRecent, text, "Titano.Toast");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user