From edd530cb4bf7748d0e98d0db3d69d02e3e81a95f Mon Sep 17 00:00:00 2001 From: maj00r Date: Sun, 15 Nov 2026 18:45:06 +0100 Subject: [PATCH] fix: NVDA says the section focus enters, a setting's explanation and each fog step NVDA passes over a group that is not content as well as control, so titled panels and the landmarks are now both. A setting's explanation and the note on why the simulator ignores it are read after its name. The key under each setting is no longer a silent stop for Tab, and a step of the fog slider moves the shown distance. --- StarterNG.Tests/AnnouncerTests.cs | 3 +- StarterNG.Tests/ScreenReaderNamesTests.cs | 28 ++++++++++++++ StarterNG/Controls/ScreenReaderNames.cs | 46 ++++++++++++++++++++++- StarterNG/Controls/SettingRow.cs | 5 +++ StarterNG/MainWindow.axaml | 4 +- StarterNG/Styles/Settings.axaml | 4 +- StarterNG/Views/Scenarios.axaml | 2 +- 7 files changed, 86 insertions(+), 6 deletions(-) diff --git a/StarterNG.Tests/AnnouncerTests.cs b/StarterNG.Tests/AnnouncerTests.cs index 07a9c57..d011f67 100644 --- a/StarterNG.Tests/AnnouncerTests.cs +++ b/StarterNG.Tests/AnnouncerTests.cs @@ -92,7 +92,7 @@ public class NamedGroupTests Assert.Equal("Scenerie", AutomationProperties.GetName(panel)); Assert.Equal(AutomationControlType.Group, AutomationProperties.GetControlTypeOverride(panel)); - Assert.True(AutomationProperties.GetIsControlElementOverride(panel)); + Assert.Equal(AccessibilityView.Content, AutomationProperties.GetAccessibilityView(panel)); } [Fact] @@ -103,6 +103,7 @@ public class NamedGroupTests Assert.Null(AutomationProperties.GetName(panel)); Assert.Null(AutomationProperties.GetControlTypeOverride(panel)); + Assert.Equal(AccessibilityView.Default, AutomationProperties.GetAccessibilityView(panel)); } [Fact] diff --git a/StarterNG.Tests/ScreenReaderNamesTests.cs b/StarterNG.Tests/ScreenReaderNamesTests.cs index 8473be7..b4aad90 100644 --- a/StarterNG.Tests/ScreenReaderNamesTests.cs +++ b/StarterNG.Tests/ScreenReaderNamesTests.cs @@ -141,6 +141,34 @@ public class ScreenReaderNamesTests Assert.Null(AutomationProperties.GetName(browse)); } + [Fact] + public void A_setting_row_describes_its_inputs_with_its_explanation() + { + var check = new CheckBox { Content = "Tryb pełnoekranowy" }; + var slider = new Slider(); + var row = new SettingRow { Label = "Ekran", Content = Row(check, slider) }; + row.Description = "Gra zajmie cały ekran."; + row.IdleNote = "Ten symulator nie zna tego ustawienia."; + + Assert.Equal("Gra zajmie cały ekran., Ten symulator nie zna tego ustawienia.", AutomationProperties.GetHelpText(check)); + Assert.Equal(AutomationProperties.GetHelpText(check), AutomationProperties.GetHelpText(slider)); + Assert.Null(AutomationProperties.GetName(check)); + + row.Description = null; + row.IdleNote = null; + Assert.Null(AutomationProperties.GetHelpText(check)); + } + + [Fact] + public void A_description_given_on_purpose_is_left_alone() + { + var box = new TextBox(); + AutomationProperties.SetHelpText(box, "Ścieżka do exe"); + _ = new SettingRow { Content = box, Description = "Plik symulatora" }; + + Assert.Equal("Ścieżka do exe", AutomationProperties.GetHelpText(box)); + } + [Fact] public void A_setting_row_without_a_label_leaves_its_input_unnamed() { diff --git a/StarterNG/Controls/ScreenReaderNames.cs b/StarterNG/Controls/ScreenReaderNames.cs index c77bb76..3d50681 100644 --- a/StarterNG/Controls/ScreenReaderNames.cs +++ b/StarterNG/Controls/ScreenReaderNames.cs @@ -154,12 +154,47 @@ public static class ScreenReaderNames string? name = TextOf(panel.Header); Give(panel, name); AutomationProperties.SetControlTypeOverride(panel, name is null ? null : AutomationControlType.Group); - AutomationProperties.SetIsControlElementOverride(panel, name is null ? null : true); + // Content as well as control: NVDA passes over a group that is not both. + AutomationProperties.SetAccessibilityView(panel, name is null ? AccessibilityView.Default : AccessibilityView.Content); } private static void NameButton(Button button) => Give(button, button.Content is string ? null : TextOf(ToolTip.GetTip(button)) ?? TextOf(button.Content)); + // The descriptions given here, so a later one replaces it but nothing else. + private static readonly ConditionalWeakTable Described = new(); + + /// + /// The inputs of a setting row, described by the row's explanation and the note on + /// why the simulator would pass it over: a reader hears them after the name, where + /// a sighted one sees them under it. + /// + public static void DescribeInputs(object? content, params string?[] notes) + { + string? text = Join(notes) is { Length: > 0 } joined ? joined : null; + foreach (var input in DescribedInputs(content)) + Describe(input, text); + } + + private static void Describe(StyledElement target, string? text) + { + string? current = AutomationProperties.GetHelpText(target); + bool ours = Described.TryGetValue(target, out string? given) && current == given; + if (!string.IsNullOrEmpty(current) && !ours) + return; + + if (string.IsNullOrEmpty(text)) + { + if (ours) + target.ClearValue(AutomationProperties.HelpTextProperty); + Described.Remove(target); + return; + } + + AutomationProperties.SetHelpText(target, text); + Described.AddOrUpdate(target, text); + } + /// /// The inputs of a setting row, named by the row's label: a list, a slider or a box /// beside the label otherwise had no name at all. @@ -188,6 +223,15 @@ public static class ScreenReaderNames _ => Array.Empty() }; + // A check box says its own text, so it is described but never named by the row. + private static IEnumerable DescribedInputs(object? content) => content switch + { + CheckBox box => new[] { (Control)box }, + Panel panel => panel.Children.SelectMany(DescribedInputs), + Decorator decorator => DescribedInputs(decorator.Child), + _ => Inputs(content) + }; + /// The text a reader would see on it, or null when it shows none. public static string? TextOf(object? content) { diff --git a/StarterNG/Controls/SettingRow.cs b/StarterNG/Controls/SettingRow.cs index 5db77fe..5c912ef 100644 --- a/StarterNG/Controls/SettingRow.cs +++ b/StarterNG/Controls/SettingRow.cs @@ -80,6 +80,10 @@ public class SettingRow : ContentControl if (change.Property == ValueTextProperty || change.Property == ContentProperty) ScreenReaderNames.TellValue(Content, ValueText); + + if (change.Property == DescriptionProperty || change.Property == IdleNoteProperty || + change.Property == ContentProperty) + ScreenReaderNames.DescribeInputs(Content, Description, IdleNote); } // Again once in the window: a panel given as content may be filled after it was set. @@ -88,6 +92,7 @@ public class SettingRow : ContentControl base.OnLoaded(e); ScreenReaderNames.NameInputs(Content, Label); ScreenReaderNames.TellValue(Content, ValueText); + ScreenReaderNames.DescribeInputs(Content, Description, IdleNote); } private void UpdatePseudoClasses() diff --git a/StarterNG/MainWindow.axaml b/StarterNG/MainWindow.axaml index 36aef47..017b352 100644 --- a/StarterNG/MainWindow.axaml +++ b/StarterNG/MainWindow.axaml @@ -27,7 +27,7 @@ - + - diff --git a/StarterNG/Styles/Settings.axaml b/StarterNG/Styles/Settings.axaml index dc938c0..6e238bc 100644 --- a/StarterNG/Styles/Settings.axaml +++ b/StarterNG/Styles/Settings.axaml @@ -61,8 +61,10 @@ with no label hides PART_Label, and without this the column would collapse onto the key and every explanation would start at a different place again. --> +