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:
Claude committed 2026-10-03 17:22:42 +00:00
1 parent 6e01995f7e
commit 3f8464aabc
29 files changed
+711 -144

No files matched your search

+62 -20
View File
@@ -1,8 +1,10 @@
using System.Collections.Specialized;
using System.Windows;
using System.Windows.Automation.Peers;
using System.Windows.Controls;
using System.Windows.Media;
using Titano.Core.Localization;
using Titano.Ui.Controls;
namespace Titano.Ui.Visuals;
@@ -10,7 +12,9 @@ namespace Titano.Ui.Visuals;
/// Base of the retained-mode visuals. Brushes are looked up by theme resource key and re-resolved when the token
/// dictionary is swapped (frozen pens are cached per theme); text is laid out with the UI font at the element's
/// DPI; an optional overlay layer (playhead, hover) is redrawn without re-rendering the static content drawn in
/// <see cref="UIElement.OnRender"/>. Time axes and images never mirror, so the element is always left-to-right.
/// <see cref="UIElement.OnRender"/>. Time axes and images never mirror, so the element is always left-to-right;
/// words (categories, legends, summaries) still read in the UI language's direction (<see cref="CreateLabel"/>) and
/// legends start on its side. Screen readers see a named image (<see cref="DrawingElementAutomationPeer"/>).
/// </summary>
public abstract class DrawingElement : FrameworkElement
{
@@ -91,13 +95,29 @@ public abstract class DrawingElement : FrameworkElement
/// <summary>Pen covering whole device pixels, for gridlines and edges drawn at <see cref="PixelGrid.SnapLine"/> positions.</summary>
protected Pen GetHairline(string key, LineDash dash = LineDash.Solid) => GetPen(key, PixelGrid.SnapThickness(1, PixelScale), dash);
/// <summary>Single-line text in the UI font, laid out for this element's DPI and text formatting mode.</summary>
protected FormattedText CreateText(string text, double emSize, Brush brush, bool semiBold = false)
{
var typeface = semiBold ? _semiBold ??= CreateTypeface(FontWeights.SemiBold) : _regular ??= CreateTypeface(FontWeights.Normal);
return new FormattedText(text, Loc.Culture, FlowDirection.LeftToRight, typeface, emSize, brush, null,
TextOptions.GetTextFormattingMode(this), VisualTreeHelper.GetDpi(this).PixelsPerDip);
}
/// <summary>
/// Text a screen reader hears for the visual when no AutomationProperties.Name is set (its summary, its values);
/// null leaves the image unnamed.
/// </summary>
protected internal virtual string? AutomationDescription => null;
/// <summary>Single-line left-to-right text in the UI font (numbers, ticks, times), laid out for this element's DPI and text formatting mode.</summary>
protected FormattedText CreateText(string text, double emSize, Brush brush, bool semiBold = false) =>
Format(text, emSize, brush, semiBold, FlowDirection.LeftToRight);
/// <summary>
/// Single-line words (category, legend, summary) in the reading order of the UI language, so right-to-left text
/// mixed with numbers or Latin units keeps its order. Place it with <see cref="DrawTextAt"/>.
/// </summary>
protected FormattedText CreateLabel(string text, double emSize, Brush brush, bool semiBold = false) =>
Format(text, emSize, brush, semiBold, Bidi.UiDirection);
/// <summary>Draws <paramref name="text"/> with its top-left corner at <paramref name="topLeft"/>; right-to-left text is laid out leftwards from its origin.</summary>
protected static void DrawTextAt(DrawingContext dc, FormattedText text, Point topLeft) =>
dc.DrawText(text, text.FlowDirection == FlowDirection.RightToLeft ? new Point(topLeft.X + text.Width, topLeft.Y) : topLeft);
/// <summary>Position of a <paramref name="width"/>-wide box laid out from the left within [0, <paramref name="extent"/>], mirrored in a right-to-left UI.</summary>
protected static double FromStart(double x, double width, double extent) => Loc.IsRightToLeft ? extent - x - width : x;
/// <summary>Redraws the overlay layer; call after any change that only affects playhead or hover state.</summary>
protected void RenderOverlay()
@@ -165,25 +185,24 @@ public abstract class DrawingElement : FrameworkElement
}
/// <summary>
/// Draws legend entries left to right from <paramref name="origin"/> (swatch, 6 px, text in the entry colour,
/// 16 px between entries) and stops before <paramref name="maxRight"/>. Returns the right edge reached.
/// Draws legend entries in reading order from the start side of [<paramref name="left"/>, <paramref name="right"/>]
/// (swatch, 6 px, text in the entry colour, 16 px between entries); entries that do not fit are left out.
/// </summary>
protected double DrawLegend(DrawingContext dc, IReadOnlyList<ChartLegendItem> items, Point origin, double maxRight, double emSize)
protected void DrawLegend(DrawingContext dc, IReadOnlyList<ChartLegendItem> items, double left, double right, double top, double emSize)
{
var x = origin.X;
var offset = 0.0;
for (var i = 0; i < items.Count; i++)
{
var item = items[i];
var brush = GetBrush(item.BrushKey);
var text = CreateText(item.Text, emSize, brush);
var text = CreateLabel(item.Text, emSize, GetBrush(item.BrushKey));
var width = 16 + 6 + text.Width;
if (x + width > maxRight) break;
var cy = origin.Y + text.Height / 2;
DrawSwatch(dc, item.Swatch, item.BrushKey, new Rect(x, cy - 5, 16, 10));
dc.DrawText(text, new Point(x + 22, origin.Y));
x += width + 16;
if (left + offset + width > right) break;
var cy = top + text.Height / 2;
var extent = right - left;
DrawSwatch(dc, item.Swatch, item.BrushKey, new Rect(left + FromStart(offset, 16, extent), cy - 5, 16, 10));
DrawTextAt(dc, text, new Point(left + FromStart(offset + 22, text.Width, extent), top));
offset += width + 16;
}
return x;
}
/// <summary>Draws a legend swatch centred in <paramref name="box"/>.</summary>
@@ -235,8 +254,31 @@ public abstract class DrawingElement : FrameworkElement
element.OnThemeChanged();
}
protected override AutomationPeer OnCreateAutomationPeer() => new DrawingElementAutomationPeer(this);
private FormattedText Format(string text, double emSize, Brush brush, bool semiBold, FlowDirection direction)
{
var typeface = semiBold ? _semiBold ??= CreateTypeface(FontWeights.SemiBold) : _regular ??= CreateTypeface(FontWeights.Normal);
return new FormattedText(text, Loc.Culture, direction, typeface, emSize, brush, null,
TextOptions.GetTextFormattingMode(this), VisualTreeHelper.GetDpi(this).PixelsPerDip);
}
private Typeface CreateTypeface(FontWeight weight) =>
new(TryFindResource("Font.Ui") as FontFamily ?? SystemFonts.MessageFontFamily, FontStyles.Normal, weight, FontStretches.Normal);
private void OnWatchedCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) => OnDataChanged();
}
/// <summary>A chart seen by UI Automation: an image named by AutomationProperties.Name or, failing that, by its description.</summary>
public class DrawingElementAutomationPeer(DrawingElement owner) : FrameworkElementAutomationPeer(owner)
{
protected override AutomationControlType GetAutomationControlTypeCore() => AutomationControlType.Image;
protected override string GetClassNameCore() => Owner.GetType().Name;
protected override string GetNameCore()
{
var name = base.GetNameCore();
return string.IsNullOrEmpty(name) ? ((DrawingElement)Owner).AutomationDescription ?? string.Empty : name;
}
}