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

+5
View File
@@ -123,6 +123,10 @@ I["Triangle"] = (None, "M8 3 L13.5 12.5 H2.5 Z")
I["TriangleRight"] = (None, "M5 3 L12 8 L5 13 Z")
I["Cross"] = ("M4.5 4.5 L11.5 11.5 M11.5 4.5 L4.5 11.5", None)
# Glyphs that point along the reading direction (arrows, chevrons, start-aligned text lines): mirrored in RTL.
# Everything else (clocks, media controls, the ▶ rendered status, symmetric shapes) never mirrors.
DIRECTIONAL = {"Back", "Forward", "ChevronLeft", "ChevronRight", "ExternalLink", "Jobs", "Logs", "ViewList"}
out = os.path.join(os.path.dirname(__file__), "..", "..", "src", "Titano.Ui", "Icons", "Icons.xaml")
with open(out, "w") as f:
f.write('<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"\n')
@@ -133,6 +137,7 @@ with open(out, "w") as f:
attrs = ''
if stroke: attrs += f' Stroke="{stroke}"'
if fill: attrs += f' Fill="{fill}"'
if name in DIRECTIONAL: attrs += ' IsDirectional="True"'
f.write(f' <ui:IconData x:Key="Icon.{name}"{attrs} />\n')
f.write('</ResourceDictionary>\n')
+7
View File
@@ -5,12 +5,19 @@
<resheader name="reader"><value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value></resheader>
<resheader name="writer"><value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value></resheader>
<data name="Common.Auto" xml:space="preserve"><value>Auto</value></data>
<data name="Common.AutoValue" xml:space="preserve"><value>Auto · {0}</value><comment>{0} advisor value</comment></data>
<data name="Common.Curve" xml:space="preserve"><value>curve</value><comment>control type read by screen readers, lower case</comment></data>
<data name="Common.CurvePoint" xml:space="preserve"><value>Point {0} of {1}: {2}</value><comment>{0} position; {1} point count; {2} coordinates (Common.CurveReadout)</comment></data>
<data name="Common.CurveReadout" xml:space="preserve"><value>{0} → {1}</value><comment>{0} horizontal value; {1} vertical value; right-to-left languages point the arrow left</comment></data>
<data name="Common.Duration.Days" xml:space="preserve"><value>{0} d {1} h</value></data>
<data name="Common.Duration.Hours" xml:space="preserve"><value>{0} h {1} m</value></data>
<data name="Common.Duration.Minutes" xml:space="preserve"><value>{0} min</value></data>
<data name="Common.Duration.Seconds" xml:space="preserve"><value>{0} s</value></data>
<data name="Common.MoreChoices" xml:space="preserve"><value>More choices</value></data>
<data name="Common.NotApplicable" xml:space="preserve"><value>n/a</value></data>
<data name="Common.Open" xml:space="preserve"><value>Open</value></data>
<data name="Common.OpenLogs" xml:space="preserve"><value>Open logs</value></data>
<data name="Common.Percent" xml:space="preserve"><value>{0} %</value></data>
<data name="Common.Remove" xml:space="preserve"><value>Remove</value></data>
<data name="Common.ResetToAuto" xml:space="preserve"><value>Back to Auto</value></data>
</root>
+1
View File
@@ -87,6 +87,7 @@
<data name="Tooltips.Archive.Verify" xml:space="preserve"><value>Re-hash every original and report bit rot · reads the whole archive</value></data>
<data name="Tooltips.Archive.YearRow" xml:space="preserve"><value>{0} · Right arrow opens the year, Left arrow closes it</value></data>
<data name="Tooltips.Common.Dismiss" xml:space="preserve"><value>Dismiss</value></data>
<data name="Tooltips.Common.DismissToast" xml:space="preserve"><value>Close this notice · Esc</value></data>
<data name="Tooltips.Common.OpenLogs" xml:space="preserve"><value>Open the folder with the log files</value></data>
<data name="Tooltips.Common.ResetToAuto" xml:space="preserve"><value>Return to the advisor's value</value></data>
<data name="Tooltips.Editor.Analyse" xml:space="preserve"><value>Read every frame again and refresh the analysis · Ctrl+Shift+A</value></data>
+7
View File
@@ -5,12 +5,19 @@
<resheader name="reader"><value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value></resheader>
<resheader name="writer"><value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value></resheader>
<data name="Common.Auto" xml:space="preserve"><value>Auto</value></data>
<data name="Common.AutoValue" xml:space="preserve"><value>Auto · {0}</value></data>
<data name="Common.Curve" xml:space="preserve"><value>curva</value></data>
<data name="Common.CurvePoint" xml:space="preserve"><value>Punto {0} di {1}: {2}</value></data>
<data name="Common.CurveReadout" xml:space="preserve"><value>{0} → {1}</value></data>
<data name="Common.Duration.Days" xml:space="preserve"><value>{0} g {1} h</value></data>
<data name="Common.Duration.Hours" xml:space="preserve"><value>{0} h {1} m</value></data>
<data name="Common.Duration.Minutes" xml:space="preserve"><value>{0} min</value></data>
<data name="Common.Duration.Seconds" xml:space="preserve"><value>{0} s</value></data>
<data name="Common.MoreChoices" xml:space="preserve"><value>Altre scelte</value></data>
<data name="Common.NotApplicable" xml:space="preserve"><value>n/d</value></data>
<data name="Common.Open" xml:space="preserve"><value>Apri</value></data>
<data name="Common.OpenLogs" xml:space="preserve"><value>Apri log</value></data>
<data name="Common.Percent" xml:space="preserve"><value>{0}%</value></data>
<data name="Common.Remove" xml:space="preserve"><value>Rimuovi</value></data>
<data name="Common.ResetToAuto" xml:space="preserve"><value>Torna ad Auto</value></data>
</root>
+1
View File
@@ -87,6 +87,7 @@
<data name="Tooltips.Archive.Verify" xml:space="preserve"><value>Ricalcola l'hash di ogni originale e segnala i danni · legge tutto l'archivio</value></data>
<data name="Tooltips.Archive.YearRow" xml:space="preserve"><value>{0} · Freccia destra apre l'anno, freccia sinistra lo chiude</value></data>
<data name="Tooltips.Common.Dismiss" xml:space="preserve"><value>Chiudi</value></data>
<data name="Tooltips.Common.DismissToast" xml:space="preserve"><value>Chiudi questo avviso · Esc</value></data>
<data name="Tooltips.Common.OpenLogs" xml:space="preserve"><value>Apri la cartella dei file di log</value></data>
<data name="Tooltips.Common.ResetToAuto" xml:space="preserve"><value>Torna al valore consigliato</value></data>
<data name="Tooltips.Editor.Analyse" xml:space="preserve"><value>Rilegge ogni fotogramma e aggiorna l’analisi · Ctrl+Maiusc+A</value></data>
+33 -4
View File
@@ -1,14 +1,17 @@
using System.Windows;
using System.Windows.Automation.Peers;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using Titano.Core.Localization;
namespace Titano.Ui.Controls;
/// <summary>
/// Advisor-aware slider (BRIEF §10.4, DESIGN §4): in Auto the track is accent with an "Auto · value" pill whose
/// tooltip carries the advisor's reason; touching the slider switches to manual (sun track, value shown, reset
/// button returns to Auto). When not applicable the value reads "n/a" with the reason in the tooltip.
/// button returns to Auto). When not applicable the value reads "n/a" with the reason in the tooltip. Screen readers
/// see a group named after <see cref="Header"/> holding the named slider, the Auto pill and the reset button.
/// </summary>
[TemplatePart(Name = PartSlider, Type = typeof(Slider))]
public class AutoSlider : Control
@@ -47,6 +50,14 @@ public class AutoSlider : Control
public AutoSlider()
{
CommandBindings.Add(new CommandBinding(ResetCommand, (_, _) => ResetToAuto()));
// The pill and the value follow a language switch; the static event is held only while the slider is shown.
Loaded += (_, _) =>
{
Loc.CultureChanged -= OnCultureChanged;
Loc.CultureChanged += OnCultureChanged;
UpdateTexts();
};
Unloaded += (_, _) => Loc.CultureChanged -= OnCultureChanged;
UpdateTexts();
}
@@ -67,7 +78,7 @@ public class AutoSlider : Control
/// <summary>Formatted current value (read by the template).</summary>
public string DisplayValue { get => (string)GetValue(DisplayValueProperty); private set => SetValue(DisplayValueProperty, value); }
/// <summary>"Auto · 41" pill text; the "Auto" word comes from the catalog (Common.Auto).</summary>
/// <summary>"Auto · 41" pill text (Common.AutoValue).</summary>
public string AutoText { get => (string)GetValue(AutoTextProperty); private set => SetValue(AutoTextProperty, value); }
/// <summary>Tooltip of the slider track: what moving it does.</summary>
@@ -131,12 +142,30 @@ public class AutoSlider : Control
s.UpdateTexts();
}
protected override AutomationPeer OnCreateAutomationPeer() => new AutoSliderAutomationPeer(this);
private static void OnFormatChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => ((AutoSlider)d).UpdateTexts();
private void OnCultureChanged(object? sender, EventArgs e) => UpdateTexts();
private void UpdateTexts()
{
var culture = Core.Localization.Loc.Culture;
var culture = Loc.Culture;
DisplayValue = Value.ToString(ValueFormat, culture);
AutoText = Core.Localization.Loc.L("Common.Auto") + " · " + AutoValue.ToString(ValueFormat, culture);
AutoText = Loc.L("Common.AutoValue", AutoValue.ToString(ValueFormat, culture));
}
}
/// <summary>A named group around the slider, the Auto pill and the reset button.</summary>
public sealed class AutoSliderAutomationPeer(AutoSlider owner) : FrameworkElementAutomationPeer(owner)
{
protected override AutomationControlType GetAutomationControlTypeCore() => AutomationControlType.Group;
protected override string GetClassNameCore() => nameof(AutoSlider);
protected override string GetNameCore()
{
var name = base.GetNameCore();
return string.IsNullOrEmpty(name) ? ((AutoSlider)Owner).Header ?? string.Empty : name;
}
}
+30
View File
@@ -0,0 +1,30 @@
using System.Windows;
namespace Titano.Ui.Controls;
/// <summary>
/// Right-to-left rules of the kit (BRIEF §16, DESIGN §5). Windows take their direction from the UI language, so
/// layout mirrors by itself; an <see cref="Icon"/> mirrors with it only when its glyph is directional
/// (<see cref="IconData.IsDirectional"/>). <see cref="IsDirectionalProperty"/> overrides that per subtree, e.g. a
/// play triangle used as a "next" arrow (true) or a chevron that points along a left-to-right time axis (false).
/// Media, charts, numbers, paths and templates are left-to-right islands: set <c>FlowDirection="LeftToRight"</c>
/// on the smallest element that holds them, and a directional icon inside an island keeps its drawn orientation.
/// </summary>
public static class Bidi
{
/// <summary>Inherited override of <see cref="IconData.IsDirectional"/>; null keeps each glyph's own flag.</summary>
public static readonly DependencyProperty IsDirectionalProperty = DependencyProperty.RegisterAttached(
"IsDirectional", typeof(bool?), typeof(Bidi), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.Inherits, OnIsDirectionalChanged));
public static bool? GetIsDirectional(DependencyObject d) => (bool?)d.GetValue(IsDirectionalProperty);
public static void SetIsDirectional(DependencyObject d, bool? value) => d.SetValue(IsDirectionalProperty, value);
/// <summary>The flow direction of the current UI language.</summary>
public static FlowDirection UiDirection => Core.Localization.Loc.IsRightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
private static void OnIsDirectionalChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is Icon icon) icon.UpdateDirection();
}
}
+4 -1
View File
@@ -4,7 +4,7 @@ using Titano.Core.Branding;
namespace Titano.Ui.Controls;
/// <summary>The Titano mark drawn as vectors from <see cref="BrandMark"/> geometry (plate optional).</summary>
/// <summary>The Titano mark drawn as vectors from <see cref="BrandMark"/> geometry (plate optional); it never mirrors.</summary>
public sealed class BrandMarkIcon : FrameworkElement
{
public static readonly DependencyProperty ShowPlateProperty = DependencyProperty.Register(
@@ -14,6 +14,9 @@ public sealed class BrandMarkIcon : FrameworkElement
private static readonly Brush Sun = Frozen(new SolidColorBrush(Color.FromRgb(BrandMark.Sun.R, BrandMark.Sun.G, BrandMark.Sun.B)));
private static readonly Brush Plate = Frozen(new SolidColorBrush(Color.FromRgb(BrandMark.Plate.R, BrandMark.Plate.G, BrandMark.Plate.B)));
// A logo keeps its orientation in right-to-left layouts: the sun stays north-east, the ticks clockwise.
public BrandMarkIcon() => FlowDirection = FlowDirection.LeftToRight;
public bool ShowPlate
{
get => (bool)GetValue(ShowPlateProperty);
+18 -2
View File
@@ -4,12 +4,16 @@ using System.Windows.Media;
namespace Titano.Ui.Controls;
/// <summary>Renders an <see cref="IconData"/> on the 16-unit grid, scaled to the element size, in the inherited foreground.</summary>
/// <summary>
/// Renders an <see cref="IconData"/> on the 16-unit grid, scaled to the element size, in the inherited foreground,
/// centred in its slot. Only directional glyphs follow a right-to-left layout (<see cref="Bidi"/>); the others keep
/// their drawn orientation.
/// </summary>
public sealed class Icon : FrameworkElement
{
public static readonly DependencyProperty GlyphProperty = DependencyProperty.Register(
nameof(Glyph), typeof(IconData), typeof(Icon),
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender, (d, _) => ((Icon)d).UpdateDirection()));
public static readonly DependencyProperty ForegroundProperty = TextElement.ForegroundProperty.AddOwner(
typeof(Icon), new FrameworkPropertyMetadata(Brushes.Gray, FrameworkPropertyMetadataOptions.Inherits | FrameworkPropertyMetadataOptions.AffectsRender));
@@ -26,8 +30,13 @@ public sealed class Icon : FrameworkElement
{
SnapsToDevicePixelsProperty.OverrideMetadata(typeof(Icon), new FrameworkPropertyMetadata(true));
FocusableProperty.OverrideMetadata(typeof(Icon), new FrameworkPropertyMetadata(false));
// The glyph is drawn from the top-left of the element: a stretched slot would pull it off centre.
HorizontalAlignmentProperty.OverrideMetadata(typeof(Icon), new FrameworkPropertyMetadata(HorizontalAlignment.Center));
VerticalAlignmentProperty.OverrideMetadata(typeof(Icon), new FrameworkPropertyMetadata(VerticalAlignment.Center));
}
public Icon() => UpdateDirection();
public IconData? Glyph
{
get => (IconData?)GetValue(GlyphProperty);
@@ -56,6 +65,13 @@ public sealed class Icon : FrameworkElement
protected override Size MeasureOverride(Size availableSize) => new(Size, Size);
/// <summary>A directional glyph inherits the layout direction (and mirrors with it); any other glyph is pinned left-to-right.</summary>
internal void UpdateDirection()
{
if (Bidi.GetIsDirectional(this) ?? Glyph?.IsDirectional ?? false) ClearValue(FlowDirectionProperty);
else SetValue(FlowDirectionProperty, FlowDirection.LeftToRight);
}
protected override void OnRender(DrawingContext dc)
{
var glyph = Glyph;
+6
View File
@@ -22,6 +22,12 @@ public sealed class IconData
set => _fill = Freeze(value);
}
/// <summary>
/// The glyph points along the reading direction (back/forward arrows, chevrons, start-aligned lines), so it
/// mirrors in right-to-left layouts (DESIGN §5); every other glyph keeps its drawn orientation.
/// </summary>
public bool IsDirectional { get; set; }
private static Geometry? Freeze(Geometry? g)
{
if (g is { CanFreeze: true, IsFrozen: false }) g.Freeze();
+4
View File
@@ -13,6 +13,7 @@ public class JobBar : Control
public static readonly DependencyProperty IsActiveProperty = DependencyProperty.Register(nameof(IsActive), typeof(bool), typeof(JobBar));
public static readonly DependencyProperty StopCommandProperty = DependencyProperty.Register(nameof(StopCommand), typeof(ICommand), typeof(JobBar));
public static readonly DependencyProperty StopToolTipProperty = DependencyProperty.Register(nameof(StopToolTip), typeof(object), typeof(JobBar));
public static readonly DependencyProperty StopNameProperty = DependencyProperty.Register(nameof(StopName), typeof(string), typeof(JobBar));
public static readonly DependencyProperty ActionGlyphProperty = DependencyProperty.Register(nameof(ActionGlyph), typeof(IconData), typeof(JobBar));
static JobBar()
@@ -33,6 +34,9 @@ public class JobBar : Control
public ICommand? StopCommand { get => (ICommand?)GetValue(StopCommandProperty); set => SetValue(StopCommandProperty, value); }
public object? StopToolTip { get => GetValue(StopToolTipProperty); set => SetValue(StopToolTipProperty, value); }
/// <summary>Short accessible name of the stop (or pause) button; the tooltip sentence becomes its help text.</summary>
public string? StopName { get => (string?)GetValue(StopNameProperty); set => SetValue(StopNameProperty, value); }
/// <summary>Glyph of the action button: stop by default; the client shows pause (DESIGN §4 job bar).</summary>
public IconData? ActionGlyph { get => (IconData?)GetValue(ActionGlyphProperty); set => SetValue(ActionGlyphProperty, value); }
}
+14 -1
View File
@@ -4,6 +4,7 @@ using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Shell;
using Titano.Core.Localization;
using Titano.Ui.Interop;
using Titano.Ui.Theming;
@@ -12,7 +13,8 @@ namespace Titano.Ui.Controls;
/// <summary>
/// Window with Titano's custom chrome: 34-px title bar in the Chrome colour, brand mark, title, optional
/// title-bar content and drawn caption buttons. The maximise button answers HTMAXBUTTON so Windows 11
/// snap layouts appear on hover.
/// snap layouts appear on hover. The window lays out in the direction of the UI language from its creation on and
/// follows every language switch while it is shown (BRIEF §16).
/// </summary>
[TemplatePart(Name = PartMaximize, Type = typeof(Button))]
public class TitanoWindow : Window
@@ -54,6 +56,7 @@ public class TitanoWindow : Window
CommandBindings.Add(new CommandBinding(SystemCommands.RestoreWindowCommand, (_, _) => ToggleMaximize()));
UseLayoutRounding = true;
TextOptions.SetTextFormattingMode(this, TextFormattingMode.Display);
FlowDirection = Bidi.UiDirection;
}
/// <summary>Extra content placed in the title bar between the title and the caption buttons.</summary>
@@ -88,8 +91,18 @@ public class TitanoWindow : Window
base.OnSourceInitialized(e);
ThemeManager.ApplyChrome(this);
if (PresentationSource.FromVisual(this) is HwndSource source) source.AddHook(WndProc);
// Subscribed only while shown: the static event must not keep a closed (or never shown) window alive.
Loc.CultureChanged += OnCultureChanged;
}
protected override void OnClosed(EventArgs e)
{
Loc.CultureChanged -= OnCultureChanged;
base.OnClosed(e);
}
private void OnCultureChanged(object? sender, EventArgs e) => FlowDirection = Bidi.UiDirection;
private void ToggleMaximize()
{
if (WindowState == WindowState.Maximized) SystemCommands.RestoreWindow(this);
+75 -14
View File
@@ -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");
}
}
+8 -8
View File
@@ -6,7 +6,7 @@
<ui:IconData x:Key="Icon.ActualSize" Stroke="M3.0 2.5 H13.0 A1.5 1.5 0 0 1 14.5 4.0 V12.0 A1.5 1.5 0 0 1 13.0 13.5 H3.0 A1.5 1.5 0 0 1 1.5 12.0 V4.0 A1.5 1.5 0 0 1 3.0 2.5 Z M5 6 L6 5.5 V10.5 M9.5 6 L10.5 5.5 V10.5 M8 7 V7.1 M8 9.5 V9.6" />
<ui:IconData x:Key="Icon.Analyse" Stroke="M1.5 8.5 H4.5 L6.5 3.5 L9.5 12.5 L11.5 8.5 H14.5" />
<ui:IconData x:Key="Icon.Archive" Stroke="M2 4.5 H14 V13.5 H2 Z M2 2 H14 V4.5 H2 Z M6 8 H10" />
<ui:IconData x:Key="Icon.Back" Stroke="M13 8 H3 M7 4 L3 8 L7 12" />
<ui:IconData x:Key="Icon.Back" Stroke="M13 8 H3 M7 4 L3 8 L7 12" IsDirectional="True" />
<ui:IconData x:Key="Icon.Calendar" Stroke="M3.0 3 H13.0 A1.5 1.5 0 0 1 14.5 4.5 V13.0 A1.5 1.5 0 0 1 13.0 14.5 H3.0 A1.5 1.5 0 0 1 1.5 13.0 V4.5 A1.5 1.5 0 0 1 3.0 3 Z M1.5 6.5 H14.5 M5 1.5 V4 M11 1.5 V4" />
<ui:IconData x:Key="Icon.Camera" Stroke="M1.5 5 A1 1 0 0 1 2.5 4 H4.5 L6 2.5 H10 L11.5 4 H13.5 A1 1 0 0 1 14.5 5 V12.5 A1 1 0 0 1 13.5 13.5 H2.5 A1 1 0 0 1 1.5 12.5 Z M5.2 8.5 A2.8 2.8 0 1 0 10.8 8.5 A2.8 2.8 0 1 0 5.2 8.5 Z" />
<ui:IconData x:Key="Icon.Cancel" Stroke="M1.5 8 A6.5 6.5 0 1 0 14.5 8 A6.5 6.5 0 1 0 1.5 8 Z M5.8 5.8 L10.2 10.2 M10.2 5.8 L5.8 10.2" />
@@ -14,8 +14,8 @@
<ui:IconData x:Key="Icon.Chart" Stroke="M2 2 V14 H14 M4.5 10.5 L7.5 7 L9.5 9 L13.5 4" />
<ui:IconData x:Key="Icon.Check" Stroke="M3 8.5 L6.5 12 L13 4.5" />
<ui:IconData x:Key="Icon.ChevronDown" Stroke="M4 6 L8 10 L12 6" />
<ui:IconData x:Key="Icon.ChevronLeft" Stroke="M10 4 L6 8 L10 12" />
<ui:IconData x:Key="Icon.ChevronRight" Stroke="M6 4 L10 8 L6 12" />
<ui:IconData x:Key="Icon.ChevronLeft" Stroke="M10 4 L6 8 L10 12" IsDirectional="True" />
<ui:IconData x:Key="Icon.ChevronRight" Stroke="M6 4 L10 8 L6 12" IsDirectional="True" />
<ui:IconData x:Key="Icon.ChevronUp" Stroke="M4 10 L8 6 L12 10" />
<ui:IconData x:Key="Icon.Clipboard" Stroke="M4.0 2.5 H12.0 A1.5 1.5 0 0 1 13.5 4.0 V13.0 A1.5 1.5 0 0 1 12.0 14.5 H4.0 A1.5 1.5 0 0 1 2.5 13.0 V4.0 A1.5 1.5 0 0 1 4.0 2.5 Z M6.3 1.5 H9.7 A0.8 0.8 0 0 1 10.5 2.3 V3.2 A0.8 0.8 0 0 1 9.7 4.0 H6.3 A0.8 0.8 0 0 1 5.5 3.2 V2.3 A0.8 0.8 0 0 1 6.3 1.5 Z" />
<ui:IconData x:Key="Icon.Clock" Stroke="M1.5 8 A6.5 6.5 0 1 0 14.5 8 A6.5 6.5 0 1 0 1.5 8 Z M8 4.5 V8 L10.5 9.5" />
@@ -35,13 +35,13 @@
<ui:IconData x:Key="Icon.Exclude" Stroke="M1.5 8 A6.5 6.5 0 1 0 14.5 8 A6.5 6.5 0 1 0 1.5 8 Z M3.4 12.6 L12.6 3.4" />
<ui:IconData x:Key="Icon.Export" Stroke="M8 10 V1.8 M4.8 5 L8 1.8 L11.2 5 M5 7.5 H3 A1 1 0 0 0 2 8.5 V13.5 A1 1 0 0 0 3 14.5 H13 A1 1 0 0 0 14 13.5 V8.5 A1 1 0 0 0 13 7.5 H11" />
<ui:IconData x:Key="Icon.Exposure" Stroke="M1.5 8 A6.5 6.5 0 1 0 14.5 8 A6.5 6.5 0 1 0 1.5 8 Z M3.4 12.6 L12.6 3.4 M4.5 6 H7 M5.75 4.75 V7.25 M9 10 H11.5" />
<ui:IconData x:Key="Icon.ExternalLink" Stroke="M9.5 2 H14 V6.5 M14 2 L7.5 8.5 M12 9.5 V13 A1 1 0 0 1 11 14 H3 A1 1 0 0 1 2 13 V5 A1 1 0 0 1 3 4 H6.5" />
<ui:IconData x:Key="Icon.ExternalLink" Stroke="M9.5 2 H14 V6.5 M14 2 L7.5 8.5 M12 9.5 V13 A1 1 0 0 1 11 14 H3 A1 1 0 0 1 2 13 V5 A1 1 0 0 1 3 4 H6.5" IsDirectional="True" />
<ui:IconData x:Key="Icon.Eye" Stroke="M1.5 8 C3.5 4 12.5 4 14.5 8 C12.5 12 3.5 12 1.5 8 Z M5.8 8 A2.2 2.2 0 1 0 10.2 8 A2.2 2.2 0 1 0 5.8 8 Z" />
<ui:IconData x:Key="Icon.Filmstrip" Stroke="M3.0 2.5 H13.0 A1.5 1.5 0 0 1 14.5 4.0 V12.0 A1.5 1.5 0 0 1 13.0 13.5 H3.0 A1.5 1.5 0 0 1 1.5 12.0 V4.0 A1.5 1.5 0 0 1 3.0 2.5 Z M4.5 2.5 V13.5 M11.5 2.5 V13.5 M1.5 6 H4.5 M1.5 10 H4.5 M11.5 6 H14.5 M11.5 10 H14.5" />
<ui:IconData x:Key="Icon.Filter" Stroke="M1.5 2.5 H14.5 L9.5 8.5 V13.5 L6.5 12 V8.5 Z" />
<ui:IconData x:Key="Icon.Folder" Stroke="M1.5 4 A1 1 0 0 1 2.5 3 H6 L7.5 4.5 H13.5 A1 1 0 0 1 14.5 5.5 V12.5 A1 1 0 0 1 13.5 13.5 H2.5 A1 1 0 0 1 1.5 12.5 Z" />
<ui:IconData x:Key="Icon.FolderOpen" Stroke="M1.5 12.5 V4 A1 1 0 0 1 2.5 3 H6 L7.5 4.5 H12.5 V6.5 M1.5 12.5 L3.5 7 H14.5 L12.5 13.5 H2.5 A1 1 0 0 1 1.5 12.5 Z" />
<ui:IconData x:Key="Icon.Forward" Stroke="M3 8 H13 M9 4 L13 8 L9 12" />
<ui:IconData x:Key="Icon.Forward" Stroke="M3 8 H13 M9 4 L13 8 L9 12" IsDirectional="True" />
<ui:IconData x:Key="Icon.Fullscreen" Stroke="M2 6 V2 H6 M10 2 H14 V6 M14 10 V14 H10 M6 14 H2 V10" />
<ui:IconData x:Key="Icon.Gpu" Stroke="M5.0 3.5 H11.0 A1.5 1.5 0 0 1 12.5 5.0 V11.0 A1.5 1.5 0 0 1 11.0 12.5 H5.0 A1.5 1.5 0 0 1 3.5 11.0 V5.0 A1.5 1.5 0 0 1 5.0 3.5 Z M6.5 6 H9.5 A0.5 0.5 0 0 1 10 6.5 V9.5 A0.5 0.5 0 0 1 9.5 10 H6.5 A0.5 0.5 0 0 1 6 9.5 V6.5 A0.5 0.5 0 0 1 6.5 6 Z M6 1.5 V3.5 M10 1.5 V3.5 M6 12.5 V14.5 M10 12.5 V14.5 M1.5 6 H3.5 M1.5 10 H3.5 M12.5 6 H14.5 M12.5 10 H14.5" />
<ui:IconData x:Key="Icon.Grip" Fill="M5 4 A1 1 0 1 0 7 4 A1 1 0 1 0 5 4 ZM9 4 A1 1 0 1 0 11 4 A1 1 0 1 0 9 4 ZM5 8 A1 1 0 1 0 7 8 A1 1 0 1 0 5 8 ZM9 8 A1 1 0 1 0 11 8 A1 1 0 1 0 9 8 ZM5 12 A1 1 0 1 0 7 12 A1 1 0 1 0 5 12 ZM9 12 A1 1 0 1 0 11 12 A1 1 0 1 0 9 12 Z" />
@@ -50,14 +50,14 @@
<ui:IconData x:Key="Icon.Image" Stroke="M3.0 2.5 H13.0 A1.5 1.5 0 0 1 14.5 4.0 V12.0 A1.5 1.5 0 0 1 13.0 13.5 H3.0 A1.5 1.5 0 0 1 1.5 12.0 V4.0 A1.5 1.5 0 0 1 3.0 2.5 Z M1.5 11 L5.5 7 L9 10.5 L11 8.5 L14.5 12" Fill="M9.600000000000001 5.6 A1.2 1.2 0 1 0 12.0 5.6 A1.2 1.2 0 1 0 9.600000000000001 5.6 Z" />
<ui:IconData x:Key="Icon.Import" Stroke="M8 2V10 M4.5 6.5 L8 10 L11.5 6.5 M2.5 13.5 H13.5" />
<ui:IconData x:Key="Icon.Info" Stroke="M1.5 8 A6.5 6.5 0 1 0 14.5 8 A6.5 6.5 0 1 0 1.5 8 Z M8 7 V11 M8 4.8 V5.2" />
<ui:IconData x:Key="Icon.Jobs" Stroke="M3 8 H13 M3 4 H13 M3 12 H9" />
<ui:IconData x:Key="Icon.Jobs" Stroke="M3 8 H13 M3 4 H13 M3 12 H9" IsDirectional="True" />
<ui:IconData x:Key="Icon.Key" Stroke="M2 10.5 A3 3 0 1 0 8 10.5 A3 3 0 1 0 2 10.5 Z M7.2 8.3 L13.5 2 M11.5 4 L13 5.5 M9.8 5.7 L11 6.9" />
<ui:IconData x:Key="Icon.Keyframe" Stroke="M8 2 L13 8 L8 14 L3 8 Z" />
<ui:IconData x:Key="Icon.Layers" Stroke="M8 1.8 L14.5 5.2 L8 8.6 L1.5 5.2 Z M1.5 8.2 L8 11.6 L14.5 8.2 M1.5 11 L8 14.4 L14.5 11" />
<ui:IconData x:Key="Icon.Library" Stroke="M2.5 1.5 H6.0 A1 1 0 0 1 7.0 2.5 V6.0 A1 1 0 0 1 6.0 7.0 H2.5 A1 1 0 0 1 1.5 6.0 V2.5 A1 1 0 0 1 2.5 1.5 ZM10 1.5 H13.5 A1 1 0 0 1 14.5 2.5 V6.0 A1 1 0 0 1 13.5 7.0 H10 A1 1 0 0 1 9 6.0 V2.5 A1 1 0 0 1 10 1.5 ZM2.5 9 H6.0 A1 1 0 0 1 7.0 10 V13.5 A1 1 0 0 1 6.0 14.5 H2.5 A1 1 0 0 1 1.5 13.5 V10 A1 1 0 0 1 2.5 9 ZM10 9 H13.5 A1 1 0 0 1 14.5 10 V13.5 A1 1 0 0 1 13.5 14.5 H10 A1 1 0 0 1 9 13.5 V10 A1 1 0 0 1 10 9 Z" />
<ui:IconData x:Key="Icon.Link" Stroke="M6.8 9.2 L9.2 6.8 M7.5 4.5 L9 3 A2.8 2.8 0 0 1 13 7 L11.5 8.5 M8.5 11.5 L7 13 A2.8 2.8 0 0 1 3 9 L4.5 7.5" />
<ui:IconData x:Key="Icon.Lock" Stroke="M4.5 7 H11.5 A1.5 1.5 0 0 1 13 8.5 V13.0 A1.5 1.5 0 0 1 11.5 14.5 H4.5 A1.5 1.5 0 0 1 3 13.0 V8.5 A1.5 1.5 0 0 1 4.5 7 Z M5.5 7 V5 A2.5 2.5 0 0 1 10.5 5 V7" />
<ui:IconData x:Key="Icon.Logs" Stroke="M3.5 1.5 H9.5 L12.5 4.5 V14.5 H3.5 Z M5.5 7 H10.5 M5.5 9.5 H10.5 M5.5 12 H8.5" />
<ui:IconData x:Key="Icon.Logs" Stroke="M3.5 1.5 H9.5 L12.5 4.5 V14.5 H3.5 Z M5.5 7 H10.5 M5.5 9.5 H10.5 M5.5 12 H8.5" IsDirectional="True" />
<ui:IconData x:Key="Icon.Menu" Stroke="M2.5 4 H13.5 M2.5 8 H13.5 M2.5 12 H13.5" />
<ui:IconData x:Key="Icon.Minus" Stroke="M3 8 H13" />
<ui:IconData x:Key="Icon.Moon" Stroke="M9.5 1.8 A6.5 6.5 0 1 0 14.2 11.2 A5.5 5.5 0 0 1 9.5 1.8 Z" />
@@ -99,7 +99,7 @@
<ui:IconData x:Key="Icon.Vectors" Stroke="M2.5 12.5 L7 8 M7 8 H4.5 M7 8 V10.5 M9 7 L13.5 2.5 M13.5 2.5 H11 M13.5 2.5 V5" />
<ui:IconData x:Key="Icon.Verify" Stroke="M8 1.5 L13.5 3.5 V7.5 C13.5 11 11 13.3 8 14.5 C5 13.3 2.5 11 2.5 7.5 V3.5 Z M5.5 8 L7.3 9.8 L10.6 6.3" />
<ui:IconData x:Key="Icon.ViewGrid" Stroke="M2.5 1.5 H6.0 A1 1 0 0 1 7.0 2.5 V6.0 A1 1 0 0 1 6.0 7.0 H2.5 A1 1 0 0 1 1.5 6.0 V2.5 A1 1 0 0 1 2.5 1.5 ZM10 1.5 H13.5 A1 1 0 0 1 14.5 2.5 V6.0 A1 1 0 0 1 13.5 7.0 H10 A1 1 0 0 1 9 6.0 V2.5 A1 1 0 0 1 10 1.5 ZM2.5 9 H6.0 A1 1 0 0 1 7.0 10 V13.5 A1 1 0 0 1 6.0 14.5 H2.5 A1 1 0 0 1 1.5 13.5 V10 A1 1 0 0 1 2.5 9 ZM10 9 H13.5 A1 1 0 0 1 14.5 10 V13.5 A1 1 0 0 1 13.5 14.5 H10 A1 1 0 0 1 9 13.5 V10 A1 1 0 0 1 10 9 Z" />
<ui:IconData x:Key="Icon.ViewList" Stroke="M5.5 4 H13.5 M5.5 8 H13.5 M5.5 12 H13.5 M2.5 4 H2.6 M2.5 8 H2.6 M2.5 12 H2.6" />
<ui:IconData x:Key="Icon.ViewList" Stroke="M5.5 4 H13.5 M5.5 8 H13.5 M5.5 12 H13.5 M2.5 4 H2.6 M2.5 8 H2.6 M2.5 12 H2.6" IsDirectional="True" />
<ui:IconData x:Key="Icon.ViewTimeline" Stroke="M2 13.5 H14 M3.5 11 V8 M6 11 V5 M8.5 11 V7 M11 11 V3.5 M13.5 11 V9" />
<ui:IconData x:Key="Icon.Warning" Stroke="M8 1.8 L14.8 13.8 H1.2 Z M8 6.2 V9.6 M8 11.7 V11.8" />
<ui:IconData x:Key="Icon.Window" Stroke="M3.0 2.5 H13.0 A1.5 1.5 0 0 1 14.5 4.0 V12.0 A1.5 1.5 0 0 1 13.0 13.5 H3.0 A1.5 1.5 0 0 1 1.5 12.0 V4.0 A1.5 1.5 0 0 1 3.0 2.5 Z M1.5 5.5 H14.5" />
+93 -31
View File
@@ -25,6 +25,17 @@
</Setter>
</Style>
<!-- Focus inside the bounds, for list rows and table rows whose neighbours or scroll viewport would hide an outer ring. -->
<Style x:Key="Focus.Inset">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Border BorderBrush="{DynamicResource Brush.Accent}" BorderThickness="2" CornerRadius="{StaticResource Radius.Control}" SnapsToDevicePixels="True" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<DropShadowEffect x:Key="Shadow.Popup" BlurRadius="24" ShadowDepth="6" Direction="270" Opacity="0.45" Color="Black" />
<DropShadowEffect x:Key="Shadow.ToolTip" BlurRadius="14" ShadowDepth="4" Direction="270" Opacity="0.4" Color="Black" />
@@ -256,8 +267,14 @@
</Setter>
</Style>
<!-- Naming templates ({year}/{date}_{n:0000}) and paths keep their characters in order in right-to-left languages. -->
<Style x:Key="TextBox.Mono" TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="FontFamily" Value="{StaticResource Font.Mono}" />
<Setter Property="FlowDirection" Value="LeftToRight" />
</Style>
<Style x:Key="TextBox.Path" TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="FlowDirection" Value="LeftToRight" />
</Style>
<Style TargetType="PasswordBox" BasedOn="{StaticResource Input.Base}">
@@ -295,7 +312,7 @@
<Setter.Value>
<ControlTemplate TargetType="ToggleButton">
<Border Background="Transparent">
<ui:Icon Glyph="{StaticResource Icon.ChevronDown}" Size="14" HorizontalAlignment="Right" Margin="0,0,10,0"
<ui:Icon Glyph="{StaticResource Icon.ChevronDown}" Size="14" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,10,0"
Foreground="{DynamicResource Brush.TextMuted}" />
</Border>
</ControlTemplate>
@@ -737,7 +754,7 @@
</Style>
<Style TargetType="ListBoxItem">
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="FocusVisualStyle" Value="{StaticResource Focus.Inset}" />
<Setter Property="Foreground" Value="{DynamicResource Brush.Text}" />
<Setter Property="MinHeight" Value="36" />
<Setter Property="Padding" Value="10,0" />
@@ -800,7 +817,7 @@
</Style>
<Style TargetType="ListViewItem">
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="FocusVisualStyle" Value="{StaticResource Focus.Inset}" />
<Setter Property="Foreground" Value="{DynamicResource Brush.Text}" />
<Setter Property="Height" Value="{StaticResource Height.Row}" />
<Setter Property="VerticalContentAlignment" Value="Center" />
@@ -1050,11 +1067,11 @@
<DockPanel LastChildFill="True">
<StackPanel DockPanel.Dock="Right" Orientation="Horizontal">
<Button x:Name="Minimize" Style="{StaticResource Caption.Button}" ui:ButtonIcon.Glyph="{StaticResource Icon.Caption.Minimize}"
Command="{x:Static SystemCommands.MinimizeWindowCommand}" AutomationProperties.Name="Minimize" ToolTip="{l:Loc Tooltips.Window.Minimize}" />
Command="{x:Static SystemCommands.MinimizeWindowCommand}" AutomationProperties.Name="{l:Loc Tooltips.Window.Minimize}" ToolTip="{l:Loc Tooltips.Window.Minimize}" />
<Button x:Name="PART_Maximize" Style="{StaticResource Caption.Button}" ui:ButtonIcon.Glyph="{StaticResource Icon.Caption.Maximize}"
Command="{x:Static SystemCommands.MaximizeWindowCommand}" AutomationProperties.Name="Maximize" ToolTip="{l:Loc Tooltips.Window.Maximize}" />
Command="{x:Static SystemCommands.MaximizeWindowCommand}" AutomationProperties.Name="{l:Loc Tooltips.Window.Maximize}" ToolTip="{l:Loc Tooltips.Window.Maximize}" />
<Button x:Name="Close" Style="{StaticResource Caption.Close}" ui:ButtonIcon.Glyph="{StaticResource Icon.Caption.Close}"
Command="{x:Static SystemCommands.CloseWindowCommand}" AutomationProperties.Name="Close" ToolTip="{l:Loc Tooltips.Window.Close}" />
Command="{x:Static SystemCommands.CloseWindowCommand}" AutomationProperties.Name="{l:Loc Tooltips.Window.Close}" ToolTip="{l:Loc Tooltips.Window.Close}" />
</StackPanel>
<ui:BrandMarkIcon Width="16" Height="16" Margin="12,0,10,0" VerticalAlignment="Center" />
<TextBlock Text="{TemplateBinding Title}" Foreground="{DynamicResource Brush.TextMuted}" FontSize="{StaticResource Size.Secondary}"
@@ -1072,6 +1089,7 @@
<Setter TargetName="Root" Property="Padding" Value="{x:Static SystemParameters.WindowResizeBorderThickness}" />
<Setter TargetName="PART_Maximize" Property="ui:ButtonIcon.Glyph" Value="{StaticResource Icon.Caption.Restore}" />
<Setter TargetName="PART_Maximize" Property="ToolTip" Value="{l:Loc Tooltips.Window.Restore}" />
<Setter TargetName="PART_Maximize" Property="AutomationProperties.Name" Value="{l:Loc Tooltips.Window.Restore}" />
</Trigger>
<Trigger Property="IsMaximizeHovered" Value="True">
<Setter TargetName="PART_Maximize" Property="Background" Value="{DynamicResource Brush.Card}" />
@@ -1106,7 +1124,7 @@
<Border x:Name="Bd" Background="Transparent" CornerRadius="{StaticResource Radius.Control}" SnapsToDevicePixels="True">
<Grid>
<Border x:Name="Edge" Width="3" HorizontalAlignment="Left" CornerRadius="1.5" Margin="0,8" Background="{DynamicResource Brush.Accent}" Visibility="Hidden" />
<Grid Margin="10,0,8,0">
<Grid x:Name="Row" Margin="10,0,8,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
@@ -1116,8 +1134,9 @@
<TextBlock x:Name="Label" Grid.Column="1" Margin="10,0,0,0" VerticalAlignment="Center" TextTrimming="CharacterEllipsis">
<ContentPresenter RecognizesAccessKey="True" />
</TextBlock>
<Border x:Name="Badge" Grid.Column="2" MinWidth="18" Height="16" CornerRadius="8" Padding="5,0" Background="{DynamicResource Brush.Accent}" VerticalAlignment="Center">
<TextBlock Text="{Binding Badge, RelativeSource={RelativeSource TemplatedParent}}" FontSize="10" FontWeight="SemiBold" Foreground="{DynamicResource Brush.OnAccent}" HorizontalAlignment="Center" VerticalAlignment="Center" />
<Border x:Name="Badge" Grid.Column="2" MinWidth="18" Height="16" CornerRadius="8" Padding="5,0" Margin="6,0,0,0" Background="{DynamicResource Brush.Accent}" VerticalAlignment="Center">
<TextBlock Text="{Binding Badge, RelativeSource={RelativeSource TemplatedParent}}" FontSize="{StaticResource Size.Chip}" FontWeight="SemiBold" Foreground="{DynamicResource Brush.OnAccent}"
HorizontalAlignment="Center" VerticalAlignment="Center" Typography.NumeralAlignment="Tabular" />
</Border>
</Grid>
</Grid>
@@ -1126,12 +1145,15 @@
<Trigger Property="Badge" Value="0">
<Setter TargetName="Badge" Property="Visibility" Value="Collapsed" />
</Trigger>
<!-- 32 px button: the 16 px icon centred; the badge hangs off the icon's top-right corner (the negative margin
keeps it from widening the icon column) and covers only that corner. -->
<Trigger Property="ui:NavRail.IsCollapsed" Value="True">
<Setter TargetName="Label" Property="Visibility" Value="Collapsed" />
<Setter TargetName="Badge" Property="HorizontalAlignment" Value="Right" />
<Setter TargetName="Badge" Property="VerticalAlignment" Value="Top" />
<Setter TargetName="Badge" Property="Margin" Value="-14,4,0,0" />
<Setter TargetName="Row" Property="Margin" Value="8,0" />
<Setter TargetName="Badge" Property="Grid.Column" Value="0" />
<Setter TargetName="Badge" Property="HorizontalAlignment" Value="Left" />
<Setter TargetName="Badge" Property="VerticalAlignment" Value="Top" />
<Setter TargetName="Badge" Property="Margin" Value="8,2,-24,0" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource Brush.Card}" />
@@ -1149,6 +1171,21 @@
</Style>
<!-- ===================== AutoSlider (advisor Auto / manual) ===================== -->
<!-- "Auto · 8" pill (DESIGN §4 Auto/manual): accent outline, 24 px, 11 px text; its tooltip gives the advisor's reason. -->
<Style x:Key="Button.AutoPill" TargetType="Button" BasedOn="{StaticResource Button.Base}">
<Setter Property="Height" Value="24" />
<Setter Property="MinWidth" Value="0" />
<Setter Property="Padding" Value="8,0" />
<Setter Property="FontSize" Value="{StaticResource Size.Chip}" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="{DynamicResource Brush.Accent}" />
<Setter Property="Foreground" Value="{DynamicResource Brush.Accent}" />
<Setter Property="ui:ControlState.CornerRadius" Value="12" />
<Setter Property="ui:ControlState.HoverBackground" Value="{DynamicResource Brush.AccentSubtle}" />
<Setter Property="ui:ControlState.HoverBorderBrush" Value="{DynamicResource Brush.Accent}" />
<Setter Property="ui:ControlState.PressedBackground" Value="{DynamicResource Brush.AccentSubtle}" />
</Style>
<Style x:Key="Pill.Auto" TargetType="Border">
<Setter Property="Height" Value="22" />
<Setter Property="Padding" Value="8,0" />
@@ -1172,32 +1209,40 @@
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Text="{TemplateBinding Header}" VerticalAlignment="Center" TextTrimming="CharacterEllipsis" />
<Border x:Name="AutoPill" Grid.Column="1" Style="{StaticResource Pill.Auto}" ToolTip="{TemplateBinding AutoReason}" ToolTipService.ShowOnDisabled="True">
<TextBlock Text="{TemplateBinding AutoText}" FontSize="{StaticResource Size.Chip}" Foreground="{DynamicResource Brush.Accent}" VerticalAlignment="Center" />
</Border>
<Button x:Name="AutoPill" Grid.Column="1" Style="{StaticResource Button.AutoPill}" Content="{TemplateBinding AutoText}" ToolTip="{TemplateBinding AutoReason}"
AutomationProperties.Name="{Binding AutoText, RelativeSource={RelativeSource TemplatedParent}}"
AutomationProperties.HelpText="{Binding AutoReason, RelativeSource={RelativeSource TemplatedParent}}" />
<StackPanel x:Name="Manual" Grid.Column="1" Orientation="Horizontal" Visibility="Collapsed">
<TextBlock Text="{TemplateBinding DisplayValue}" VerticalAlignment="Center" Style="{StaticResource Text.Number}" />
<Button Style="{StaticResource Button.IconSubtle}" Width="26" Height="26" Margin="6,0,0,0" ui:ButtonIcon.Glyph="{StaticResource Icon.Reset}"
Command="{x:Static ui:AutoSlider.ResetCommand}" ToolTip="{l:Loc Tooltips.Common.ResetToAuto}" />
Command="{x:Static ui:AutoSlider.ResetCommand}" ToolTip="{l:Loc Tooltips.Common.ResetToAuto}" AutomationProperties.Name="{l:Loc Common.ResetToAuto}" />
</StackPanel>
<TextBlock x:Name="NotApplicable" Grid.Column="1" Text="{l:Loc Common.NotApplicable}" Foreground="{DynamicResource Brush.TextFaint}"
ToolTip="{TemplateBinding NotApplicableReason}" Visibility="Collapsed" VerticalAlignment="Center" />
</Grid>
<!-- The slider carries the setting's name; its status says Auto (with the advisor's reason) or not applicable. -->
<Slider x:Name="PART_Slider" Margin="0,6,0,0" Minimum="{TemplateBinding Minimum}" Maximum="{TemplateBinding Maximum}"
SmallChange="{TemplateBinding SmallChange}" LargeChange="{TemplateBinding SmallChange}" TickFrequency="{TemplateBinding TickFrequency}"
IsSnapToTickEnabled="{TemplateBinding IsSnapToTickEnabled}" ToolTip="{TemplateBinding SliderToolTip}" />
IsSnapToTickEnabled="{TemplateBinding IsSnapToTickEnabled}" ToolTip="{TemplateBinding SliderToolTip}"
AutomationProperties.Name="{Binding Header, RelativeSource={RelativeSource TemplatedParent}}"
AutomationProperties.ItemStatus="{Binding AutoText, RelativeSource={RelativeSource TemplatedParent}}"
AutomationProperties.HelpText="{Binding AutoReason, RelativeSource={RelativeSource TemplatedParent}}" />
</StackPanel>
<ControlTemplate.Triggers>
<Trigger Property="IsAuto" Value="False">
<Setter TargetName="AutoPill" Property="Visibility" Value="Collapsed" />
<Setter TargetName="Manual" Property="Visibility" Value="Visible" />
<Setter TargetName="PART_Slider" Property="ui:ControlState.Accent" Value="{DynamicResource Brush.Sun}" />
<Setter TargetName="PART_Slider" Property="AutomationProperties.ItemStatus" Value="" />
<Setter TargetName="PART_Slider" Property="AutomationProperties.HelpText" Value="" />
</Trigger>
<Trigger Property="IsApplicable" Value="False">
<Setter TargetName="AutoPill" Property="Visibility" Value="Collapsed" />
<Setter TargetName="Manual" Property="Visibility" Value="Collapsed" />
<Setter TargetName="NotApplicable" Property="Visibility" Value="Visible" />
<Setter TargetName="PART_Slider" Property="IsEnabled" Value="False" />
<Setter TargetName="PART_Slider" Property="AutomationProperties.ItemStatus" Value="{l:Loc Common.NotApplicable}" />
<Setter TargetName="PART_Slider" Property="AutomationProperties.HelpText" Value="{Binding NotApplicableReason, RelativeSource={RelativeSource TemplatedParent}}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
@@ -1221,7 +1266,7 @@
<ContentPresenter VerticalAlignment="Center" Margin="0,0,4,0" />
<Button x:Name="Remove" Style="{StaticResource Button.IconSubtle}" Width="18" Height="18" MinWidth="18" ui:ControlState.CornerRadius="9"
ui:ButtonIcon.Glyph="{StaticResource Icon.Close}" Command="{TemplateBinding RemoveCommand}" CommandParameter="{TemplateBinding RemoveCommandParameter}"
ToolTip="{TemplateBinding RemoveToolTip}" />
ToolTip="{TemplateBinding RemoveToolTip}" AutomationProperties.Name="{l:Loc Common.Remove}" />
</StackPanel>
</Border>
<ControlTemplate.Triggers>
@@ -1314,19 +1359,19 @@
<Setter.Value>
<ControlTemplate TargetType="ui:JobBar">
<Border Background="{DynamicResource Brush.Surface}" BorderBrush="{DynamicResource Brush.Stroke}" BorderThickness="0,0,0,1" Padding="20,0,12,0">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" MinWidth="120" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ProgressBar x:Name="Bar" VerticalAlignment="Center" Maximum="1" Value="{TemplateBinding Progress}" IsIndeterminate="{TemplateBinding IsIndeterminate}" />
<TextBlock Grid.Column="1" Text="{TemplateBinding Text}" Margin="12,0,12,0" VerticalAlignment="Center" FontSize="{StaticResource Size.Body}"
Typography.NumeralAlignment="Tabular" TextTrimming="CharacterEllipsis" MaxWidth="640" />
<Button x:Name="Stop" Grid.Column="2" Style="{StaticResource Button.Icon}" Width="28" Height="28" MinWidth="28"
<!-- The text takes what it needs and trims only once the bar is down to 120 px: the spacer reserves those
120 px before the text is measured, and the bar reaches back over it. -->
<DockPanel>
<Button x:Name="Stop" DockPanel.Dock="Right" Style="{StaticResource Button.Icon}" Width="28" Height="28" MinWidth="28"
ui:ButtonIcon.Glyph="{TemplateBinding ActionGlyph}" Command="{TemplateBinding StopCommand}" ToolTip="{TemplateBinding StopToolTip}"
AutomationProperties.Name="{Binding StopToolTip, RelativeSource={RelativeSource TemplatedParent}}" />
</Grid>
AutomationProperties.Name="{Binding StopName, RelativeSource={RelativeSource TemplatedParent}}"
AutomationProperties.HelpText="{Binding StopToolTip, RelativeSource={RelativeSource TemplatedParent}}" />
<FrameworkElement DockPanel.Dock="Left" Width="120" />
<TextBlock DockPanel.Dock="Right" Text="{TemplateBinding Text}" Margin="12,0,12,0" VerticalAlignment="Center" FontSize="{StaticResource Size.Body}"
Typography.NumeralAlignment="Tabular" TextTrimming="CharacterEllipsis" />
<ProgressBar x:Name="Bar" Margin="-120,0,0,0" VerticalAlignment="Center" Maximum="1" Value="{TemplateBinding Progress}" IsIndeterminate="{TemplateBinding IsIndeterminate}"
AutomationProperties.Name="{Binding Text, RelativeSource={RelativeSource TemplatedParent}}" />
</DockPanel>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsActive" Value="False">
@@ -1364,6 +1409,22 @@
<Setter Property="VerticalAlignment" Value="Bottom" />
<Setter Property="Margin" Value="0,0,20,44" />
<Setter Property="Focusable" Value="False" />
<!-- The host keys its own style, so no theme template applies: without this one nothing would draw. -->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ui:ToastHost">
<ItemsPresenter />
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="ItemContainerStyle">
<Setter.Value>
<Style TargetType="ContentPresenter">
<Setter Property="AutomationProperties.Name" Value="{Binding Title}" />
<Setter Property="AutomationProperties.HelpText" Value="{Binding Message}" />
</Style>
</Setter.Value>
</Setter>
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate DataType="{x:Type ui:Toast}">
@@ -1384,7 +1445,8 @@
<Button Grid.Column="1" Style="{StaticResource Button.Primary}" Margin="12,0,0,0" Content="{Binding ActionText}" Command="{Binding ActionCommand}"
ToolTip="{Binding ActionToolTip}" Visibility="{Binding ActionCommand, Converter={x:Static ui:NullToCollapsedConverter.Instance}}" />
<Button Grid.Column="2" Style="{StaticResource Button.IconSubtle}" Margin="4,0,0,0" ui:ButtonIcon.Glyph="{StaticResource Icon.Close}"
Command="{x:Static ui:ToastHost.DismissCommand}" CommandParameter="{Binding}" ToolTip="{l:Loc Tooltips.Common.Dismiss}" />
Command="{x:Static ui:ToastHost.DismissCommand}" CommandParameter="{Binding}" ToolTip="{l:Loc Tooltips.Common.DismissToast}"
AutomationProperties.Name="{l:Loc Tooltips.Common.Dismiss}" />
</Grid>
</Grid>
</Border>
+15 -8
View File
@@ -1,7 +1,8 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="clr-namespace:Titano.Ui.Controls"
xmlns:v="clr-namespace:Titano.Ui.Visuals">
xmlns:v="clr-namespace:Titano.Ui.Visuals"
xmlns:l="clr-namespace:Titano.Ui.Localization">
<!--
Styles of the high-performance visuals (Titano.Ui.Visuals), merged by Controls.xaml. Brushes and the shared
button templates of Controls.xaml are DynamicResource (they live in the parent dictionary); sizes, radii and
@@ -76,14 +77,17 @@
CornerRadius="{StaticResource Radius.Card}">
<StackPanel>
<v:AspectRatioDecorator>
<Grid x:Name="PART_Thumbnail" Background="Transparent">
<!-- The photo and the scrub position are a left-to-right island (time runs left to right, as in the
filmstrip); the check box, badge and quick actions follow the layout direction. -->
<Grid Background="Transparent">
<Border CornerRadius="7,7,0,0" Background="{DynamicResource Brush.Preview}" />
<Border CornerRadius="7,7,0,0">
<Border x:Name="PART_Thumbnail" CornerRadius="7,7,0,0" FlowDirection="LeftToRight">
<Border.Background>
<ImageBrush ImageSource="{Binding DisplayedThumbnail, RelativeSource={RelativeSource TemplatedParent}}" Stretch="UniformToFill" />
</Border.Background>
</Border>
<Border x:Name="ScrubTrack" Height="2" VerticalAlignment="Bottom" Background="{DynamicResource Brush.Accent}" RenderTransformOrigin="0,0.5" Visibility="Collapsed">
<Border x:Name="ScrubTrack" Height="2" VerticalAlignment="Bottom" Background="{DynamicResource Brush.Accent}" RenderTransformOrigin="0,0.5" Visibility="Collapsed"
FlowDirection="LeftToRight">
<Border.RenderTransform>
<ScaleTransform ScaleX="{Binding ScrubPosition, RelativeSource={RelativeSource TemplatedParent}}" />
</Border.RenderTransform>
@@ -146,13 +150,14 @@
</Style>
<!-- ===================== Preview viewport (BRIEF §12.3) ===================== -->
<!-- The image surface (a drawn visual, always left to right) and the numeric shot data stay left to right; the tool
row follows the layout direction. -->
<Style TargetType="v:PreviewViewport">
<Setter Property="Background" Value="{DynamicResource Brush.Preview}" />
<Setter Property="Foreground" Value="{DynamicResource Brush.Text}" />
<Setter Property="FontFamily" Value="{StaticResource Font.Ui}" />
<Setter Property="FontSize" Value="{StaticResource Size.Secondary}" />
<Setter Property="FlowDirection" Value="LeftToRight" />
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="FocusVisualStyle" Value="{DynamicResource Focus.Ring}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="v:PreviewViewport">
@@ -160,7 +165,7 @@
<Grid>
<v:PreviewSurface x:Name="PART_Surface" CornerRadius="8" />
<ContentPresenter x:Name="PART_Tools" Content="{TemplateBinding ToolsContent}" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="12" />
<Grid x:Name="PART_Info" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="12" IsHitTestVisible="False">
<Grid x:Name="PART_Info" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="12" IsHitTestVisible="False" FlowDirection="LeftToRight">
<Border Background="{DynamicResource Brush.Chrome}" Opacity="0.85" CornerRadius="{StaticResource Radius.Control}" />
<TextBlock Text="{TemplateBinding InfoText}" Margin="10,6" Typography.NumeralAlignment="Tabular" TextTrimming="CharacterEllipsis" />
</Grid>
@@ -270,6 +275,7 @@
<Style TargetType="v:SplitButton">
<Setter Property="Height" Value="{StaticResource Height.Control}" />
<Setter Property="DropDownName" Value="{l:Loc Common.MoreChoices}" />
<Setter Property="FontFamily" Value="{StaticResource Font.Ui}" />
<Setter Property="FontSize" Value="{StaticResource Size.Body}" />
<Setter Property="ToolTipService.ShowOnDisabled" Value="True" />
@@ -282,7 +288,8 @@
CommandTarget="{TemplateBinding CommandTarget}" />
<ToggleButton x:Name="Arrow" Style="{DynamicResource Button.Base}" Height="{TemplateBinding Height}" Width="28" MinWidth="28" Padding="0" Margin="-1,0,0,0"
ClickMode="Press" ui:ControlState.CornerRadius="0,6,6,0" ui:ButtonIcon.Glyph="{DynamicResource Icon.ChevronDown}"
IsChecked="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}" ToolTip="{TemplateBinding DropDownToolTip}" />
IsChecked="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}" ToolTip="{TemplateBinding DropDownToolTip}"
AutomationProperties.Name="{Binding DropDownName, RelativeSource={RelativeSource TemplatedParent}}" />
</StackPanel>
<ControlTemplate.Triggers>
<Trigger Property="IsPrimary" Value="True">
+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
@@ -119,8 +119,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);
@@ -132,8 +132,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);