fix(ui): kit follow-ups for lists, chart contrast, activation and RTL bars

- ListBox (and the Library card grid) get a theme template that keeps their
  fill when disabled; ListView keeps the system GridView template.
- BarChart, HeatmapStrip, SeriesChart and TimelineBands draw their labels in
  TextMuted; heatmap cells without data take the Stroke tone.
- Category charts show the hand cursor and take the keyboard (arrows, Home,
  End, Enter, Space) only while an activation handler is attached to them;
  the keyboard item is outlined, read out and exposed as ItemStatus.
- Horizontal bar charts and stacked bars start on the reading side in
  right-to-left languages; vertical bars, heatmaps and time axes stay LTR.
- Archive drops its local list template, Focus.Inset copy, chart brush
  aliases and the redundant FlowDirection on the template box.

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:55:50 +00:00
1 parent 712bf9417f
commit 37ed91500d
10 files changed
+350 -197

No files matched your search

+152 -3
View File
@@ -1,7 +1,9 @@
using System.Collections.Specialized;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Automation.Peers;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using Titano.Core.Localization;
using Titano.Ui.Controls;
@@ -12,9 +14,17 @@ 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;
/// 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"/>).
/// <see cref="UIElement.OnRender"/>. The element itself is always left-to-right, so time axes and images never
/// mirror; words (categories, legends, summaries) still read in the UI language's direction
/// (<see cref="CreateLabel"/>), legends start on its side, and a category chart places its bars from that side
/// (<see cref="FromStart"/>). Screen readers see a named image (<see cref="DrawingElementAutomationPeer"/>).
/// <para>
/// A chart of discrete items (bars, segments, cells) describes them through <see cref="ItemCount"/>,
/// <see cref="ItemAt"/>, <see cref="ItemBounds"/> and <see cref="ItemText"/>: hovering one reads it out and clicking
/// it calls <see cref="Activate"/>. Only while a handler of its activation event is attached to the chart
/// (<see cref="TrackActivation"/>) does an item show the hand cursor and the chart take the keyboard: the arrows
/// choose an item (<see cref="Navigate"/>), Enter or Space activates it.
/// </para>
/// </summary>
public abstract class DrawingElement : FrameworkElement
{
@@ -28,6 +38,8 @@ public abstract class DrawingElement : FrameworkElement
private HoverReadout? _readout;
private Typeface? _regular;
private Typeface? _semiBold;
private Delegate? _activationHandlers;
private int _keyboardItem = -1;
/// <param name="hasOverlay">Creates the overlay layer drawn by <see cref="OnRenderOverlay"/>.</param>
protected DrawingElement(bool hasOverlay = false)
@@ -101,6 +113,51 @@ public abstract class DrawingElement : FrameworkElement
/// </summary>
protected internal virtual string? AutomationDescription => null;
/// <summary>The item the keyboard is on, read to screen readers as the image's status; null when none.</summary>
internal string? KeyboardItemText => IsActivatable && _keyboardItem >= 0 && _keyboardItem < ItemCount ? ItemText(_keyboardItem) : null;
/// <summary>Whether a handler of the visual's activation event is attached to the visual itself (not to an ancestor).</summary>
protected bool IsActivatable => _activationHandlers is not null;
/// <summary>Number of discrete items (bars, segments, cells); 0 for visuals without items.</summary>
protected virtual int ItemCount => 0;
/// <summary>Item under <paramref name="point"/>, or −1.</summary>
protected virtual int ItemAt(Point point) => -1;
/// <summary>Where <paramref name="item"/> was last drawn: the keyboard outline follows this rectangle.</summary>
protected virtual Rect ItemBounds(int item) => Rect.Empty;
/// <summary>What the readout says for <paramref name="item"/>.</summary>
protected virtual string? ItemText(int item) => null;
/// <summary>The item an arrow key moves to from <paramref name="item"/>; −1 when the key does not move.</summary>
protected virtual int Navigate(int item, Key key) => -1;
/// <summary>Raises the visual's activation event for <paramref name="item"/>.</summary>
protected virtual void Activate(int item)
{
}
/// <summary>Records a handler added to or removed from the activation event; call from the event's accessors.</summary>
protected void TrackActivation(Delegate handler, bool added)
{
_activationHandlers = added ? Delegate.Combine(_activationHandlers, handler) : Delegate.Remove(_activationHandlers, handler);
SetCurrentValue(FocusableProperty, IsActivatable);
InvalidateVisual();
}
/// <summary>The cursor the visual shows at <paramref name="point"/>: the hand over an item something activates, otherwise none of its own.</summary>
internal Cursor? CursorAt(Point point) => IsActivatable && ItemAt(point) >= 0 ? Cursors.Hand : null;
/// <summary>Outlines the keyboard's item while the visual has keyboard focus (DESIGN §4: 2 px Accent); call last in OnRender.</summary>
protected void DrawKeyboardItem(DrawingContext dc)
{
if (!IsKeyboardFocused || !IsActivatable || _keyboardItem < 0 || _keyboardItem >= ItemCount) return;
var bounds = ItemBounds(_keyboardItem);
if (!bounds.IsEmpty) dc.DrawRoundedRectangle(null, GetPen("Brush.Accent", 2), bounds, 4, 4);
}
/// <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);
@@ -142,6 +199,7 @@ public abstract class DrawingElement : FrameworkElement
/// <summary>Called when a data property or a watched collection changed; the default re-measures and redraws.</summary>
protected virtual void OnDataChanged()
{
_keyboardItem = Math.Min(_keyboardItem, ItemCount - 1);
InvalidateMeasure();
InvalidateVisual();
}
@@ -163,6 +221,90 @@ public abstract class DrawingElement : FrameworkElement
OnThemeChanged();
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
if (ItemCount == 0) return;
var p = e.GetPosition(this);
var item = ItemAt(p);
Readout.Show(item >= 0 ? ItemText(item) : null, p);
}
protected override void OnMouseLeave(MouseEventArgs e)
{
base.OnMouseLeave(e);
if (ItemCount > 0) Readout.Hide();
}
protected override void OnQueryCursor(QueryCursorEventArgs e)
{
base.OnQueryCursor(e);
if (e.Handled || CursorAt(e.GetPosition(this)) is not { } cursor) return;
e.Cursor = cursor;
e.Handled = true;
}
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonUp(e);
if (e.Handled || ItemCount == 0) return;
var item = ItemAt(e.GetPosition(this));
if (item < 0) return;
_keyboardItem = item;
Activate(item);
e.Handled = true;
}
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
var count = ItemCount;
if (e.Handled || !IsActivatable || count == 0) return;
var current = Math.Clamp(_keyboardItem, 0, count - 1);
if (e.Key is Key.Enter or Key.Space)
{
MoveKeyboardTo(current);
Activate(current);
e.Handled = true;
return;
}
var next = e.Key switch
{
Key.Home => 0,
Key.End => count - 1,
_ => Navigate(current, e.Key),
};
if (next < 0) return;
MoveKeyboardTo(Math.Min(next, count - 1));
e.Handled = true;
}
protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
{
base.OnGotKeyboardFocus(e);
if (IsActivatable && ItemCount > 0 && ReferenceEquals(e.NewFocus, this)) MoveKeyboardTo(Math.Clamp(_keyboardItem, 0, ItemCount - 1));
}
protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
{
base.OnLostKeyboardFocus(e);
if (!IsActivatable) return;
Readout.Hide();
InvalidateVisual();
}
/// <summary>Puts the keyboard on <paramref name="item"/>: outlined, read out next to it and announced as the image's status.</summary>
private void MoveKeyboardTo(int item)
{
var before = KeyboardItemText;
_keyboardItem = item;
InvalidateVisual();
var bounds = ItemBounds(item);
if (!bounds.IsEmpty) Readout.Show(ItemText(item), bounds.BottomLeft);
UIElementAutomationPeer.FromElement(this)?.RaisePropertyChangedEvent(AutomationElementIdentifiers.ItemStatusProperty, before ?? string.Empty,
KeyboardItemText ?? string.Empty);
}
/// <summary>Fills the whole element with a transparent brush so empty areas still receive the mouse.</summary>
protected void DrawHitArea(DrawingContext dc) => dc.DrawRectangle(Brushes.Transparent, null, new Rect(RenderSize));
@@ -281,4 +423,11 @@ public class DrawingElementAutomationPeer(DrawingElement owner) : FrameworkEleme
var name = base.GetNameCore();
return string.IsNullOrEmpty(name) ? ((DrawingElement)Owner).AutomationDescription ?? string.Empty : name;
}
/// <summary>The item the keyboard is on, unless AutomationProperties.ItemStatus says otherwise.</summary>
protected override string GetItemStatusCore()
{
var status = base.GetItemStatusCore();
return string.IsNullOrEmpty(status) ? ((DrawingElement)Owner).KeyboardItemText ?? string.Empty : status;
}
}