merge: integration branch claude/keen-knuth-uhxv8w (Archive manager and UI kit review) into the Library workstream

The Archive manager's reviewed dialogs (live status lines, one-sentence
errors, growing label columns, left-to-right paths) move into the shared
ArchiveDialogs.xaml with their styles, so the Library's Delete and the
Trash dialog use them too. Delete, Restore and Rate failures read as one
sentence through ArchiveFailures, which now knows a stale delete plan, a
newer sidecar and a sequence already back in the library
(SequenceInLibraryException). The confirmation's plan lines in the UI font
follow the reading direction; fingerprints stay left to right.

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-06 20:36:02 +00:00
commit 9f7907d903
77 files changed
+1966 -468

No files matched your search

+11 -8
View File
@@ -85,6 +85,9 @@ public sealed class BarChart : DrawingElement
remove => RemoveHandler(ItemActivatedEvent, value);
}
protected internal override string? AutomationDescription =>
Items is { Count: > 0 } items ? string.Join(Environment.NewLine, items.Select(ReadoutText)) : null;
protected override Size MeasureOverride(Size availableSize)
{
var count = Items?.Count ?? 0;
@@ -166,10 +169,10 @@ public sealed class BarChart : DrawingElement
double labelWidth = 0, valueWidth = 0;
for (var i = 0; i < items.Count; i++)
{
labels[i] = CreateText(items[i].Label, LabelSize, faint);
labels[i] = CreateLabel(items[i].Label, LabelSize, faint);
labelWidth = Math.Max(labelWidth, labels[i].Width);
if (!ShowValues) continue;
values[i] = CreateText(items[i].ValueText ?? Format(items[i].Value), LabelSize, text);
values[i] = CreateLabel(items[i].ValueText ?? Format(items[i].Value), LabelSize, text);
valueWidth = Math.Max(valueWidth, values[i]!.Width);
}
var gridHeight = ShowGrid ? 16 : 0;
@@ -184,7 +187,7 @@ public sealed class BarChart : DrawingElement
{
var item = items[i];
var cy = _area.Top + _pitch * (i + 0.5);
dc.DrawText(labels[i], new Point(left - 8 - labels[i].Width, cy - labels[i].Height / 2));
DrawTextAt(dc, labels[i], new Point(left - 8 - labels[i].Width, cy - labels[i].Height / 2));
var length = _area.Width * Math.Clamp(item.Value / max, 0, 1);
if (length > 0)
{
@@ -192,7 +195,7 @@ public sealed class BarChart : DrawingElement
dc.DrawRoundedRectangle(GetBrush(item.BrushKey ?? BrushKey), null, new Rect(left, cy - thickness / 2, length, thickness), 2, 2);
dc.Pop();
}
if (values[i] is { } value) dc.DrawText(value, new Point(left + length + 6, cy - value.Height / 2));
if (values[i] is { } value) DrawTextAt(dc, value, new Point(left + length + 6, cy - value.Height / 2));
}
}
@@ -228,13 +231,13 @@ public sealed class BarChart : DrawingElement
}
if (ShowValues && _pitch >= 24)
{
var value = CreateText(item.ValueText ?? Format(item.Value), LabelSize, text);
if (value.Width <= _pitch) dc.DrawText(value, new Point(cx - value.Width / 2, _area.Bottom - height - value.Height - 2));
var value = CreateLabel(item.ValueText ?? Format(item.Value), LabelSize, text);
if (value.Width <= _pitch) DrawTextAt(dc, value, new Point(cx - value.Width / 2, _area.Bottom - height - value.Height - 2));
}
var label = CreateText(item.Label, LabelSize, faint);
var label = CreateLabel(item.Label, LabelSize, faint);
var x = cx - label.Width / 2;
if (x < lastLabelRight + 6) continue;
dc.DrawText(label, new Point(x, _area.Bottom + 4));
DrawTextAt(dc, label, new Point(x, _area.Bottom + 4));
lastLabelRight = x + label.Width;
}
}
+100 -8
View File
@@ -1,5 +1,8 @@
using System.Collections.Specialized;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Automation.Peers;
using System.Windows.Automation.Provider;
using System.Windows.Input;
using System.Windows.Media;
using Titano.Core.Localization;
@@ -23,6 +26,8 @@ public enum CurveEditMode
/// sampling <see cref="Evaluator"/> once per device-pixel column, so the engine's Fritsch–Carlson spline is what
/// the user sees. Grid, optional identity diagonal and a playhead are drawn; hovering or dragging a point reads
/// out its coordinates. <see cref="EditCompletedEvent"/> fires after each add, delete, nudge or finished drag.
/// Keyboard alone: focus selects the first point, PageUp/PageDown step through the points, Insert or Enter adds one
/// at the playhead, and the readout follows the selected point; screen readers hear the selected point as the value.
/// </summary>
public sealed class CurveEditor : DrawingElement
{
@@ -37,7 +42,8 @@ public sealed class CurveEditor : DrawingElement
public static readonly DependencyProperty SelectedIndexProperty = DependencyProperty.Register(
nameof(SelectedIndex), typeof(int), typeof(CurveEditor),
new FrameworkPropertyMetadata(-1, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.AffectsRender, null, CoerceSelectedIndex));
new FrameworkPropertyMetadata(-1, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.AffectsRender,
(d, _) => ((CurveEditor)d).AnnounceSelection(), CoerceSelectedIndex));
public static readonly DependencyProperty PlayheadPositionProperty = DependencyProperty.Register(
nameof(PlayheadPosition), typeof(double), typeof(CurveEditor), new PropertyMetadata(double.NaN, (d, _) => ((CurveEditor)d).RenderOverlay()));
@@ -70,6 +76,7 @@ public sealed class CurveEditor : DrawingElement
private int _hover = -1;
private bool _dragging;
private bool _moved;
private string _announced = string.Empty;
static CurveEditor()
{
@@ -138,8 +145,15 @@ public sealed class CurveEditor : DrawingElement
_hover = -1;
CoerceValue(SelectedIndexProperty);
base.OnDataChanged();
AnnounceSelection();
}
protected internal override string? AutomationDescription => SelectionText;
/// <summary>"Point 2 of 4: x → y" for the selected point; empty without a selection.</summary>
internal string SelectionText =>
SelectedIndex >= 0 && SelectedIndex < _count ? Loc.L("Common.CurvePoint", SelectedIndex + 1, _count, ReadoutText(SelectedIndex)) : string.Empty;
protected override void OnRender(DrawingContext dc)
{
DrawHitArea(dc);
@@ -211,7 +225,7 @@ public sealed class CurveEditor : DrawingElement
if (_dragging && SelectedIndex >= 0)
{
_moved |= Move(SelectedIndex, ToX(p.X), ToY(p.Y));
Readout.Show(ReadoutText(SelectedIndex), p);
Readout.Show(ReadoutText(SelectedIndex), p, FlowDirection.LeftToRight);
return;
}
var hover = HitTest(p);
@@ -220,7 +234,7 @@ public sealed class CurveEditor : DrawingElement
_hover = hover;
InvalidateVisual();
}
Readout.Show(hover >= 0 ? ReadoutText(hover) : null, p);
Readout.Show(hover >= 0 ? ReadoutText(hover) : null, p, FlowDirection.LeftToRight);
}
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
@@ -256,11 +270,42 @@ public sealed class CurveEditor : DrawingElement
e.Handled = true;
}
protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
{
base.OnGotKeyboardFocus(e);
// Tabbing in selects a point so the arrows have something to move; a click selects what it hits instead.
if (SelectedIndex < 0 && _count > 0 && InputManager.Current.MostRecentInputDevice is KeyboardDevice)
SetCurrentValue(SelectedIndexProperty, 0);
ShowSelectionReadout();
}
protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
{
base.OnLostKeyboardFocus(e);
if (!_dragging) Readout.Hide();
}
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
if (e.Handled) return;
if (e.Key is (Key.PageUp or Key.PageDown) && _count > 0)
{
var next = SelectedIndex < 0 ? 0 : SelectedIndex + (e.Key == Key.PageDown ? 1 : -1);
SetCurrentValue(SelectedIndexProperty, Math.Clamp(next, 0, _count - 1));
ShowSelectionReadout();
e.Handled = true;
return;
}
if (e.Key is (Key.Insert or Key.Enter) && IsEditable)
{
AddFromKeyboard();
ShowSelectionReadout();
e.Handled = true;
return;
}
var index = SelectedIndex;
if (e.Handled || index < 0 || index >= _count || !IsEditable) return;
if (index < 0 || index >= _count || !IsEditable) return;
var step = (Keyboard.Modifiers & ModifierKeys.Shift) != 0 ? 0.1 : 0.01;
var changed = e.Key switch
{
@@ -273,9 +318,12 @@ public sealed class CurveEditor : DrawingElement
};
if (changed is null) return;
e.Handled = true;
ShowSelectionReadout();
if (changed.Value) RaiseEvent(new RoutedEventArgs(EditCompletedEvent));
}
protected override AutomationPeer OnCreateAutomationPeer() => new CurveEditorAutomationPeer(this);
private static object CoerceSelectedIndex(DependencyObject d, object value)
{
var index = (int)value;
@@ -341,18 +389,45 @@ public sealed class CurveEditor : DrawingElement
return true;
}
private void Add(Point at)
private void Add(Point at) => AddAt(ToX(at.X), ToY(at.Y));
/// <summary>A new point on the curve as it is drawn now, at the playhead or in the gap after the selection.</summary>
private void AddFromKeyboard()
{
var xs = _xs.AsSpan(0, _count);
var x = CurveMath.KeyboardInsertionX(xs, SelectedIndex, PlayheadPosition, MinimumGap, PinEnds);
AddAt(x, Evaluator?.Invoke(x) ?? CurveMath.Interpolate(xs, _ys.AsSpan(0, _count), x));
}
private void AddAt(double x, double y)
{
if (Points is not { IsReadOnly: false } points) return;
var x = ToX(at.X);
var index = CurveMath.InsertionIndex(_xs.AsSpan(0, _count), x, MinimumGap, PinEnds);
if (index < 0) return;
points.Insert(index, new Point(x, CurveMath.ConstrainY(ToY(at.Y))));
points.Insert(index, new Point(x, CurveMath.ConstrainY(y)));
AfterEdit(points);
SetCurrentValue(SelectedIndexProperty, index);
RaiseEvent(new RoutedEventArgs(EditCompletedEvent));
}
/// <summary>Tells screen readers about a new selection or a moved point (the peer's value).</summary>
private void AnnounceSelection()
{
var text = SelectionText;
if (text == _announced) return;
var previous = _announced;
_announced = text;
UIElementAutomationPeer.FromElement(this)?.RaisePropertyChangedEvent(ValuePatternIdentifiers.ValueProperty, previous, text);
}
/// <summary>The coordinate readout next to the selected point, for keyboard edits.</summary>
private void ShowSelectionReadout()
{
var index = SelectedIndex;
if (!IsKeyboardFocused || index < 0 || index >= _count || _plot.Width < 1) return;
Readout.Show(ReadoutText(index), new Point(X(_xs[index]), Y(_ys[index])), FlowDirection.LeftToRight);
}
private bool Remove(int index)
{
if (Points is not { IsReadOnly: false } points || !CurveMath.CanRemove(_count, index, PinEnds)) return false;
@@ -372,8 +447,25 @@ public sealed class CurveEditor : DrawingElement
{
var x = XLabelFormatter ?? DefaultFormat;
var y = YLabelFormatter ?? DefaultFormat;
return x(_xs[index]) + " → " + y(_ys[index]);
return Loc.L("Common.CurveReadout", x(_xs[index]), y(_ys[index]));
}
private static string DefaultFormat(double value) => value.ToString("0.###", Loc.Culture);
}
/// <summary>The curve editor seen by UI Automation: its value reads the selected point ("Point 2 of 4: 0:12 → 0:30").</summary>
public sealed class CurveEditorAutomationPeer(CurveEditor owner) : DrawingElementAutomationPeer(owner), IValueProvider
{
public string Value => ((CurveEditor)Owner).SelectionText;
public bool IsReadOnly => true;
public void SetValue(string value) => throw new InvalidOperationException("The curve is edited with the arrow keys, not by text.");
public override object? GetPattern(PatternInterface patternInterface) =>
patternInterface == PatternInterface.Value ? this : base.GetPattern(patternInterface);
protected override AutomationControlType GetAutomationControlTypeCore() => AutomationControlType.Custom;
protected override string GetLocalizedControlTypeCore() => Loc.L("Common.Curve");
}
+28
View File
@@ -51,6 +51,34 @@ public static class CurveMath
return index;
}
/// <summary>
/// X of a point added from the keyboard: the playhead when a point fits there, otherwise the middle of the gap
/// after point <paramref name="selected"/> (before it for the last point; 0.5 on an empty curve).
/// </summary>
public static double KeyboardInsertionX(ReadOnlySpan<double> xs, int selected, double playhead, double minGap, bool pinEnds)
{
if (double.IsFinite(playhead) && InsertionIndex(xs, playhead, minGap, pinEnds) >= 0) return playhead;
if (xs.Length == 0) return 0.5;
if (xs.Length == 1) return xs[0] < 0.5 ? (xs[0] + 1) / 2 : xs[0] / 2;
var i = Math.Clamp(selected, 0, xs.Length - 2);
return (xs[i] + xs[i + 1]) / 2;
}
/// <summary>Y at <paramref name="x"/> on the straight segments through the points, flat beyond the ends; the identity without points.</summary>
public static double Interpolate(ReadOnlySpan<double> xs, ReadOnlySpan<double> ys, double x)
{
var n = Math.Min(xs.Length, ys.Length);
if (n == 0) return x;
if (x <= xs[0]) return ys[0];
for (var i = 1; i < n; i++)
{
if (x > xs[i]) continue;
var span = xs[i] - xs[i - 1];
return span > 0 ? ys[i - 1] + (x - xs[i - 1]) / span * (ys[i] - ys[i - 1]) : ys[i];
}
return ys[n - 1];
}
/// <summary>Whether point <paramref name="index"/> may be deleted: two points always remain and pinned ends stay.</summary>
public static bool CanRemove(int count, int index, bool pinEnds) =>
count > 2 && index >= 0 && index < count && (!pinEnds || (index > 0 && index < count - 1));
+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;
}
}
+47 -4
View File
@@ -1,5 +1,8 @@
using System.Diagnostics.CodeAnalysis;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Automation.Peers;
using System.Windows.Automation.Provider;
using System.Windows.Input;
using System.Windows.Media;
using Titano.Core.Diagnostics;
@@ -11,7 +14,8 @@ namespace Titano.Ui.Visuals;
/// (exposure steps ▼ in Sun/Warning, keyframes ◆ in Accent). The cell holding <see cref="CurrentIndex"/> is outlined
/// in Accent and an accent ▼ marks the exact frame. Click or drag seeks, the wheel and arrow keys step one frame
/// (PageUp/PageDown one cell, Home/End the ends). Thumbnails load asynchronously from <see cref="Source"/> into an
/// LRU cache; cells show a placeholder until their image arrives. Hovering a marker reads out its label.
/// LRU cache; cells show a placeholder until their image arrives. Hovering a marker reads out its label. Screen
/// readers see a slider over the frame index.
/// </summary>
public sealed class Filmstrip : DrawingElement
{
@@ -77,7 +81,10 @@ public sealed class Filmstrip : DrawingElement
/// <summary>Decoded thumbnails kept in memory.</summary>
public int CacheCapacity { get => (int)GetValue(CacheCapacityProperty); set => SetValue(CacheCapacityProperty, value); }
private int FrameCount => Source?.Count ?? 0;
internal int FrameCount => Source?.Count ?? 0;
/// <summary>Frames per thumbnail cell: the PageUp/PageDown step.</summary>
internal int CellFrames => Math.Max(1, FrameCount / Math.Max(1, _strip.CellCount));
protected override Size MeasureOverride(Size availableSize) => new(0, MarkerRow + 3 + CellHeight);
@@ -188,7 +195,7 @@ public sealed class Filmstrip : DrawingElement
base.OnKeyDown(e);
var count = FrameCount;
if (count == 0) return;
var cellFrames = Math.Max(1, count / Math.Max(1, _strip.CellCount));
var cellFrames = CellFrames;
int? target = e.Key switch
{
Key.Left => CurrentIndex - 1,
@@ -212,7 +219,14 @@ public sealed class Filmstrip : DrawingElement
strip.InvalidateVisual();
}
private static void OnCurrentIndexChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => ((Filmstrip)d).RenderOverlay();
protected override AutomationPeer OnCreateAutomationPeer() => new FilmstripAutomationPeer(this);
private static void OnCurrentIndexChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var strip = (Filmstrip)d;
strip.RenderOverlay();
UIElementAutomationPeer.FromElement(strip)?.RaisePropertyChangedEvent(RangeValuePatternIdentifiers.ValueProperty, (double)(int)e.OldValue, (double)(int)e.NewValue);
}
private static object CoerceCurrentIndex(DependencyObject d, object value)
{
@@ -347,3 +361,32 @@ public sealed class Filmstrip : DrawingElement
private readonly record struct CachedFrame(ImageSource Image, int PixelWidth);
}
/// <summary>The filmstrip seen by UI Automation: a slider whose value is the current frame (0-based).</summary>
public sealed class FilmstripAutomationPeer(Filmstrip owner) : DrawingElementAutomationPeer(owner), IRangeValueProvider
{
private Filmstrip Strip => (Filmstrip)Owner;
public double Value => Strip.CurrentIndex;
public double Minimum => 0;
public double Maximum => Math.Max(0, Strip.FrameCount - 1);
public double SmallChange => 1;
public double LargeChange => Strip.CellFrames;
public bool IsReadOnly => !IsEnabled();
public void SetValue(double value)
{
if (!IsEnabled()) throw new ElementNotEnabledException();
Strip.SetCurrentValue(Filmstrip.CurrentIndexProperty, (int)Math.Round(value));
}
public override object? GetPattern(PatternInterface patternInterface) =>
patternInterface == PatternInterface.RangeValue ? this : base.GetPattern(patternInterface);
protected override AutomationControlType GetAutomationControlTypeCore() => AutomationControlType.Slider;
}
+5 -5
View File
@@ -114,9 +114,9 @@ public sealed class HeatmapStrip : DrawingElement
{
for (var c = 0; c < columns.Count; c++)
{
var label = CreateText(columns[c], LabelSize, faint);
var label = CreateLabel(columns[c], LabelSize, faint);
var (x, _) = _grid.CellOrigin(0, c);
dc.DrawText(label, new Point(x + (_grid.CellSize - label.Width) / 2, 0));
DrawTextAt(dc, label, new Point(x + (_grid.CellSize - label.Width) / 2, 0));
}
}
@@ -126,9 +126,9 @@ public sealed class HeatmapStrip : DrawingElement
for (var r = 0; r < rows.Count; r++)
{
var row = rows[r];
var label = CreateText(row.Label, LabelSize, faint);
var label = CreateLabel(row.Label, LabelSize, faint);
var (_, y) = _grid.CellOrigin(r, 0);
dc.DrawText(label, new Point(_grid.Left - 8 - label.Width, y + (_grid.CellSize - label.Height) / 2));
DrawTextAt(dc, label, new Point(_grid.Left - 8 - label.Width, y + (_grid.CellSize - label.Height) / 2));
for (var c = 0; c < _grid.Columns; c++)
{
var (x, _) = _grid.CellOrigin(r, c);
@@ -192,7 +192,7 @@ public sealed class HeatmapStrip : DrawingElement
var faint = Brushes.Transparent;
var labelWidth = 0.0;
if (Rows is { } rows)
for (var r = 0; r < rows.Count; r++) labelWidth = Math.Max(labelWidth, CreateText(rows[r].Label, LabelSize, faint).Width);
for (var r = 0; r < rows.Count; r++) labelWidth = Math.Max(labelWidth, CreateLabel(rows[r].Label, LabelSize, faint).Width);
var left = Math.Ceiling(labelWidth) + 8;
var top = ColumnLabels is { Count: > 0 } ? LabelHeight() + 4 : 0;
var cell = CellGridLayout.FitCellSize(width - left, height - top, RowCount, ColumnCount, CellGap, MaxCellSize);
+25 -10
View File
@@ -1,36 +1,51 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using Titano.Ui.Controls;
namespace Titano.Ui.Visuals;
/// <summary>
/// A tooltip (same style as every other) that opens at once and follows the mouse to read out the value under
/// the cursor. While it shows, the owner's own tooltip (which describes the action) is suppressed.
/// the cursor. While it shows, the owner's own tooltip (which describes the action) is suppressed. The text reads in
/// the UI language's direction unless the caller pins a numeric readout left to right.
/// </summary>
public sealed class HoverReadout(FrameworkElement owner)
{
private ToolTip? _tip;
private TextBlock? _text;
private object? _savedEnabled;
public bool IsOpen => _tip?.IsOpen == true;
/// <summary>Shows <paramref name="text"/> next to <paramref name="position"/> (owner coordinates); empty text hides the readout.</summary>
public void Show(string? text, Point position)
/// <summary>
/// Shows <paramref name="text"/> next to <paramref name="position"/> (owner coordinates); empty text hides the
/// readout. <paramref name="direction"/> defaults to the UI language's.
/// </summary>
public void Show(string? text, Point position, FlowDirection? direction = null)
{
if (string.IsNullOrEmpty(text))
{
Hide();
return;
}
_tip ??= new ToolTip
if (_tip is null)
{
Placement = PlacementMode.Relative,
PlacementTarget = owner,
IsHitTestVisible = false,
Focusable = false,
};
if (!Equals(_tip.Content, text)) _tip.Content = text;
// The tip keeps the owner's direction so its placement offsets stay the owner's; only the text inside reads
// right to left. The content is explicit, so the tooltip style's text settings are repeated here.
_text = new TextBlock { TextWrapping = TextWrapping.Wrap, LineHeight = 16 };
_tip = new ToolTip
{
Placement = PlacementMode.Relative,
PlacementTarget = owner,
IsHitTestVisible = false,
Focusable = false,
FlowDirection = owner.FlowDirection,
Content = _text,
};
}
_text!.FlowDirection = direction ?? Bidi.UiDirection;
if (_text.Text != text) _text.Text = text;
// Below-right of the cursor so the popup never sits under the mouse (which would end the hover).
_tip.HorizontalOffset = position.X + 12;
_tip.VerticalOffset = position.Y + 18;
+4
View File
@@ -1,4 +1,5 @@
using System.Windows;
using System.Windows.Automation.Peers;
using System.Windows.Media;
namespace Titano.Ui.Visuals;
@@ -50,6 +51,9 @@ public sealed class PreviewSurface : DrawingElement
protected override Visual GetVisualChild(int index) => _layers[index];
/// <summary>The viewport is the image screen readers see; the surface adds nothing to it.</summary>
protected override AutomationPeer OnCreateAutomationPeer() => null!;
/// <summary>Redraws both images over the image rectangle [0, size].</summary>
internal void SetImages(ImageSource? corrected, ImageSource? original, Size imageSize)
{
+26 -1
View File
@@ -1,8 +1,10 @@
using System.Windows;
using System.Windows.Automation.Peers;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Titano.Core.Localization;
namespace Titano.Ui.Visuals;
@@ -39,7 +41,8 @@ public readonly record struct MotionVector(float X, float Y, float Dx, float Dy)
/// polyline) and a crop mask (normalised <see cref="CropRect"/>; dims or hides what the output loses). Tools go
/// bottom-left (<see cref="ToolsContent"/>), the shot data pill bottom-right (<see cref="InfoText"/>). Images and
/// overlays are retained visuals under one shared transform, so panning re-renders nothing. Double-click toggles
/// Fit and 1:1; Ctrl+0 fits, Ctrl+1 shows 1:1.
/// Fit and 1:1; Ctrl+0 fits, Ctrl+1 shows 1:1. Screen readers see an image (named by AutomationProperties.Name)
/// whose status is the zoom and whose help text is the shot data, holding the tools.
/// </summary>
[TemplatePart(Name = PartSurface, Type = typeof(FrameworkElement))]
[TemplatePart(Name = PartTools, Type = typeof(FrameworkElement))]
@@ -298,6 +301,8 @@ public class PreviewViewport : Control
ApplyZoomMode();
}
protected override AutomationPeer OnCreateAutomationPeer() => new PreviewViewportAutomationPeer(this);
private static object CoerceUnit(DependencyObject d, object value) => double.IsNaN((double)value) ? 0.5 : Math.Clamp((double)value, 0, 1);
private static object CoerceZoom(DependencyObject d, object value) =>
@@ -411,3 +416,23 @@ public class PreviewViewport : Control
return !_imageSize.IsEmpty && (_imageSize.Width * _view.Scale > view.Width + 0.5 || _imageSize.Height * _view.Scale > view.Height + 0.5);
}
}
/// <summary>The preview seen by UI Automation: an image whose status gives the zoom ("50 %") and whose help text is the shot data.</summary>
public sealed class PreviewViewportAutomationPeer(PreviewViewport owner) : FrameworkElementAutomationPeer(owner)
{
protected override AutomationControlType GetAutomationControlTypeCore() => AutomationControlType.Image;
protected override string GetClassNameCore() => nameof(PreviewViewport);
protected override string GetItemStatusCore()
{
var viewport = (PreviewViewport)Owner;
return viewport.ImageSize.IsEmpty ? string.Empty : Loc.L("Common.Percent", Math.Round(viewport.Zoom * 100));
}
protected override string GetHelpTextCore()
{
var help = base.GetHelpTextCore();
return string.IsNullOrEmpty(help) ? ((PreviewViewport)Owner).InfoText ?? string.Empty : help;
}
}
+10 -7
View File
@@ -86,7 +86,7 @@ public sealed class SeriesChart : DrawingElement
/// <summary>Explicit legend entries; null lists the titled series.</summary>
public IReadOnlyList<ChartLegendItem>? Legend { get => (IReadOnlyList<ChartLegendItem>?)GetValue(LegendProperty); set => SetValue(LegendProperty, value); }
/// <summary>Right-aligned text of the legend row (e.g. "flicker −67 % · max step 0.21 EV").</summary>
/// <summary>Text closing the legend row, at its end side (e.g. "flicker −67 % · max step 0.21 EV").</summary>
public string? Summary { get => (string?)GetValue(SummaryProperty); set => SetValue(SummaryProperty, value); }
public bool ShowLegend { get => (bool)GetValue(ShowLegendProperty); set => SetValue(ShowLegendProperty, value); }
@@ -114,6 +114,8 @@ public sealed class SeriesChart : DrawingElement
/// <summary>Formatting of frame indices (readout header and, when set, X axis labels).</summary>
public Func<double, string>? XLabelFormatter { get => (Func<double, string>?)GetValue(XLabelFormatterProperty); set => SetValue(XLabelFormatterProperty, value); }
protected internal override string? AutomationDescription => Summary;
protected override Size MeasureOverride(Size availableSize) => new(0, 160);
protected override void OnDataChanged()
@@ -290,15 +292,16 @@ public sealed class SeriesChart : DrawingElement
{
var items = Legend ?? AutoLegend();
if (items.Count == 0 && string.IsNullOrEmpty(Summary)) return 0;
var right = width;
double left = 0, right = width;
if (!string.IsNullOrEmpty(Summary))
{
var summary = CreateText(Summary, LabelSize, GetBrush("Brush.TextMuted"));
right -= summary.Width;
dc.DrawText(summary, new Point(right, 0));
right -= 16;
var summary = CreateLabel(Summary, LabelSize, GetBrush("Brush.TextMuted"));
var x = FromStart(width - summary.Width, summary.Width, width);
DrawTextAt(dc, summary, new Point(x, 0));
if (Loc.IsRightToLeft) left = summary.Width + 16;
else right = x - 16;
}
DrawLegend(dc, items, new Point(0, 0), right, LabelSize);
DrawLegend(dc, items, left, right, 0, LabelSize);
return LegendHeight;
}
+55 -1
View File
@@ -1,5 +1,8 @@
using System.Collections;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Automation.Peers;
using System.Windows.Automation.Provider;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
@@ -12,7 +15,9 @@ namespace Titano.Ui.Visuals;
/// The main part executes <see cref="Command"/>; choosing a menu entry sets <see cref="SelectedItem"/> (checked in
/// the menu) — bind <see cref="CommandParameter"/> to it to act on the chosen preset. The control's ToolTip
/// describes the main action, <see cref="DropDownToolTip"/> the ▾ part. F4 or Alt+Down opens the menu.
/// <see cref="IsPrimary"/> gives the accent look of the screen's primary button.
/// <see cref="IsPrimary"/> gives the accent look of the screen's primary button. Screen readers see a split button
/// (named by AutomationProperties.Name or the content) that invokes and expands, holding the two parts;
/// <see cref="DropDownName"/> names the ▾ part.
/// </summary>
public class SplitButton : Control
{
@@ -25,6 +30,7 @@ public class SplitButton : Control
public static readonly DependencyProperty ItemContainerStyleProperty = DependencyProperty.Register(nameof(ItemContainerStyle), typeof(Style), typeof(SplitButton));
public static readonly DependencyProperty DisplayMemberPathProperty = DependencyProperty.Register(nameof(DisplayMemberPath), typeof(string), typeof(SplitButton));
public static readonly DependencyProperty DropDownToolTipProperty = DependencyProperty.Register(nameof(DropDownToolTip), typeof(object), typeof(SplitButton));
public static readonly DependencyProperty DropDownNameProperty = DependencyProperty.Register(nameof(DropDownName), typeof(string), typeof(SplitButton));
public static readonly DependencyProperty IsPrimaryProperty = DependencyProperty.Register(nameof(IsPrimary), typeof(bool), typeof(SplitButton));
public static readonly DependencyProperty SelectedItemProperty = DependencyProperty.Register(
@@ -69,6 +75,9 @@ public class SplitButton : Control
/// <summary>Tooltip of the ▾ part.</summary>
public object? DropDownToolTip { get => GetValue(DropDownToolTipProperty); set => SetValue(DropDownToolTipProperty, value); }
/// <summary>Accessible name of the ▾ part (default "More choices").</summary>
public string? DropDownName { get => (string?)GetValue(DropDownNameProperty); set => SetValue(DropDownNameProperty, value); }
/// <summary>Accent fill (the one primary action of a screen).</summary>
public bool IsPrimary { get => (bool)GetValue(IsPrimaryProperty); set => SetValue(IsPrimaryProperty, value); }
@@ -84,11 +93,25 @@ public class SplitButton : Control
}
}
protected override AutomationPeer OnCreateAutomationPeer() => new SplitButtonAutomationPeer(this);
/// <summary>Runs the main action, as a click on the main part does.</summary>
internal void Invoke()
{
if (Command is { } command && command.CanExecute(CommandParameter)) command.Execute(CommandParameter);
}
private static void OnIsDropDownOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var button = (SplitButton)d;
if ((bool)e.NewValue) button.EnsureMenu().IsOpen = true;
else if (button._menu is { IsOpen: true } menu) menu.IsOpen = false;
if (UIElementAutomationPeer.FromElement(button) is { } peer)
{
peer.RaisePropertyChangedEvent(ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
(bool)e.OldValue ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed,
(bool)e.NewValue ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed);
}
}
private ContextMenu EnsureMenu()
@@ -124,3 +147,34 @@ public class SplitButton : Control
container.IsChecked = Equals(_menu.Items[i], SelectedItem);
}
}
/// <summary>UI Automation view of a <see cref="SplitButton"/>: Invoke runs the main action, ExpandCollapse opens the choices.</summary>
public sealed class SplitButtonAutomationPeer(SplitButton owner) : FrameworkElementAutomationPeer(owner), IInvokeProvider, IExpandCollapseProvider
{
private SplitButton Button => (SplitButton)Owner;
public ExpandCollapseState ExpandCollapseState => Button.IsDropDownOpen ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed;
public override object? GetPattern(PatternInterface patternInterface) =>
patternInterface is PatternInterface.Invoke or PatternInterface.ExpandCollapse ? this : base.GetPattern(patternInterface);
public void Invoke()
{
if (!IsEnabled()) throw new ElementNotEnabledException();
Button.Invoke();
}
public void Expand() => Button.SetCurrentValue(SplitButton.IsDropDownOpenProperty, true);
public void Collapse() => Button.SetCurrentValue(SplitButton.IsDropDownOpenProperty, false);
protected override AutomationControlType GetAutomationControlTypeCore() => AutomationControlType.SplitButton;
protected override string GetClassNameCore() => nameof(SplitButton);
protected override string GetNameCore()
{
var name = base.GetNameCore();
return string.IsNullOrEmpty(name) ? Button.Content as string ?? string.Empty : name;
}
}
+13 -7
View File
@@ -62,6 +62,9 @@ public sealed class StackedBar : DrawingElement
remove => RemoveHandler(ItemActivatedEvent, value);
}
protected internal override string? AutomationDescription =>
Items is { Count: > 0 } items ? string.Join(Environment.NewLine, Enumerable.Range(0, items.Count).Select(ReadoutText)) : null;
protected override Size MeasureOverride(Size availableSize)
{
if (Items is not { Count: > 0 } items) return new Size(0, 0);
@@ -147,7 +150,10 @@ public sealed class StackedBar : DrawingElement
private string Share(double share) => ShareFormatter?.Invoke(share) ?? share.ToString("P0", Loc.Culture);
/// <summary>Flows legend entries into lines of the given width; draws them when <paramref name="dc"/> is set. Returns the line count.</summary>
/// <summary>
/// Flows legend entries into lines of the given width from the reading direction's side (the bar itself never
/// mirrors); draws them when <paramref name="dc"/> is set. Returns the line count.
/// </summary>
private int LayoutLegend(IReadOnlyList<ChartItem> items, double width, DrawingContext? dc)
{
var total = Total(items);
@@ -158,8 +164,8 @@ public sealed class StackedBar : DrawingElement
var top = BarHeight + LegendGap;
for (var i = 0; i < items.Count; i++)
{
var label = CreateText(items[i].Label, LabelSize, muted);
var value = CreateText(items[i].ValueText ?? Share(total > 0 ? Math.Max(0, items[i].Value) / total : 0), LabelSize, text);
var label = CreateLabel(items[i].Label, LabelSize, muted);
var value = CreateLabel(items[i].ValueText ?? Share(total > 0 ? Math.Max(0, items[i].Value) / total : 0), LabelSize, text);
var entryWidth = 8 + 6 + label.Width + 4 + value.Width;
if (x > 0 && double.IsFinite(width) && x + entryWidth > width)
{
@@ -171,11 +177,11 @@ public sealed class StackedBar : DrawingElement
var y = top + line * LegendLine;
var cy = y + label.Height / 2;
dc.PushOpacity(OpacityOf(i, items));
dc.DrawRoundedRectangle(GetBrush(items[i].BrushKey ?? BrushKey), null, new Rect(x, cy - 4, 8, 8), 2, 2);
dc.DrawRoundedRectangle(GetBrush(items[i].BrushKey ?? BrushKey), null, new Rect(FromStart(x, 8, width), cy - 4, 8, 8), 2, 2);
dc.Pop();
dc.DrawText(label, new Point(x + 14, y));
dc.DrawText(value, new Point(x + 14 + label.Width + 4, y));
_entries.Add(new Rect(x, y, entryWidth, LegendLine));
DrawTextAt(dc, label, new Point(FromStart(x + 14, label.Width, width), y));
DrawTextAt(dc, value, new Point(FromStart(x + 14 + label.Width + 4, value.Width, width), y));
_entries.Add(new Rect(FromStart(x, entryWidth, width), y, entryWidth, LegendLine));
}
x += entryWidth + EntryGap;
}
+4 -4
View File
@@ -132,8 +132,8 @@ public sealed class TimelineBands : DrawingElement
var top = b * BandHeight;
var baseline = top + BandHeight - captionHeight - 8;
var barSpace = baseline - top - 8;
var title = CreateText(band.Label, 13, text, semiBold: true);
dc.DrawText(title, new Point(0, top + (BandHeight - title.Height) / 2));
var title = CreateLabel(band.Label, 13, text, semiBold: true);
DrawTextAt(dc, title, new Point(0, top + (BandHeight - title.Height) / 2));
for (var s = 0; s < slots; s++)
{
var cx = LabelColumn + pitch * (s + 0.5);
@@ -145,8 +145,8 @@ public sealed class TimelineBands : DrawingElement
}
if (SlotLabels is { } labels && s < labels.Count)
{
var caption = CreateText(labels[s], LabelSize, faint);
dc.DrawText(caption, new Point(cx - caption.Width / 2, baseline + 4));
var caption = CreateLabel(labels[s], LabelSize, faint);
DrawTextAt(dc, caption, new Point(cx - caption.Width / 2, baseline + 4));
}
if (b == CurrentBand && s == CurrentSlot)
dc.DrawRoundedRectangle(null, GetPen("Brush.Accent", 1.5), new Rect(cx - pitch / 2 + 2, top + 4, pitch - 4, BandHeight - 8), 4, 4);