diff --git a/branding/ui-icons/icons.py b/branding/ui-icons/icons.py index 51aa85d7..2ecc1973 100644 --- a/branding/ui-icons/icons.py +++ b/branding/ui-icons/icons.py @@ -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('\n') f.write('\n') diff --git a/i18n/en/Common.resx b/i18n/en/Common.resx index bcf09a3a..ffda1774 100644 --- a/i18n/en/Common.resx +++ b/i18n/en/Common.resx @@ -5,12 +5,19 @@ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Auto + Auto · {0}{0} advisor value + curvecontrol type read by screen readers, lower case + Point {0} of {1}: {2}{0} position; {1} point count; {2} coordinates (Common.CurveReadout) + {0} → {1}{0} horizontal value; {1} vertical value; right-to-left languages point the arrow left {0} d {1} h {0} h {1} m {0} min {0} s + More choices n/a Open Open logs {0} % + Remove + Back to Auto diff --git a/i18n/en/Tooltips.resx b/i18n/en/Tooltips.resx index 2601110d..51968922 100644 --- a/i18n/en/Tooltips.resx +++ b/i18n/en/Tooltips.resx @@ -87,6 +87,7 @@ Re-hash every original and report bit rot · reads the whole archive {0} · Right arrow opens the year, Left arrow closes it Dismiss + Close this notice · Esc Open the folder with the log files Return to the advisor's value Read every frame again and refresh the analysis · Ctrl+Shift+A diff --git a/i18n/it/Common.it.resx b/i18n/it/Common.it.resx index 8794e75b..f56189e6 100644 --- a/i18n/it/Common.it.resx +++ b/i18n/it/Common.it.resx @@ -5,12 +5,19 @@ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Auto + Auto · {0} + curva + Punto {0} di {1}: {2} + {0} → {1} {0} g {1} h {0} h {1} m {0} min {0} s + Altre scelte n/d Apri Apri log {0}% + Rimuovi + Torna ad Auto diff --git a/i18n/it/Tooltips.it.resx b/i18n/it/Tooltips.it.resx index 2d899232..c934142f 100644 --- a/i18n/it/Tooltips.it.resx +++ b/i18n/it/Tooltips.it.resx @@ -87,6 +87,7 @@ Ricalcola l'hash di ogni originale e segnala i danni · legge tutto l'archivio {0} · Freccia destra apre l'anno, freccia sinistra lo chiude Chiudi + Chiudi questo avviso · Esc Apri la cartella dei file di log Torna al valore consigliato Rilegge ogni fotogramma e aggiorna l’analisi · Ctrl+Maiusc+A diff --git a/src/Titano.Ui/Controls/AutoSlider.cs b/src/Titano.Ui/Controls/AutoSlider.cs index cc2a1bb1..08de005f 100644 --- a/src/Titano.Ui/Controls/AutoSlider.cs +++ b/src/Titano.Ui/Controls/AutoSlider.cs @@ -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; /// /// 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 holding the named slider, the Auto pill and the reset button. /// [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 /// Formatted current value (read by the template). public string DisplayValue { get => (string)GetValue(DisplayValueProperty); private set => SetValue(DisplayValueProperty, value); } - /// "Auto · 41" pill text; the "Auto" word comes from the catalog (Common.Auto). + /// "Auto · 41" pill text (Common.AutoValue). public string AutoText { get => (string)GetValue(AutoTextProperty); private set => SetValue(AutoTextProperty, value); } /// Tooltip of the slider track: what moving it does. @@ -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)); + } +} + +/// A named group around the slider, the Auto pill and the reset button. +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; } } diff --git a/src/Titano.Ui/Controls/Bidi.cs b/src/Titano.Ui/Controls/Bidi.cs new file mode 100644 index 00000000..bab33444 --- /dev/null +++ b/src/Titano.Ui/Controls/Bidi.cs @@ -0,0 +1,30 @@ +using System.Windows; + +namespace Titano.Ui.Controls; + +/// +/// 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 mirrors with it only when its glyph is directional +/// (). 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 FlowDirection="LeftToRight" +/// on the smallest element that holds them, and a directional icon inside an island keeps its drawn orientation. +/// +public static class Bidi +{ + /// Inherited override of ; null keeps each glyph's own flag. + 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); + + /// The flow direction of the current UI language. + 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(); + } +} diff --git a/src/Titano.Ui/Controls/BrandMarkIcon.cs b/src/Titano.Ui/Controls/BrandMarkIcon.cs index 1a95125c..aa881c97 100644 --- a/src/Titano.Ui/Controls/BrandMarkIcon.cs +++ b/src/Titano.Ui/Controls/BrandMarkIcon.cs @@ -4,7 +4,7 @@ using Titano.Core.Branding; namespace Titano.Ui.Controls; -/// The Titano mark drawn as vectors from geometry (plate optional). +/// The Titano mark drawn as vectors from geometry (plate optional); it never mirrors. 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); diff --git a/src/Titano.Ui/Controls/Icon.cs b/src/Titano.Ui/Controls/Icon.cs index f87b2542..b598384d 100644 --- a/src/Titano.Ui/Controls/Icon.cs +++ b/src/Titano.Ui/Controls/Icon.cs @@ -4,12 +4,16 @@ using System.Windows.Media; namespace Titano.Ui.Controls; -/// Renders an on the 16-unit grid, scaled to the element size, in the inherited foreground. +/// +/// Renders an 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 (); the others keep +/// their drawn orientation. +/// 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); + /// A directional glyph inherits the layout direction (and mirrors with it); any other glyph is pinned left-to-right. + 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; diff --git a/src/Titano.Ui/Controls/IconData.cs b/src/Titano.Ui/Controls/IconData.cs index 9c756621..1b63606d 100644 --- a/src/Titano.Ui/Controls/IconData.cs +++ b/src/Titano.Ui/Controls/IconData.cs @@ -22,6 +22,12 @@ public sealed class IconData set => _fill = Freeze(value); } + /// + /// 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. + /// + public bool IsDirectional { get; set; } + private static Geometry? Freeze(Geometry? g) { if (g is { CanFreeze: true, IsFrozen: false }) g.Freeze(); diff --git a/src/Titano.Ui/Controls/JobBar.cs b/src/Titano.Ui/Controls/JobBar.cs index 0d74ccd3..ddfd770c 100644 --- a/src/Titano.Ui/Controls/JobBar.cs +++ b/src/Titano.Ui/Controls/JobBar.cs @@ -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); } + /// Short accessible name of the stop (or pause) button; the tooltip sentence becomes its help text. + public string? StopName { get => (string?)GetValue(StopNameProperty); set => SetValue(StopNameProperty, value); } + /// Glyph of the action button: stop by default; the client shows pause (DESIGN §4 job bar). public IconData? ActionGlyph { get => (IconData?)GetValue(ActionGlyphProperty); set => SetValue(ActionGlyphProperty, value); } } diff --git a/src/Titano.Ui/Controls/TitanoWindow.cs b/src/Titano.Ui/Controls/TitanoWindow.cs index 4a8f326d..932f5de5 100644 --- a/src/Titano.Ui/Controls/TitanoWindow.cs +++ b/src/Titano.Ui/Controls/TitanoWindow.cs @@ -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; /// /// 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). /// [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; } /// Extra content placed in the title bar between the title and the caption buttons. @@ -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); diff --git a/src/Titano.Ui/Controls/Toasts.cs b/src/Titano.Ui/Controls/Toasts.cs index 19f1da3e..75701caa 100644 --- a/src/Titano.Ui/Controls/Toasts.cs +++ b/src/Titano.Ui/Controls/Toasts.cs @@ -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); } -/// Bottom-right stack of s with auto-dismiss. +/// +/// Bottom-right stack of 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; 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. +/// public class ToastHost : ItemsControl { private readonly Dictionary _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 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(); - } - - /// Pauses or resumes the dismissal timer (hover pauses). - 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) + /// Moves the keyboard to the newest toast's first control; false when no toast is shown. + 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; + } + + /// Hovering or focusing any toast holds them all; leaving restarts their full lifetime. + private void UpdateTimers() + { + var held = IsHeld; + foreach (var timer in _timers.Values) + { + timer.Stop(); + if (!held) timer.Start(); + } + } + + /// The action executes right after its Click event; the toast closes once it has run. + 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"); } } diff --git a/src/Titano.Ui/Icons/Icons.xaml b/src/Titano.Ui/Icons/Icons.xaml index 96d567b8..8e6729d9 100644 --- a/src/Titano.Ui/Icons/Icons.xaml +++ b/src/Titano.Ui/Icons/Icons.xaml @@ -6,7 +6,7 @@ - + @@ -14,8 +14,8 @@ - - + + @@ -35,13 +35,13 @@ - + - + @@ -50,14 +50,14 @@ - + - + @@ -99,7 +99,7 @@ - + diff --git a/src/Titano.Ui/Themes/Controls.xaml b/src/Titano.Ui/Themes/Controls.xaml index a22debfb..be8a204a 100644 --- a/src/Titano.Ui/Themes/Controls.xaml +++ b/src/Titano.Ui/Themes/Controls.xaml @@ -25,6 +25,17 @@ + + + @@ -256,8 +267,14 @@ + + + + + + + + @@ -1384,7 +1445,8 @@