diff --git a/i18n/ar/Archive.ar.resx b/i18n/ar/Archive.ar.resx index 1e18623c..98842b47 100644 --- a/i18n/ar/Archive.ar.resx +++ b/i18n/ar/Archive.ar.resx @@ -216,7 +216,6 @@ تحقق شجرة الأرشيف بلا تاريخ - الصيانة العرض نظرة عامة diff --git a/i18n/bg/Archive.bg.resx b/i18n/bg/Archive.bg.resx index 3772a3b5..72c4c13b 100644 --- a/i18n/bg/Archive.bg.resx +++ b/i18n/bg/Archive.bg.resx @@ -176,7 +176,6 @@ Проверка Дърво на архива Без дата - Поддръжка Изглед Общ преглед diff --git a/i18n/cs/Archive.cs.resx b/i18n/cs/Archive.cs.resx index 52d7dd9f..7166e827 100644 --- a/i18n/cs/Archive.cs.resx +++ b/i18n/cs/Archive.cs.resx @@ -196,7 +196,6 @@ Ověřit Strom archivu Bez data - Údržba Zobrazení Přehled diff --git a/i18n/da/Archive.da.resx b/i18n/da/Archive.da.resx index ab609af9..99666028 100644 --- a/i18n/da/Archive.da.resx +++ b/i18n/da/Archive.da.resx @@ -176,7 +176,6 @@ Verificer Arkivtræ Uden dato - Vedligeholdelse Visning Oversigt diff --git a/i18n/de/Archive.de.resx b/i18n/de/Archive.de.resx index 5f829750..5bff6ebe 100644 --- a/i18n/de/Archive.de.resx +++ b/i18n/de/Archive.de.resx @@ -176,7 +176,6 @@ Prüfen Archivbaum Ohne Datum - Wartung Ansicht Übersicht diff --git a/i18n/el/Archive.el.resx b/i18n/el/Archive.el.resx index c506a44a..ba9272f6 100644 --- a/i18n/el/Archive.el.resx +++ b/i18n/el/Archive.el.resx @@ -176,7 +176,6 @@ Επαλήθευση Δέντρο αρχειοθήκης Χωρίς ημερομηνία - Συντήρηση Προβολή Επισκόπηση diff --git a/i18n/en/Archive.resx b/i18n/en/Archive.resx index 8e9dbc0e..79ccbb34 100644 --- a/i18n/en/Archive.resx +++ b/i18n/en/Archive.resx @@ -235,10 +235,11 @@ {0:N0} sequence restoredlong {0:N0} sequences restoredlong Restoring {0}…long + Hide year + Show year Archive tree Undated Health - Maintenance View Overview diff --git a/i18n/en/Editor.resx b/i18n/en/Editor.resx index 836a85e7..8c4cc113 100644 --- a/i18n/en/Editor.resx +++ b/i18n/en/Editor.resx @@ -159,6 +159,7 @@ Path smoothing Stabilise {0}: {1} → {2}invariant + {0}: {1} ← {2}invariant; right-to-left languages: the arrow points from the old value to the new one {0} setting changed {0} settings changed Nothing to change diff --git a/i18n/en/Shell.resx b/i18n/en/Shell.resx index af382003..47ad54db 100644 --- a/i18n/en/Shell.resx +++ b/i18n/en/Shell.resx @@ -12,6 +12,8 @@ Ready · {0} jobs queued{0} count About Archive + Collapse navigation + Expand navigation Import Jobs Library diff --git a/i18n/es/Archive.es.resx b/i18n/es/Archive.es.resx index 7c67d095..ce74be20 100644 --- a/i18n/es/Archive.es.resx +++ b/i18n/es/Archive.es.resx @@ -176,7 +176,6 @@ Verificar Árbol de la fototeca Sin fecha - Mantenimiento Vista Vista general diff --git a/i18n/et/Archive.et.resx b/i18n/et/Archive.et.resx index 20ee7811..75e8e364 100644 --- a/i18n/et/Archive.et.resx +++ b/i18n/et/Archive.et.resx @@ -176,7 +176,6 @@ Kontrolli Arhiivipuu Kuupäevata - Hooldus Vaade Ülevaade diff --git a/i18n/fi/Archive.fi.resx b/i18n/fi/Archive.fi.resx index 87b1f622..47520ee2 100644 --- a/i18n/fi/Archive.fi.resx +++ b/i18n/fi/Archive.fi.resx @@ -176,7 +176,6 @@ Tarkista Arkistopuu Päiväämätön - Ylläpito Näkymä Yleiskatsaus diff --git a/i18n/fr/Archive.fr.resx b/i18n/fr/Archive.fr.resx index f546d1c9..d8c2db85 100644 --- a/i18n/fr/Archive.fr.resx +++ b/i18n/fr/Archive.fr.resx @@ -176,7 +176,6 @@ Vérifier Arborescence de l'archive Sans date - Maintenance Affichage Vue d'ensemble diff --git a/i18n/he/Archive.he.resx b/i18n/he/Archive.he.resx index bf2ecb38..eb4615bc 100644 --- a/i18n/he/Archive.he.resx +++ b/i18n/he/Archive.he.resx @@ -196,7 +196,6 @@ אמת עץ הארכיון ללא תאריך - תחזוקה תצוגה סקירה כללית diff --git a/i18n/hi/Archive.hi.resx b/i18n/hi/Archive.hi.resx index 28071fe4..0dbe265b 100644 --- a/i18n/hi/Archive.hi.resx +++ b/i18n/hi/Archive.hi.resx @@ -176,7 +176,6 @@ सत्यापित करें संग्रह ट्री बिना दिनांक - रखरखाव दृश्य अवलोकन diff --git a/i18n/hr/Archive.hr.resx b/i18n/hr/Archive.hr.resx index 0c42fdfd..c7e74b40 100644 --- a/i18n/hr/Archive.hr.resx +++ b/i18n/hr/Archive.hr.resx @@ -196,7 +196,6 @@ Provjeri Stablo arhive Bez datuma - Održavanje Prikaz Pregled diff --git a/i18n/hu/Archive.hu.resx b/i18n/hu/Archive.hu.resx index fdbf6e42..421d20a8 100644 --- a/i18n/hu/Archive.hu.resx +++ b/i18n/hu/Archive.hu.resx @@ -176,7 +176,6 @@ Ellenőrzés Archívumfa Dátum nélkül - Karbantartás Nézet Áttekintés diff --git a/i18n/id/Archive.id.resx b/i18n/id/Archive.id.resx index 2b297a95..e71b74e4 100644 --- a/i18n/id/Archive.id.resx +++ b/i18n/id/Archive.id.resx @@ -176,7 +176,6 @@ Verifikasi Pohon arsip Tanpa tanggal - Pemeliharaan Tampilan Ikhtisar diff --git a/i18n/it/Archive.it.resx b/i18n/it/Archive.it.resx index 71c4a084..889e7ad4 100644 --- a/i18n/it/Archive.it.resx +++ b/i18n/it/Archive.it.resx @@ -228,10 +228,11 @@ {0:N0} sequenza ripristinata {0:N0} sequenze ripristinate Ripristino di {0}… + Nascondi anno + Mostra anno Albero dell'archivio Senza data Stato - Manutenzione Vista Panoramica diff --git a/i18n/it/Shell.it.resx b/i18n/it/Shell.it.resx index cea2f212..4e62588a 100644 --- a/i18n/it/Shell.it.resx +++ b/i18n/it/Shell.it.resx @@ -11,6 +11,8 @@ Pronto · {0} attività in coda Informazioni Archivio + Riduci navigazione + Espandi navigazione Importa Attività Libreria diff --git a/i18n/ja/Archive.ja.resx b/i18n/ja/Archive.ja.resx index a3e17ad1..97adac39 100644 --- a/i18n/ja/Archive.ja.resx +++ b/i18n/ja/Archive.ja.resx @@ -176,7 +176,6 @@ 検証 アーカイブツリー 日付なし - メンテナンス 表示 概要 diff --git a/i18n/ko/Archive.ko.resx b/i18n/ko/Archive.ko.resx index 5115b133..28431b4c 100644 --- a/i18n/ko/Archive.ko.resx +++ b/i18n/ko/Archive.ko.resx @@ -176,7 +176,6 @@ 검증 아카이브 트리 날짜 없음 - 유지 관리 보기 개요 diff --git a/i18n/lt/Archive.lt.resx b/i18n/lt/Archive.lt.resx index 02dbd5d8..41346142 100644 --- a/i18n/lt/Archive.lt.resx +++ b/i18n/lt/Archive.lt.resx @@ -196,7 +196,6 @@ Patikrinti Archyvo medis Be datos - Priežiūra Rodinys Apžvalga diff --git a/i18n/lv/Archive.lv.resx b/i18n/lv/Archive.lv.resx index e4ace43b..b3c42e0c 100644 --- a/i18n/lv/Archive.lv.resx +++ b/i18n/lv/Archive.lv.resx @@ -196,7 +196,6 @@ Verificēt Arhīva koks Bez datuma - Apkope Skats Pārskats diff --git a/i18n/ms/Archive.ms.resx b/i18n/ms/Archive.ms.resx index 0f7a60ff..8ba5bc0f 100644 --- a/i18n/ms/Archive.ms.resx +++ b/i18n/ms/Archive.ms.resx @@ -176,7 +176,6 @@ Sahkan Pepohon arkib Tanpa tarikh - Penyelenggaraan Paparan Gambaran keseluruhan diff --git a/i18n/nb/Archive.nb.resx b/i18n/nb/Archive.nb.resx index 6714148c..e79dc934 100644 --- a/i18n/nb/Archive.nb.resx +++ b/i18n/nb/Archive.nb.resx @@ -176,7 +176,6 @@ Verifiser Arkivtre Udatert - Vedlikehold Visning Oversikt diff --git a/i18n/nl/Archive.nl.resx b/i18n/nl/Archive.nl.resx index 9d3ec457..c2f5dbfe 100644 --- a/i18n/nl/Archive.nl.resx +++ b/i18n/nl/Archive.nl.resx @@ -176,7 +176,6 @@ Verifiëren Archiefstructuur Zonder datum - Onderhoud Weergave Overzicht diff --git a/i18n/pl/Archive.pl.resx b/i18n/pl/Archive.pl.resx index 1bf7d942..dfd001e0 100644 --- a/i18n/pl/Archive.pl.resx +++ b/i18n/pl/Archive.pl.resx @@ -216,7 +216,6 @@ Weryfikuj Drzewo archiwum Bez daty - Konserwacja Widok Przegląd diff --git a/i18n/pt-BR/Archive.pt-BR.resx b/i18n/pt-BR/Archive.pt-BR.resx index ce1c7838..80414915 100644 --- a/i18n/pt-BR/Archive.pt-BR.resx +++ b/i18n/pt-BR/Archive.pt-BR.resx @@ -176,7 +176,6 @@ Verificar Árvore do acervo Sem data - Manutenção Exibição Visão geral diff --git a/i18n/pt-PT/Archive.pt-PT.resx b/i18n/pt-PT/Archive.pt-PT.resx index 7b43eb18..861cdda9 100644 --- a/i18n/pt-PT/Archive.pt-PT.resx +++ b/i18n/pt-PT/Archive.pt-PT.resx @@ -176,7 +176,6 @@ Verificar Árvore do arquivo Sem data - Manutenção Vista Descrição geral diff --git a/i18n/ro/Archive.ro.resx b/i18n/ro/Archive.ro.resx index 6afe1e88..3bdbf0a9 100644 --- a/i18n/ro/Archive.ro.resx +++ b/i18n/ro/Archive.ro.resx @@ -196,7 +196,6 @@ Verificare Arbore arhivă Fără dată - Întreținere Vizualizare Prezentare generală diff --git a/i18n/ru/Archive.ru.resx b/i18n/ru/Archive.ru.resx index 450fba91..0aa94594 100644 --- a/i18n/ru/Archive.ru.resx +++ b/i18n/ru/Archive.ru.resx @@ -216,7 +216,6 @@ Проверить Дерево архива Без даты - Обслуживание Вид Обзор diff --git a/i18n/sk/Archive.sk.resx b/i18n/sk/Archive.sk.resx index a16e10a4..460af4f4 100644 --- a/i18n/sk/Archive.sk.resx +++ b/i18n/sk/Archive.sk.resx @@ -196,7 +196,6 @@ Overiť Strom archívu Bez dátumu - Údržba Zobrazenie Prehľad diff --git a/i18n/sl/Archive.sl.resx b/i18n/sl/Archive.sl.resx index 13b846be..cc63fc28 100644 --- a/i18n/sl/Archive.sl.resx +++ b/i18n/sl/Archive.sl.resx @@ -196,7 +196,6 @@ Preveri Drevo arhiva Brez datuma - Vzdrževanje Pogled Povzetek diff --git a/i18n/sv/Archive.sv.resx b/i18n/sv/Archive.sv.resx index 82996310..950b76e7 100644 --- a/i18n/sv/Archive.sv.resx +++ b/i18n/sv/Archive.sv.resx @@ -176,7 +176,6 @@ Verifiera Arkivträd Odaterade - Underhåll Vy Översikt diff --git a/i18n/th/Archive.th.resx b/i18n/th/Archive.th.resx index 94eff1cb..a43c324f 100644 --- a/i18n/th/Archive.th.resx +++ b/i18n/th/Archive.th.resx @@ -176,7 +176,6 @@ ตรวจสอบ แผนผังคลังภาพ ไม่มีวันที่ - การบำรุงรักษา มุมมอง ภาพรวม diff --git a/i18n/tr/Archive.tr.resx b/i18n/tr/Archive.tr.resx index 936493c0..7d81474e 100644 --- a/i18n/tr/Archive.tr.resx +++ b/i18n/tr/Archive.tr.resx @@ -176,7 +176,6 @@ Doğrula Arşiv ağacı Tarihsiz - Bakım Görünüm Genel bakış diff --git a/i18n/uk/Archive.uk.resx b/i18n/uk/Archive.uk.resx index 4091c6e0..0fe7e25c 100644 --- a/i18n/uk/Archive.uk.resx +++ b/i18n/uk/Archive.uk.resx @@ -216,7 +216,6 @@ Перевірити Дерево архіву Без дати - Обслуговування Вигляд Огляд diff --git a/i18n/vi/Archive.vi.resx b/i18n/vi/Archive.vi.resx index 3ed022c6..731a3a9c 100644 --- a/i18n/vi/Archive.vi.resx +++ b/i18n/vi/Archive.vi.resx @@ -176,7 +176,6 @@ Xác minh Cây kho lưu trữ Không có ngày - Bảo trì Chế độ xem Tổng quan diff --git a/i18n/zh-Hans/Archive.zh-Hans.resx b/i18n/zh-Hans/Archive.zh-Hans.resx index baa80ac7..2156e54d 100644 --- a/i18n/zh-Hans/Archive.zh-Hans.resx +++ b/i18n/zh-Hans/Archive.zh-Hans.resx @@ -176,7 +176,6 @@ 校验 档案库目录树 无日期 - 维护 视图 概览 diff --git a/i18n/zh-Hant/Archive.zh-Hant.resx b/i18n/zh-Hant/Archive.zh-Hant.resx index e383bdcd..14e44b91 100644 --- a/i18n/zh-Hant/Archive.zh-Hant.resx +++ b/i18n/zh-Hant/Archive.zh-Hant.resx @@ -176,7 +176,6 @@ 驗證 典藏庫樹狀結構 無日期 - 維護 檢視 概觀 diff --git a/src/Titano.App/Archive/ArchiveDialogs.xaml b/src/Titano.App/Archive/ArchiveDialogs.xaml index 66ba78f2..03c84319 100644 --- a/src/Titano.App/Archive/ArchiveDialogs.xaml +++ b/src/Titano.App/Archive/ArchiveDialogs.xaml @@ -106,7 +106,7 @@ - diff --git a/src/Titano.App/Archive/ArchiveRowViewModels.cs b/src/Titano.App/Archive/ArchiveRowViewModels.cs index 639e7e51..0656c581 100644 --- a/src/Titano.App/Archive/ArchiveRowViewModels.cs +++ b/src/Titano.App/Archive/ArchiveRowViewModels.cs @@ -24,6 +24,9 @@ public sealed class ArchiveTreeRowViewModel(ArchiveTreeNode node, ArchiveAvailab public string ToggleToolTip => Loc.L(Node.IsExpanded ? "Tooltips.Archive.Collapse" : "Tooltips.Archive.Expand"); + /// The expander's accessible name: two words, the sentence is its tooltip. + public string ToggleName => Loc.L(Node.IsExpanded ? "Archive.Tree.Collapse" : "Archive.Tree.Expand"); + /// /// The full title (the tree trims it) and its figures; a year also says how the keyboard opens and closes it, with /// the arrow keys swapped in a right-to-left layout. diff --git a/src/Titano.App/Editor/EditorText.cs b/src/Titano.App/Editor/EditorText.cs index d7d6376e..85d1c72a 100644 --- a/src/Titano.App/Editor/EditorText.cs +++ b/src/Titano.App/Editor/EditorText.cs @@ -196,6 +196,14 @@ public static class EditorText _ => parameter, }; + /// + /// "Deflicker window: 21 frames → 41 frames", one line of the Optimise toast. Bidi never mirrors an arrow, so a + /// right-to-left language reads it from its own resource, the arrow pointing from the old value to the new one. + /// + public static string Change(SettingChange change) => + Loc.L(Loc.IsRightToLeft ? "Editor.Optimise.ChangeRtl" : "Editor.Optimise.Change", ParameterLabel(change.Parameter), Value(change.Parameter, change.Before), + Value(change.Parameter, change.After)); + /// A value of an advisor parameter as its control shows it (the "what changed" toast of Optimise). public static string Value(string parameter, object? value) => (parameter, value) switch { diff --git a/src/Titano.App/Editor/EditorViewModel.cs b/src/Titano.App/Editor/EditorViewModel.cs index adfb5ad5..e2c80437 100644 --- a/src/Titano.App/Editor/EditorViewModel.cs +++ b/src/Titano.App/Editor/EditorViewModel.cs @@ -819,6 +819,7 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable { Title = Loc.L("Editor.Save.Failed"), Message = ex.Message, + IsError = true, ActionText = Loc.L("Editor.Save.Retry"), ActionToolTip = Loc.L("Tooltips.Editor.Save.Retry"), ActionCommand = new RelayCommand(() => _ = Session.FlushAsync()), @@ -893,9 +894,7 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable Shell.Notify(Loc.L("Editor.Optimise.Nothing")); return; } - var lines = changes.Select(c => Loc.L("Editor.Optimise.Change", EditorText.ParameterLabel(c.Parameter), EditorText.Value(c.Parameter, c.Before), - EditorText.Value(c.Parameter, c.After))); - Shell.Notify(Loc.Plural("Editor.Optimise.Done", changes.Count), string.Join(Environment.NewLine, lines)); + Shell.Notify(Loc.Plural("Editor.Optimise.Done", changes.Count), string.Join(Environment.NewLine, changes.Select(EditorText.Change))); } private async Task AnalyseAsync() @@ -957,6 +956,7 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable { Title = Loc.L("Editor.ServerJob.Ended", JobText.Kind(job.Kind), Loc.L("Jobs.State." + job.State), server), Message = job.Error ?? job.TargetLabel ?? Title, + IsError = job.State == JobState.Failed, ActionText = Loc.L("Jobs.Action.Retry"), ActionToolTip = Loc.L("Tooltips.Editor.ServerJob.Retry", server), ActionCommand = new AsyncRelayCommand(() => Session.Source.RetryJobAsync(job.Id, CancellationToken.None), () => !_disposed), diff --git a/src/Titano.App/Import/ImportResultViewModel.cs b/src/Titano.App/Import/ImportResultViewModel.cs index bea85506..04f65e89 100644 --- a/src/Titano.App/Import/ImportResultViewModel.cs +++ b/src/Titano.App/Import/ImportResultViewModel.cs @@ -177,7 +177,7 @@ public sealed class ImportResultViewModel : LocalizedViewModel catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or DatabaseException) { Log.Warning("import", "Card check failed", ex); - _shell.Notify(Loc.L("Import.Toast.CheckFailed"), ex.Message); + _shell.Notify(Loc.L("Import.Toast.CheckFailed"), ex.Message, isError: true); } finally { @@ -212,7 +212,7 @@ public sealed class ImportResultViewModel : LocalizedViewModel catch (Exception ex) when (ex is IOException or UnauthorizedAccessException) { Log.Warning("import", "Deleting imported photos failed", ex); - _shell.Notify(Loc.L("Import.Toast.DeleteFailed"), ex.Message); + _shell.Notify(Loc.L("Import.Toast.DeleteFailed"), ex.Message, isError: true); } finally { @@ -263,12 +263,12 @@ public sealed class ImportResultViewModel : LocalizedViewModel if (!unchanged) { Actions = _actions with { Erase = null, Card = null }; - _shell.Notify(Loc.L("Import.Toast.CardChanged", name), Loc.L("Import.Blocked.NoDryRun")); + _shell.Notify(Loc.L("Import.Toast.CardChanged", name), Loc.L("Import.Blocked.NoDryRun"), isError: true); return; } var outcome = _shell.Services.Devices.Format(device); if (outcome == FormatOutcome.Formatted) Actions = _actions with { Erase = null, Card = null }; - if (outcome != FormatOutcome.Cancelled) _shell.Notify(Loc.L("Import.Toast.Format." + outcome, name)); + if (outcome != FormatOutcome.Cancelled) _shell.Notify(Loc.L("Import.Toast.Format." + outcome, name), isError: outcome == FormatOutcome.Failed); } /// The first files that were never imported, one per line. @@ -286,7 +286,7 @@ public sealed class ImportResultViewModel : LocalizedViewModel try { var outcome = await Task.Run(() => _shell.Services.Devices.Eject(device)); - _shell.Notify(Loc.L("Import.Toast.Eject." + outcome, _card?.Nickname ?? device.Label)); + _shell.Notify(Loc.L("Import.Toast.Eject." + outcome, _card?.Nickname ?? device.Label), isError: outcome != EjectOutcome.Ejected); if (outcome == EjectOutcome.Ejected) SetDevice(null); } finally diff --git a/src/Titano.App/Infrastructure/ArchiveSetup.cs b/src/Titano.App/Infrastructure/ArchiveSetup.cs index 15b3672c..0533f67a 100644 --- a/src/Titano.App/Infrastructure/ArchiveSetup.cs +++ b/src/Titano.App/Infrastructure/ArchiveSetup.cs @@ -56,7 +56,7 @@ public static class ArchiveActions or Data.DatabaseException) { Log.Error("archive", "Archive action failed", ex); - shell.Notify(Core.Localization.Loc.L("Errors.Archive.Open"), ex.Message); + shell.Notify(Core.Localization.Loc.L("Errors.Archive.Open"), ex.Message, isError: true); return false; } } diff --git a/src/Titano.App/Sections/ArchiveView.xaml b/src/Titano.App/Sections/ArchiveView.xaml index de3d128d..a0d1f5d5 100644 --- a/src/Titano.App/Sections/ArchiveView.xaml +++ b/src/Titano.App/Sections/ArchiveView.xaml @@ -13,36 +13,6 @@ - - - - - - diff --git a/src/Titano.App/Shell/MainWindow.xaml b/src/Titano.App/Shell/MainWindow.xaml index 70b7a7e3..08a191b5 100644 --- a/src/Titano.App/Shell/MainWindow.xaml +++ b/src/Titano.App/Shell/MainWindow.xaml @@ -36,7 +36,7 @@ public abstract class DrawingElement : FrameworkElement { @@ -28,6 +38,8 @@ public abstract class DrawingElement : FrameworkElement private HoverReadout? _readout; private Typeface? _regular; private Typeface? _semiBold; + private Delegate? _activationHandlers; + private int _keyboardItem = -1; /// Creates the overlay layer drawn by . protected DrawingElement(bool hasOverlay = false) @@ -101,6 +113,51 @@ public abstract class DrawingElement : FrameworkElement /// protected internal virtual string? AutomationDescription => null; + /// The item the keyboard is on, read to screen readers as the image's status; null when none. + internal string? KeyboardItemText => IsActivatable && _keyboardItem >= 0 && _keyboardItem < ItemCount ? ItemText(_keyboardItem) : null; + + /// Whether a handler of the visual's activation event is attached to the visual itself (not to an ancestor). + protected bool IsActivatable => _activationHandlers is not null; + + /// Number of discrete items (bars, segments, cells); 0 for visuals without items. + protected virtual int ItemCount => 0; + + /// Item under , or −1. + protected virtual int ItemAt(Point point) => -1; + + /// Where was last drawn: the keyboard outline follows this rectangle. + protected virtual Rect ItemBounds(int item) => Rect.Empty; + + /// What the readout says for . + protected virtual string? ItemText(int item) => null; + + /// The item an arrow key moves to from ; −1 when the key does not move. + protected virtual int Navigate(int item, Key key) => -1; + + /// Raises the visual's activation event for . + protected virtual void Activate(int item) + { + } + + /// Records a handler added to or removed from the activation event; call from the event's accessors. + protected void TrackActivation(Delegate handler, bool added) + { + _activationHandlers = added ? Delegate.Combine(_activationHandlers, handler) : Delegate.Remove(_activationHandlers, handler); + SetCurrentValue(FocusableProperty, IsActivatable); + InvalidateVisual(); + } + + /// The cursor the visual shows at : the hand over an item something activates, otherwise none of its own. + internal Cursor? CursorAt(Point point) => IsActivatable && ItemAt(point) >= 0 ? Cursors.Hand : null; + + /// Outlines the keyboard's item while the visual has keyboard focus (DESIGN §4: 2 px Accent); call last in OnRender. + protected void DrawKeyboardItem(DrawingContext dc) + { + if (!IsKeyboardFocused || !IsActivatable || _keyboardItem < 0 || _keyboardItem >= ItemCount) return; + var bounds = ItemBounds(_keyboardItem); + if (!bounds.IsEmpty) dc.DrawRoundedRectangle(null, GetPen("Brush.Accent", 2), bounds, 4, 4); + } + /// Single-line left-to-right text in the UI font (numbers, ticks, times), laid out for this element's DPI and text formatting mode. protected FormattedText CreateText(string text, double emSize, Brush brush, bool semiBold = false) => Format(text, emSize, brush, semiBold, FlowDirection.LeftToRight); @@ -142,6 +199,7 @@ public abstract class DrawingElement : FrameworkElement /// Called when a data property or a watched collection changed; the default re-measures and redraws. protected virtual void OnDataChanged() { + _keyboardItem = Math.Min(_keyboardItem, ItemCount - 1); InvalidateMeasure(); InvalidateVisual(); } @@ -163,6 +221,90 @@ public abstract class DrawingElement : FrameworkElement OnThemeChanged(); } + protected override void OnMouseMove(MouseEventArgs e) + { + base.OnMouseMove(e); + if (ItemCount == 0) return; + var p = e.GetPosition(this); + var item = ItemAt(p); + Readout.Show(item >= 0 ? ItemText(item) : null, p); + } + + protected override void OnMouseLeave(MouseEventArgs e) + { + base.OnMouseLeave(e); + if (ItemCount > 0) Readout.Hide(); + } + + protected override void OnQueryCursor(QueryCursorEventArgs e) + { + base.OnQueryCursor(e); + if (e.Handled || CursorAt(e.GetPosition(this)) is not { } cursor) return; + e.Cursor = cursor; + e.Handled = true; + } + + protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e) + { + base.OnMouseLeftButtonUp(e); + if (e.Handled || ItemCount == 0) return; + var item = ItemAt(e.GetPosition(this)); + if (item < 0) return; + _keyboardItem = item; + Activate(item); + e.Handled = true; + } + + protected override void OnKeyDown(KeyEventArgs e) + { + base.OnKeyDown(e); + var count = ItemCount; + if (e.Handled || !IsActivatable || count == 0) return; + var current = Math.Clamp(_keyboardItem, 0, count - 1); + if (e.Key is Key.Enter or Key.Space) + { + MoveKeyboardTo(current); + Activate(current); + e.Handled = true; + return; + } + var next = e.Key switch + { + Key.Home => 0, + Key.End => count - 1, + _ => Navigate(current, e.Key), + }; + if (next < 0) return; + MoveKeyboardTo(Math.Min(next, count - 1)); + e.Handled = true; + } + + protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e) + { + base.OnGotKeyboardFocus(e); + if (IsActivatable && ItemCount > 0 && ReferenceEquals(e.NewFocus, this)) MoveKeyboardTo(Math.Clamp(_keyboardItem, 0, ItemCount - 1)); + } + + protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e) + { + base.OnLostKeyboardFocus(e); + if (!IsActivatable) return; + Readout.Hide(); + InvalidateVisual(); + } + + /// Puts the keyboard on : outlined, read out next to it and announced as the image's status. + private void MoveKeyboardTo(int item) + { + var before = KeyboardItemText; + _keyboardItem = item; + InvalidateVisual(); + var bounds = ItemBounds(item); + if (!bounds.IsEmpty) Readout.Show(ItemText(item), bounds.BottomLeft); + UIElementAutomationPeer.FromElement(this)?.RaisePropertyChangedEvent(AutomationElementIdentifiers.ItemStatusProperty, before ?? string.Empty, + KeyboardItemText ?? string.Empty); + } + /// Fills the whole element with a transparent brush so empty areas still receive the mouse. protected void DrawHitArea(DrawingContext dc) => dc.DrawRectangle(Brushes.Transparent, null, new Rect(RenderSize)); @@ -281,4 +423,11 @@ public class DrawingElementAutomationPeer(DrawingElement owner) : FrameworkEleme var name = base.GetNameCore(); return string.IsNullOrEmpty(name) ? ((DrawingElement)Owner).AutomationDescription ?? string.Empty : name; } + + /// The item the keyboard is on, unless AutomationProperties.ItemStatus says otherwise. + protected override string GetItemStatusCore() + { + var status = base.GetItemStatusCore(); + return string.IsNullOrEmpty(status) ? ((DrawingElement)Owner).KeyboardItemText ?? string.Empty : status; + } } diff --git a/src/Titano.Ui/Visuals/HeatmapStrip.cs b/src/Titano.Ui/Visuals/HeatmapStrip.cs index 7dc79054..fcd5fd19 100644 --- a/src/Titano.Ui/Visuals/HeatmapStrip.cs +++ b/src/Titano.Ui/Visuals/HeatmapStrip.cs @@ -7,9 +7,11 @@ namespace Titano.Ui.Visuals; /// /// Density grid (Archive: photos per month, one row per year × 12 months). Each value is a square cell in the -/// brush colour whose opacity grows with the value; NaN cells ("no data", e.g. future months) use the card fill. -/// Column labels sit above, row labels on the left, an optional min–max scale below. Hovering reads out the cell -/// (its tooltip or "row column · value"); clicking raises . +/// brush colour whose opacity grows with the value; NaN cells ("no data", e.g. future months) take the stroke tone, +/// which differs from the card and panel fills in both themes. Column labels sit above, row labels on the left, an +/// optional min–max scale below; months run left to right in every language. Hovering reads out the cell (its +/// tooltip or "row column · value"); clicking raises , and a handler attached to the +/// grid also gives it the hand cursor and the keyboard. /// public sealed class HeatmapStrip : DrawingElement { @@ -49,7 +51,6 @@ public sealed class HeatmapStrip : DrawingElement private const double LabelSize = 11; private CellGridLayout _grid; - private bool _hovering; /// One row per year (label + 12 monthly values). public IReadOnlyList? Rows { get => (IReadOnlyList?)GetValue(RowsProperty); set => SetValue(RowsProperty, value); } @@ -75,10 +76,19 @@ public sealed class HeatmapStrip : DrawingElement /// Culture-aware value formatting (scale ends and readouts). public Func? ValueFormatter { get => (Func?)GetValue(ValueFormatterProperty); set => SetValue(ValueFormatterProperty, value); } + /// Raised when a cell is clicked, or chosen with the keyboard and Enter; attach it to the grid itself to make the cells interactive. public event ChartItemEventHandler CellActivated { - add => AddHandler(CellActivatedEvent, value); - remove => RemoveHandler(CellActivatedEvent, value); + add + { + AddHandler(CellActivatedEvent, value); + TrackActivation(value, added: true); + } + remove + { + RemoveHandler(CellActivatedEvent, value); + TrackActivation(value, added: false); + } } private int RowCount => Rows?.Count ?? 0; @@ -95,6 +105,9 @@ public sealed class HeatmapStrip : DrawingElement } } + /// Cells in reading order: row by row, per row. + protected override int ItemCount => RowCount * ColumnCount; + protected override Size MeasureOverride(Size availableSize) { if (RowCount == 0 || ColumnCount == 0) return new Size(0, 0); @@ -107,26 +120,26 @@ public sealed class HeatmapStrip : DrawingElement DrawHitArea(dc); if (Rows is not { Count: > 0 } rows || ColumnCount == 0) return; _grid = Layout(ActualWidth, ActualHeight - ScaleHeight()); - var faint = GetBrush("Brush.TextFaint"); + var muted = GetBrush("Brush.TextMuted"); var max = ScaleMaximum(rows); if (ColumnLabels is { } columns) { for (var c = 0; c < columns.Count; c++) { - var label = CreateLabel(columns[c], LabelSize, faint); + var label = CreateLabel(columns[c], LabelSize, muted); var (x, _) = _grid.CellOrigin(0, c); DrawTextAt(dc, label, new Point(x + (_grid.CellSize - label.Width) / 2, 0)); } } var fill = GetBrush(BrushKey); - var empty = GetBrush("Brush.Card"); + var empty = GetBrush("Brush.Stroke"); var radius = Math.Min(2, _grid.CellSize / 4); for (var r = 0; r < rows.Count; r++) { var row = rows[r]; - var label = CreateLabel(row.Label, LabelSize, faint); + var label = CreateLabel(row.Label, LabelSize, muted); var (_, y) = _grid.CellOrigin(r, 0); DrawTextAt(dc, label, new Point(_grid.Left - 8 - label.Width, y + (_grid.CellSize - label.Height) / 2)); for (var c = 0; c < _grid.Columns; c++) @@ -145,39 +158,39 @@ public sealed class HeatmapStrip : DrawingElement } } if (ShowScale) DrawScale(dc, fill, max); + DrawKeyboardItem(dc); } - protected override void OnMouseMove(MouseEventArgs e) + protected override int ItemAt(Point point) => + _grid.TryHit(point.X, point.Y, out var row, out var column) && row < RowCount && column < ColumnCount ? row * ColumnCount + column : -1; + + protected override Rect ItemBounds(int item) { - base.OnMouseMove(e); - var p = e.GetPosition(this); - _hovering = _grid.TryHit(p.X, p.Y, out var row, out var column) && row < RowCount; - Readout.Show(_hovering ? ReadoutText(row, column) : null, p); + if (_grid.CellSize <= 0 || ColumnCount == 0) return Rect.Empty; + var (x, y) = _grid.CellOrigin(item / ColumnCount, item % ColumnCount); + var cell = new Rect(x, y, _grid.CellSize, _grid.CellSize); + cell.Inflate(2, 2); + return cell; } - protected override void OnMouseLeave(MouseEventArgs e) + protected override string? ItemText(int item) => ColumnCount == 0 ? null : ReadoutText(item / ColumnCount, item % ColumnCount); + + /// Left/Right move along a year (months left to right in every language), Up/Down between years. + protected override int Navigate(int item, Key key) { - base.OnMouseLeave(e); - _hovering = false; - Readout.Hide(); + var columns = ColumnCount; + var (row, column) = (item / columns, item % columns); + return key switch + { + Key.Left => row * columns + Math.Max(0, column - 1), + Key.Right => row * columns + Math.Min(columns - 1, column + 1), + Key.Up => Math.Max(0, row - 1) * columns + column, + Key.Down => Math.Min(RowCount - 1, row + 1) * columns + column, + _ => -1, + }; } - protected override void OnQueryCursor(QueryCursorEventArgs e) - { - base.OnQueryCursor(e); - if (e.Handled || !_hovering) return; - e.Cursor = Cursors.Hand; - e.Handled = true; - } - - protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e) - { - base.OnMouseLeftButtonUp(e); - var p = e.GetPosition(this); - if (!_grid.TryHit(p.X, p.Y, out var row, out var column) || row >= RowCount) return; - RaiseEvent(new ChartItemEventArgs(CellActivatedEvent, row, column)); - e.Handled = true; - } + protected override void Activate(int item) => RaiseEvent(new ChartItemEventArgs(CellActivatedEvent, item / ColumnCount, item % ColumnCount)); private string Format(double value) => (ValueFormatter ?? DefaultFormat)(value); diff --git a/src/Titano.Ui/Visuals/SeriesChart.cs b/src/Titano.Ui/Visuals/SeriesChart.cs index 933f3013..aa3dc363 100644 --- a/src/Titano.Ui/Visuals/SeriesChart.cs +++ b/src/Titano.Ui/Visuals/SeriesChart.cs @@ -158,7 +158,7 @@ public sealed class SeriesChart : DrawingElement var labelWidth = 0.0; if (ShowYLabels) { - var labelBrush = GetBrush("Brush.TextFaint"); + var labelBrush = GetBrush("Brush.TextMuted"); for (var i = 0; i < ticks.Count; i++) { labels[i] = CreateText(format(ticks[i]), LabelSize, labelBrush); @@ -328,7 +328,7 @@ public sealed class SeriesChart : DrawingElement { if (_count < 2) return; var ticks = NiceScale.Inner(0, _count - 1, Math.Max(2, (int)(_plot.Width / 90))); - var brush = GetBrush("Brush.TextFaint"); + var brush = GetBrush("Brush.TextMuted"); var lastRight = double.NegativeInfinity; for (var i = 0; i < ticks.Count; i++) { diff --git a/src/Titano.Ui/Visuals/StackedBar.cs b/src/Titano.Ui/Visuals/StackedBar.cs index 64195061..61ac7f78 100644 --- a/src/Titano.Ui/Visuals/StackedBar.cs +++ b/src/Titano.Ui/Visuals/StackedBar.cs @@ -8,8 +8,9 @@ namespace Titano.Ui.Visuals; /// /// One bar split into proportional segments (by camera, by format) with a wrapping legend underneath /// ("■ label share"). Segments share one theme colour and fade by rank (items may set their own brush), so no new -/// colours are introduced; 2-px gaps separate them. Hovering a segment or legend entry reads it out; clicking -/// raises . +/// colours are introduced; 2-px gaps separate them. The first segment and the legend start on the reading side, so +/// both mirror in a right-to-left language. Hovering a segment or legend entry reads it out; clicking raises +/// , and a handler attached to the bar also gives it the hand cursor and the keyboard. /// public sealed class StackedBar : DrawingElement { @@ -42,7 +43,6 @@ public sealed class StackedBar : DrawingElement private readonly List _segments = []; private readonly List _entries = []; - private int _hover = -1; /// Parts in display order (largest first reads best). public IReadOnlyList? Items { get => (IReadOnlyList?)GetValue(ItemsProperty); set => SetValue(ItemsProperty, value); } @@ -56,15 +56,26 @@ public sealed class StackedBar : DrawingElement /// Formats a share 0…1 for the legend (default: culture percent without decimals). public Func? ShareFormatter { get => (Func?)GetValue(ShareFormatterProperty); set => SetValue(ShareFormatterProperty, value); } + /// Raised when a segment or its legend entry is clicked, or chosen with the keyboard and Enter; attach it to the bar itself to make it interactive. public event ChartItemEventHandler ItemActivated { - add => AddHandler(ItemActivatedEvent, value); - remove => RemoveHandler(ItemActivatedEvent, value); + add + { + AddHandler(ItemActivatedEvent, value); + TrackActivation(value, added: true); + } + remove + { + RemoveHandler(ItemActivatedEvent, value); + TrackActivation(value, added: false); + } } protected internal override string? AutomationDescription => Items is { Count: > 0 } items ? string.Join(Environment.NewLine, Enumerable.Range(0, items.Count).Select(ReadoutText)) : null; + protected override int ItemCount => Items?.Count ?? 0; + protected override Size MeasureOverride(Size availableSize) { if (Items is not { Count: > 0 } items) return new Size(0, 0); @@ -72,12 +83,6 @@ public sealed class StackedBar : DrawingElement return new Size(0, BarHeight + (lines > 0 ? LegendGap + lines * LegendLine : 0)); } - protected override void OnDataChanged() - { - _hover = -1; - base.OnDataChanged(); - } - protected override void OnRender(DrawingContext dc) { DrawHitArea(dc); @@ -94,48 +99,48 @@ public sealed class StackedBar : DrawingElement for (var i = 0; i < items.Count; i++) { var share = total > 0 ? Math.Max(0, items[i].Value) / total : 0; - var segment = new Rect(x, 0, available * share, BarHeight); + var segmentWidth = available * share; + var segment = new Rect(FromStart(x, segmentWidth, width), 0, segmentWidth, BarHeight); _segments.Add(segment); dc.PushOpacity(OpacityOf(i, items)); dc.DrawRectangle(GetBrush(items[i].BrushKey ?? BrushKey), null, segment); dc.Pop(); - x = segment.Right + SegmentGap; + x += segmentWidth + SegmentGap; } dc.Pop(); if (ShowLegend) LayoutLegend(items, width, dc); + DrawKeyboardItem(dc); } - protected override void OnMouseMove(MouseEventArgs e) + /// A segment, or its legend entry; a click in the gap between two segments counts for the nearer one. + protected override int ItemAt(Point point) { - base.OnMouseMove(e); - var p = e.GetPosition(this); - _hover = HitTest(p); - Readout.Show(_hover >= 0 ? ReadoutText(_hover) : null, p); + for (var i = 0; i < _segments.Count; i++) + if (point.Y >= 0 && point.Y <= BarHeight && point.X >= _segments[i].Left - SegmentGap / 2 && point.X <= _segments[i].Right + SegmentGap / 2) return i; + for (var i = 0; i < _entries.Count; i++) + if (_entries[i].Contains(point)) return i; + return -1; } - protected override void OnMouseLeave(MouseEventArgs e) + protected override Rect ItemBounds(int item) { - base.OnMouseLeave(e); - _hover = -1; - Readout.Hide(); + if (item >= _segments.Count) return Rect.Empty; + var segment = _segments[item]; + segment.Inflate(2, 2); + return segment; } - protected override void OnQueryCursor(QueryCursorEventArgs e) - { - base.OnQueryCursor(e); - if (e.Handled || _hover < 0) return; - e.Cursor = Cursors.Hand; - e.Handled = true; - } + protected override string? ItemText(int item) => Items is { } items && item < items.Count ? ReadoutText(item) : null; - protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e) + /// Left and Right move to the segment drawn on that side (the bar mirrors in a right-to-left language). + protected override int Navigate(int item, Key key) => key switch { - base.OnMouseLeftButtonUp(e); - var index = HitTest(e.GetPosition(this)); - if (index < 0) return; - RaiseEvent(new ChartItemEventArgs(ItemActivatedEvent, index, -1)); - e.Handled = true; - } + Key.Left => Loc.IsRightToLeft ? item + 1 : Math.Max(0, item - 1), + Key.Right => Loc.IsRightToLeft ? Math.Max(0, item - 1) : item + 1, + _ => -1, + }; + + protected override void Activate(int item) => RaiseEvent(new ChartItemEventArgs(ItemActivatedEvent, item, -1)); private static double Total(IReadOnlyList items) { @@ -188,15 +193,6 @@ public sealed class StackedBar : DrawingElement return line + 1; } - private int HitTest(Point p) - { - for (var i = 0; i < _segments.Count; i++) - if (p.Y >= 0 && p.Y <= BarHeight && p.X >= _segments[i].Left && p.X <= _segments[i].Right + SegmentGap) return i; - for (var i = 0; i < _entries.Count; i++) - if (_entries[i].Contains(p)) return i; - return -1; - } - private string ReadoutText(int index) { var items = Items!; diff --git a/src/Titano.Ui/Visuals/TimelineBands.cs b/src/Titano.Ui/Visuals/TimelineBands.cs index 981dfc3f..e565cde3 100644 --- a/src/Titano.Ui/Visuals/TimelineBands.cs +++ b/src/Titano.Ui/Visuals/TimelineBands.cs @@ -120,10 +120,10 @@ public sealed class TimelineBands : DrawingElement if (max <= 0) max = 1; var text = GetBrush("Brush.Text"); - var faint = GetBrush("Brush.TextFaint"); + var muted = GetBrush("Brush.TextMuted"); var fill = GetBrush(BrushKey); var divider = GetHairline("Brush.Stroke"); - var captionHeight = Math.Ceiling(CreateText("0", LabelSize, faint).Height); + var captionHeight = Math.Ceiling(CreateText("0", LabelSize, muted).Height); var barWidth = Math.Max(1, Math.Min(pitch * 0.6, 28)); for (var b = 0; b < bands.Count; b++) @@ -145,7 +145,7 @@ public sealed class TimelineBands : DrawingElement } if (SlotLabels is { } labels && s < labels.Count) { - var caption = CreateLabel(labels[s], LabelSize, faint); + var caption = CreateLabel(labels[s], LabelSize, muted); DrawTextAt(dc, caption, new Point(cx - caption.Width / 2, baseline + 4)); } if (b == CurrentBand && s == CurrentSlot) diff --git a/src/Titano.Uploader/Shell/MainViewModel.cs b/src/Titano.Uploader/Shell/MainViewModel.cs index 8cd5465d..d7a24f4d 100644 --- a/src/Titano.Uploader/Shell/MainViewModel.cs +++ b/src/Titano.Uploader/Shell/MainViewModel.cs @@ -346,7 +346,7 @@ public sealed class MainViewModel : LocalizedViewModel if (paths.Count == 0) return; if (_target == UploadTargetMode.Sequence && SelectedSequence is null) { - ShowToast(Loc.L("Uploader.Toast.ChooseSequence")); + ShowToast(Loc.L("Uploader.Toast.ChooseSequence"), isError: true); return; } var found = await Task.Run(() => PhotoScanner.Scan(paths)); @@ -394,7 +394,7 @@ public sealed class MainViewModel : LocalizedViewModel public void ReportError(Exception ex) { Log.Error("ui", "Operation failed", ex); - ShowToast(Loc.L("Errors.Unexpected"), Loc.L("Common.OpenLogs"), Loc.L("Tooltips.Common.OpenLogs"), new RelayCommand(OpenLogs)); + ShowToast(Loc.L("Errors.Unexpected"), Loc.L("Common.OpenLogs"), Loc.L("Tooltips.Common.OpenLogs"), new RelayCommand(OpenLogs), isError: true); } public void TogglePause() @@ -574,7 +574,8 @@ public sealed class MainViewModel : LocalizedViewModel /// One sentence plus one action (BRIEF §0.2 rule 6): "Sign in" takes the user to the password box. private void OnSessionEnded(object? sender, ServerProblem problem) => ShowToast(Loc.L(problem == ServerProblem.CertificateChanged ? "Uploader.Toast.CertificateChanged" : "Uploader.Toast.SignedOut"), - Loc.L("Uploader.Connect.SignIn"), Loc.L("Tooltips.Uploader.SignIn"), new RelayCommand(() => SignInRequested?.Invoke(this, EventArgs.Empty))); + Loc.L("Uploader.Connect.SignIn"), Loc.L("Tooltips.Uploader.SignIn"), new RelayCommand(() => SignInRequested?.Invoke(this, EventArgs.Empty)), + isError: true); private void OnDrained(object? sender, EventArgs e) { @@ -585,8 +586,9 @@ public sealed class MainViewModel : LocalizedViewModel if (confirmed > 0) UploadsCompleted?.Invoke(confirmed); } - private void ShowToast(string title, string? actionText = null, string? actionToolTip = null, ICommand? action = null) => - PendingToasts.Add(new Toast { Title = title, ActionText = actionText, ActionToolTip = actionToolTip, ActionCommand = action }); + /// One sentence and at most one action; marks a failure or refusal, which screen readers say at once. + private void ShowToast(string title, string? actionText = null, string? actionToolTip = null, ICommand? action = null, bool isError = false) => + PendingToasts.Add(new Toast { Title = title, ActionText = actionText, ActionToolTip = actionToolTip, ActionCommand = action, IsError = isError }); private void OpenLogs() { diff --git a/tests/Titano.App.Tests/Archive/ArchiveScreenSmokeTests.cs b/tests/Titano.App.Tests/Archive/ArchiveScreenSmokeTests.cs index 835fd41e..18af3c60 100644 --- a/tests/Titano.App.Tests/Archive/ArchiveScreenSmokeTests.cs +++ b/tests/Titano.App.Tests/Archive/ArchiveScreenSmokeTests.cs @@ -55,6 +55,8 @@ public sealed class ArchiveScreenSmokeTests AssertEveryButtonIsNamed(app); Assert.Contains(archive.SetText, AutomationProperties.GetName(SetButton(app))); foreach (var row in TreeItems(app)) Assert.NotNull(row.FocusVisualStyle, "a tree row shows keyboard focus"); + Assert.Equal(Loc.L("Archive.Tree.Collapse"), AutomationProperties.GetName(ButtonFor(app, archive.TreeRows[1].ToggleCommand)), + "the open year's expander has a short name; the sentence is its tooltip"); var sequence = archive.TreeRows.First(r => r.Node.Kind == TreeNodeKind.Sequence); Assert.Contains(sequence.Title, sequence.RowToolTip); diff --git a/tests/Titano.App.Tests/Editor/EditorSmokeTests.cs b/tests/Titano.App.Tests/Editor/EditorSmokeTests.cs index 613014b6..137b5ef2 100644 --- a/tests/Titano.App.Tests/Editor/EditorSmokeTests.cs +++ b/tests/Titano.App.Tests/Editor/EditorSmokeTests.cs @@ -1,3 +1,4 @@ +using System.Globalization; using System.Windows; using System.Windows.Controls; using System.Windows.Media; @@ -9,6 +10,7 @@ using Titano.App.Infrastructure; using Titano.App.Sections; using Titano.App.Shell; using Titano.App.Tests.Windows; +using Titano.Core.Advice; using Titano.Core.Export; using Titano.Core.Localization; using Titano.Core.Model; @@ -32,6 +34,26 @@ public sealed class EditorSmokeTests { private static readonly AppTheme[] Themes = [AppTheme.Dark, AppTheme.Light]; + /// Here rather than with the other texts: it switches the UI language, which only a serial class may do. + [Test] + public void AnOptimiseLinePointsFromTheOldValueToTheNewOneInEitherReadingDirection() + { + var change = new SettingChange(AdvisorParameters.DeflickerWindow, 21, 41, "reason", []); + try + { + Loc.SetCulture(CultureInfo.GetCultureInfo("en")); + Assert.Equal("Deflicker window: 21 frames → 41 frames", EditorText.Change(change)); + Loc.SetCulture(CultureInfo.GetCultureInfo("ar")); + Assert.Equal(Loc.L("Editor.Optimise.ChangeRtl", Loc.L("Editor.Exposure.Window"), Loc.Plural("Editor.Value.Frames", 21), Loc.Plural("Editor.Value.Frames", 41)), + EditorText.Change(change), "Arabic reads the old value first, from the right"); + Assert.Contains("←", EditorText.Change(change)); + } + finally + { + Loc.SetCulture(CultureInfo.GetCultureInfo("en")); + } + } + [Test] public Task EverySectionOfTheEditorRendersInBothThemes() => ScreenHost.RunAsync(async () => { diff --git a/tests/Titano.App.Tests/Uploader/UploaderScreenSmokeTests.cs b/tests/Titano.App.Tests/Uploader/UploaderScreenSmokeTests.cs index fd3c9230..19e25822 100644 --- a/tests/Titano.App.Tests/Uploader/UploaderScreenSmokeTests.cs +++ b/tests/Titano.App.Tests/Uploader/UploaderScreenSmokeTests.cs @@ -83,6 +83,12 @@ public sealed class UploaderScreenSmokeTests await screen.SettleAsync(); screen.AssertIconButtonsNamed("settings"); vm.IsSettingsOpen = false; + + // A failure interrupts the screen reader (assertive) instead of waiting its turn. + Toast? shown = null; + vm.PendingToasts.CollectionChanged += (_, e) => shown ??= e.NewItems?.OfType().FirstOrDefault(); + vm.ReportError(new InvalidOperationException("The queue file cannot be read")); + Assert.True(Assert.NotNull(shown).IsError, "an unexpected error is announced at once"); }); [Test] diff --git a/tests/Titano.App.Tests/Visuals/VisualsSmokeTests.cs b/tests/Titano.App.Tests/Visuals/VisualsSmokeTests.cs index 1f1ef2a9..1d45d857 100644 --- a/tests/Titano.App.Tests/Visuals/VisualsSmokeTests.cs +++ b/tests/Titano.App.Tests/Visuals/VisualsSmokeTests.cs @@ -1,10 +1,14 @@ using System.Collections.ObjectModel; using System.Diagnostics; +using System.Globalization; 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 System.Windows.Threading; +using Titano.Core.Localization; using Titano.Testing; using Titano.Ui.Controls; using Titano.Ui.Theming; @@ -127,6 +131,153 @@ public sealed class VisualsSmokeTests Assert.Equal(412, strip.CurrentIndex); }); + [Test] + public void ListsKeepTheirFillWhenDisabled() => WpfHost.Run(() => + { + var surface = ColorOf("Brush.Surface"); + foreach (var list in new[] { new ListBox(), new ListBox { Style = (Style)Application.Current.FindResource("ListBox.Cards") } }) + { + list.Background = (Brush)Application.Current.FindResource("Brush.Surface"); + list.ItemsSource = new[] { "Harbour sunset" }; + list.IsEnabled = false; + var bitmap = Render(list, 200, 100); + Assert.NotNull(VisualTreeHelper.GetChild(list, 0) as Border, "the theme's list frame"); + Assert.True(Near(PixelAt(bitmap, 100, 95), surface, 1), "a disabled list keeps its fill instead of the system's white"); + } + + // A list view keeps the system template, which carries the column headers. + var view = new ListView { ItemsSource = new[] { "Harbour sunset" }, View = new GridView { Columns = { new GridViewColumn { Header = "Title" } } } }; + Render(view, 200, 100); + Assert.NotNull(FindChild(view), "the column header row"); + }); + + [Test] + public void ChartLabelsAreMutedAndMonthsWithoutDataTakeTheStrokeTone() => WpfHost.Run(() => + { + foreach (var theme in new[] { AppTheme.Dark, AppTheme.Light }) + { + ThemeManager.Apply(theme); + var (muted, faint, stroke, card) = (ColorOf("Brush.TextMuted"), ColorOf("Brush.TextFaint"), ColorOf("Brush.Stroke"), ColorOf("Brush.Card")); + + // Zero values draw no bars: what remains is the labels. + var bars = Covered(Render(new BarChart { Items = [new ChartItem("Canon EOS R6", 0), new ChartItem("Nikon Z 8", 0)], ShowValues = false }, 300, 60)); + Assert.NotEmpty(bars); + Assert.True(bars.All(c => Near(c, muted)), $"bar labels are TextMuted in {theme}, not TextFaint ({faint})"); + + var months = new[] { "J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D" }; + var empty = new ChartRow("2027", Enumerable.Repeat(double.NaN, 12).ToArray()); + var heatmap = Covered(Render(new HeatmapStrip { Rows = [empty], ColumnLabels = months, ShowScale = false }, 400, 60)); + Assert.Contains(heatmap, c => Near(c, stroke)); + Assert.False(heatmap.Any(c => Near(c, card) && !Near(c, stroke)), $"months without data are not the card colour in {theme}"); + Assert.True(heatmap.All(c => Near(c, stroke) || Near(c, muted)), $"heatmap labels are TextMuted in {theme}"); + } + ThemeManager.Apply(AppTheme.Dark); + }); + + [Test] + public void ChartsTakeTheHandAndTheKeyboardOnlyWhileSomethingHandlesActivation() => WpfHost.Run(() => + { + var items = new[] { new ChartItem("2025", 2), new ChartItem("2026", 1) }; + var bars = new BarChart { Items = items }; + var stacked = new StackedBar { Items = items }; + var heatmap = new HeatmapStrip { Rows = [new ChartRow("2026", [1, 2, 3])], ColumnLabels = ["J", "F", "M"] }; + ChartItemEventHandler handler = (_, _) => { }; + var charts = new (DrawingElement Chart, Action Attach, Action Detach)[] + { + (bars, () => bars.ItemActivated += handler, () => bars.ItemActivated -= handler), + (stacked, () => stacked.ItemActivated += handler, () => stacked.ItemActivated -= handler), + (heatmap, () => heatmap.CellActivated += handler, () => heatmap.CellActivated -= handler), + }; + foreach (var (chart, attach, detach) in charts) + { + Render(chart, 300, 80); + var name = chart.GetType().Name; + Assert.False(ShowsHand(chart), $"{name}: no hand cursor while nothing handles a click"); + Assert.False(chart.Focusable, $"{name}: no tab stop while nothing handles Enter"); + attach(); + Assert.True(ShowsHand(chart), $"{name}: the hand over an item once a handler is attached"); + Assert.True(chart.Focusable, $"{name}: the keyboard reaches it once a handler is attached"); + detach(); + Assert.False(ShowsHand(chart), $"{name}: no hand once the handler is gone"); + Assert.False(chart.Focusable, $"{name}: no tab stop once the handler is gone"); + } + }); + + [Test] + public void TheKeyboardChoosesAndActivatesABar() => WpfHost.Run(() => + { + var bars = new BarChart { Items = [new ChartItem("2024", 3), new ChartItem("2025", 2), new ChartItem("2026", 1)] }; + var host = new Border { Child = bars }; + var window = new Window + { + Content = host, + Width = 320, + Height = 160, + WindowStyle = WindowStyle.None, + WindowStartupLocation = WindowStartupLocation.Manual, + Left = -20000, + Top = -20000, + ShowActivated = false, + ShowInTaskbar = false, + }; + window.Show(); + try + { + window.UpdateLayout(); + var bubbled = new List(); + host.AddHandler(BarChart.ItemActivatedEvent, new ChartItemEventHandler((_, e) => bubbled.Add(e.Row))); + Press(bars, Key.Enter); + Assert.Empty(bubbled, "Enter does nothing while no handler is attached to the chart"); + + var rows = new List(); + bars.ItemActivated += (_, e) => rows.Add(e.Row); + Press(bars, Key.Down); + Press(bars, Key.Down); + Press(bars, Key.Down); + Press(bars, Key.Enter); + Press(bars, Key.Home); + Press(bars, Key.Space); + Assert.SequenceEqual([2, 0], rows, "Down stops at the last bar; Home goes back to the first"); + Assert.Contains("2024", UIElementAutomationPeer.CreatePeerForElement(bars).GetItemStatus()); + } + finally + { + window.Close(); + } + }); + + [Test] + public void CategoryBarsStartOnTheReadingSideWhileMonthsKeepTheirOrder() => WpfHost.Run(() => + { + var accent = ColorOf("Brush.Accent"); + var culture = Loc.Culture; + try + { + foreach (var (language, rightToLeft) in new[] { ("en", false), ("ar", true) }) + { + Loc.SetCulture(CultureInfo.GetCultureInfo(language)); + // Rows 22 px apart: the short second bar (y 26–40) grows from the labels' side. + var bars = Render(new BarChart { Items = [new ChartItem("A", 4), new ChartItem("B", 1)], ShowValues = false }, 300, 44); + var (left, right) = Extent(bars, accent, 33); + Assert.True(rightToLeft ? left > 150 : right < 150 && right > 0, $"{language}: the short bar spans {left}–{right}"); + + // The largest segment comes first, on the reading side. + var stacked = Render(new StackedBar { Items = [new ChartItem("A", 3), new ChartItem("B", 1)], ShowLegend = false }, 300, 12); + (left, right) = Extent(stacked, accent, 6); + Assert.True(rightToLeft ? left > 60 && right >= 296 : left is >= 0 and <= 3 && right < 240, $"{language}: the first segment spans {left}–{right}"); + + // The full month (January) stays on the left: months are a time axis. + var months = Render(new HeatmapStrip { Rows = [new ChartRow("2026", [5, 0, 0, 0])], ColumnLabels = ["1", "2", "3", "4"], ShowScale = false }, 300, 60); + (left, right) = Extent(months, accent, 31); + Assert.True(left > 0 && right < 150, $"{language}: January spans {left}–{right}"); + } + } + finally + { + Loc.SetCulture(culture); + } + }); + private static IEnumerable<(string Name, FrameworkElement Element, double Width, double Height)> Samples() { var n = 120_000; @@ -235,6 +386,61 @@ public sealed class VisualsSmokeTests return bitmap; } + private static Color ColorOf(string key) => ((SolidColorBrush)Application.Current.FindResource(key)).Color; + + private static Color PixelAt(BitmapSource bitmap, int x, int y) + { + var pixel = new byte[4]; + bitmap.CopyPixels(new Int32Rect(x, y, 1, 1), pixel, 4, 0); + return Color.FromArgb(pixel[3], pixel[2], pixel[1], pixel[0]); + } + + /// The colours drawn at least two-thirds opaque, un-premultiplied: text edges keep the colour of their brush. + private static List Covered(BitmapSource bitmap) + { + var stride = bitmap.PixelWidth * 4; + var pixels = new byte[stride * bitmap.PixelHeight]; + bitmap.CopyPixels(pixels, stride, 0); + var colours = new List(); + for (var i = 0; i < pixels.Length; i += 4) + { + var a = pixels[i + 3]; + if (a < 170) continue; + colours.Add(Color.FromRgb((byte)(pixels[i + 2] * 255 / a), (byte)(pixels[i + 1] * 255 / a), (byte)(pixels[i] * 255 / a))); + } + return colours; + } + + private static bool Near(Color a, Color b, int tolerance = 12) => + Math.Abs(a.R - b.R) <= tolerance && Math.Abs(a.G - b.G) <= tolerance && Math.Abs(a.B - b.B) <= tolerance; + + /// First and last x of row drawn in at full opacity; (−1, −1) when none. + private static (int Left, int Right) Extent(BitmapSource bitmap, Color colour, int y) + { + var (left, right) = (-1, -1); + for (var x = 0; x < bitmap.PixelWidth; x++) + { + var pixel = PixelAt(bitmap, x, y); + if (pixel.A != 255 || !Near(pixel, colour, 2)) continue; + if (left < 0) left = x; + right = x; + } + return (left, right); + } + + private static bool ShowsHand(DrawingElement chart) + { + for (var y = 0.0; y < chart.ActualHeight; y += 2) + { + for (var x = 0.0; x < chart.ActualWidth; x += 2) + if (chart.CursorAt(new Point(x, y)) == Cursors.Hand) return true; + } + return false; + } + + private static void Press(UIElement target, Key key) => + target.RaiseEvent(new KeyEventArgs(Keyboard.PrimaryDevice, PresentationSource.FromVisual(target)!, 0, key) { RoutedEvent = Keyboard.KeyDownEvent }); + private static RenderTargetBitmap Render(FrameworkElement element, double width, double height) { var host = Host(element); diff --git a/tests/Titano.App.Tests/Windows/ScreenSmokeTests.cs b/tests/Titano.App.Tests/Windows/ScreenSmokeTests.cs index 97909a98..24e5cb69 100644 --- a/tests/Titano.App.Tests/Windows/ScreenSmokeTests.cs +++ b/tests/Titano.App.Tests/Windows/ScreenSmokeTests.cs @@ -1,8 +1,10 @@ +using System.IO; 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.Input; using System.Windows.Media; using System.Windows.Media.Imaging; @@ -197,6 +199,12 @@ public sealed class ScreenSmokeTests await app.ExpectAsync("library-toast-done"); Assert.True(ran, "the action ran"); Assert.Equal(0, host.Toasts.Count, "the toast closes once its action has run"); + + // A failure interrupts the screen reader (assertive); a notice waits its turn. + Assert.False(await ArchiveActions.TryAsync(app.Shell, _ => throw new IOException("The archive drive is gone"))); + Assert.True(host.Toasts.Single().IsError, "a failed archive action is announced at once"); + app.Shell.Notify("Harbour sunset rendered"); + Assert.False(host.Toasts[^1].IsError, "a notice is announced in turn"); }); [Test] @@ -210,6 +218,9 @@ public sealed class ScreenSmokeTests Assert.Equal(Loc.L("Tooltips.Window.Minimize"), AutomationProperties.GetName(captions.Single(b => b.Command == SystemCommands.MinimizeWindowCommand))); Assert.Equal(Loc.L("Tooltips.Window.Maximize"), AutomationProperties.GetName(captions.Single(b => b.Command == SystemCommands.MaximizeWindowCommand))); Assert.Equal(Loc.L("Tooltips.Window.Close"), AutomationProperties.GetName(captions.Single(b => b.Command == SystemCommands.CloseWindowCommand))); + var railToggle = Descendants