fix: nothing under the mouse is silent: dividers, previews, class pictures, categories

A page swept point by point left a few places a reader heard nothing: the panel
dividers, the vehicle preview in the depot and the texture base, the picture by
a vehicle class and the empty part of the settings categories. Each now has a
name; a picture with a caption beside it reads as the caption.

The tests that build controls run one after another: a control belongs to the
thread that made the first one, and side by side they now and then failed.
This commit is contained in:
maj00r
2026-11-15 20:01:25 +01:00
parent 184629b544
commit ee6da4c8ee
19 changed files with 65 additions and 7 deletions

View File

@@ -6,6 +6,7 @@ using StarterNG.Controls;
namespace StarterNG.Tests;
[Collection(AvaloniaControls.Name)]
public class AnnouncerTests
{
private DateTime _now = new(2026, 11, 15, 12, 0, 0, DateTimeKind.Utc);
@@ -81,6 +82,7 @@ public class AnnouncerTests
}
}
[Collection(AvaloniaControls.Name)]
public class NamedGroupTests
{
static NamedGroupTests() => ScreenReaderNames.Install();

View File

@@ -0,0 +1,11 @@
namespace StarterNG.Tests;
/// <summary>
/// Tests that build Avalonia controls run one after another: a control belongs to the
/// thread that made the first one, and run side by side they now and then failed.
/// </summary>
[CollectionDefinition(Name)]
public sealed class AvaloniaControls
{
public const string Name = "Avalonia controls";
}

View File

@@ -5,6 +5,7 @@ using StarterNG.Controls;
namespace StarterNG.Tests;
[Collection(AvaloniaControls.Name)]
public class ExpandableTreeViewItemTests
{
private static IExpandCollapseProvider Peer(ExpandableTreeViewItem item) =>

View File

@@ -4,6 +4,7 @@ using StarterNG.Controls;
namespace StarterNG.Tests;
[Collection(AvaloniaControls.Name)]
public class FieldLabelTests
{
static FieldLabelTests() => ScreenReaderNames.Install();

View File

@@ -4,6 +4,7 @@ using StarterNG.Controls;
namespace StarterNG.Tests;
[Collection(AvaloniaControls.Name)]
public class KeyboardFocusTests
{
private readonly Button _window = new();

View File

@@ -5,6 +5,7 @@ using StarterNG.Infrastructure;
namespace StarterNG.Tests;
[Collection(AvaloniaControls.Name)]
public class MouseReadingTests
{
static MouseReadingTests() => ScreenReaderNames.Install();
@@ -20,6 +21,18 @@ public class MouseReadingTests
Assert.Same(button, AutomationProperties.GetLabeledBy(logo));
}
[Fact]
public void A_picture_beside_a_caption_is_read_as_the_caption()
{
var mini = new Image();
var caption = new TextBlock { Text = "EU07" };
_ = new StackPanel { Children = { mini, new TextBlock { IsVisible = false, Text = "ukryte" }, caption } };
ScreenReaderNames.NamePicture(mini);
Assert.Same(caption, AutomationProperties.GetLabeledBy(mini));
}
[Fact]
public void A_picture_in_a_card_is_read_as_the_card_tooltip()
{

View File

@@ -7,6 +7,7 @@ using StarterNG.Controls;
namespace StarterNG.Tests;
[Collection(AvaloniaControls.Name)]
public class ReadableSliderTests
{
[Fact]

View File

@@ -6,6 +6,7 @@ using StarterNG.Controls;
namespace StarterNG.Tests;
[Collection(AvaloniaControls.Name)]
public class ScreenReaderNamesTests
{
static ScreenReaderNamesTests() => ScreenReaderNames.Install();
@@ -188,6 +189,7 @@ public class ScreenReaderNamesTests
}
}
[Collection(AvaloniaControls.Name)]
public class PickerNameTests
{
[Fact]

View File

@@ -166,7 +166,7 @@ public static class ScreenReaderNames
private const int PictureReach = 3;
/// <summary>
/// Names a picture after the button or card it lies in. Under the mouse a reader
/// Names a picture after the caption beside it or the button or card it lies in. Under the mouse a reader
/// hears what lies there, and a bare picture said nothing: a vehicle in the consist,
/// the logo, an icon on a button.
/// </summary>
@@ -176,6 +176,14 @@ public static class ScreenReaderNames
|| AutomationProperties.GetLabeledBy(picture) is not null)
return;
// A caption beside it says what it shows, such as a vehicle class by its picture.
if (picture.Parent is Panel row
&& row.Children.OfType<TextBlock>().FirstOrDefault(t => t.IsVisible && !string.IsNullOrWhiteSpace(t.Text)) is { } caption)
{
AutomationProperties.SetLabeledBy(picture, caption);
return;
}
var holder = picture.Parent as Control;
for (int i = 0; i < PictureReach && holder is not null; i++, holder = holder.Parent as Control)
{

View File

@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Avalonia;
using Avalonia.Automation;
using Avalonia.Controls;
using Avalonia.Controls.Templates;
using Avalonia.Input;
@@ -338,6 +339,7 @@ public sealed class VehicleBrowser
Selected = null;
miniPreview.Source = null;
miniPreview.ClearValue(AutomationProperties.NameProperty);
addVehicleButton.IsEnabled = false;
vehicleListBox.Items.Clear();
@@ -381,10 +383,12 @@ public sealed class VehicleBrowser
public void VehicleListBox_OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
{
if (vehicleListBox.SelectedItem is ListBoxItem { Tag: VehicleTexture texture })
if (vehicleListBox.SelectedItem is ListBoxItem { Tag: VehicleTexture texture } row)
{
Selected = texture;
miniPreview.Source = _minis.Get(_db.ResolveMiniName(texture), MiniPreviewHeight);
// Under the mouse a reader hears which vehicle the picture shows.
AutomationProperties.SetName(miniPreview, ScreenReaderNames.TextOf(row.Content));
addVehicleButton.IsEnabled = true;
SyncCombosTo(texture);
@@ -397,6 +401,7 @@ public sealed class VehicleBrowser
{
Selected = null;
miniPreview.Source = null;
miniPreview.ClearValue(AutomationProperties.NameProperty);
addVehicleButton.IsEnabled = false;
}
}

View File

@@ -51,7 +51,7 @@
</DockPanel>
</HeaderedContentControl>
<GridSplitter IsTabStop="False" Grid.Column="1" Grid.Row="0" Width="6"
<GridSplitter IsTabStop="False" AutomationProperties.Name="{Binding [PanelSplitter], Source={x:Static starterNg:App.Loc}}" Grid.Column="1" Grid.Row="0" Width="6"
Background="Transparent" ResizeDirection="Columns" />
<Grid Grid.Column="2" Grid.Row="0">
@@ -76,7 +76,7 @@
SelectionChanged="VehicleList_OnSelectionChanged" />
</HeaderedContentControl>
<GridSplitter IsTabStop="False" Grid.Row="1" Height="4" HorizontalAlignment="Stretch"
<GridSplitter IsTabStop="False" AutomationProperties.Name="{Binding [PanelSplitter], Source={x:Static starterNg:App.Loc}}" Grid.Row="1" Height="4" HorizontalAlignment="Stretch"
Background="Transparent" ResizeDirection="Rows" />
<TabControl Grid.Row="2" Name="infoTabs">

View File

@@ -69,7 +69,7 @@
Click="ExportIniButton_OnClick" />
</StackPanel>
<ListBox x:Name="CategoryList" AutomationProperties.LandmarkType="Navigation" Classes="SettingsNav" SelectedIndex="0"
<ListBox x:Name="CategoryList" AutomationProperties.LandmarkType="Navigation" AutomationProperties.Name="{Binding [SettingsCategories], Source={x:Static starterNg:App.Loc}}" Classes="SettingsNav" SelectedIndex="0"
ItemContainerTheme="{StaticResource SettingsNavItem}"
SelectionChanged="CategoryList_OnSelectionChanged">
<ListBoxItem Tag="general" Content="{Binding [General], Source={x:Static starterNg:App.Loc}}" />

View File

@@ -77,7 +77,7 @@
<Grid RowDefinitions="Auto,*,4,Auto,*,Auto,Auto">
<TextBlock Grid.Row="0" Classes="Heading" Text="{Binding [Category], Source={x:Static starterNg:App.Loc}}" />
<ListBox Name="categoryList" Grid.Row="1" Classes="Compact" />
<GridSplitter IsTabStop="False" Grid.Row="2" Height="4" HorizontalAlignment="Stretch"
<GridSplitter IsTabStop="False" AutomationProperties.Name="{Binding [PanelSplitter], Source={x:Static starterNg:App.Loc}}" Grid.Row="2" Height="4" HorizontalAlignment="Stretch"
Background="Transparent" ResizeDirection="Rows" />
<TextBlock Grid.Row="3" Classes="Heading" Text="{Binding [Class], Source={x:Static starterNg:App.Loc}}" />
<ListBox Name="classList" Grid.Row="4" Classes="Compact">
@@ -97,7 +97,7 @@
</Grid>
</Border>
<GridSplitter IsTabStop="False" Grid.Column="1" Width="3" Background="Transparent" ResizeDirection="Columns" />
<GridSplitter IsTabStop="False" AutomationProperties.Name="{Binding [PanelSplitter], Source={x:Static starterNg:App.Loc}}" Grid.Column="1" Width="3" Background="Transparent" ResizeDirection="Columns" />
<Border Grid.Column="2" Classes="Panel">
<Grid RowDefinitions="Auto,*">

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Avalonia.Automation;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
@@ -180,6 +181,7 @@ public partial class VehicleBaseWindow : Window
if (row is null)
{
preview.Source = null;
preview.ClearValue(AutomationProperties.NameProperty);
detailTitle.Text = "";
detailText.Text = App.Loc["TextureBasePick"];
ToolTip.SetTip(detailText, null);
@@ -188,6 +190,7 @@ public partial class VehicleBaseWindow : Window
preview.Source = _minis.Get(_db.ResolveMiniName(row.Texture), PreviewHeight);
detailTitle.Text = string.Join(" · ", new[] { row.Skin, row.Class, row.Operator }.Where(s => s.Length > 0));
AutomationProperties.SetName(preview, detailTitle.Text);
var lines = new[]
{

View File

@@ -568,6 +568,8 @@
<String key="TreeExpanded">rozbaleno</String>
<String key="TreeCollapsed">sbaleno</String>
<String key="SceneryImage">Obrázek scenérie</String>
<String key="PanelSplitter">Oddělovač panelů</String>
<String key="SettingsCategories">Kategorie nastavení</String>
<String key="SettingsNotSaved">Nastavení se nepodařilo uložit</String>
<String key="UnsavedChanges">Neuložené změny</String>

View File

@@ -594,6 +594,8 @@
<String key="TreeExpanded">expanded</String>
<String key="TreeCollapsed">collapsed</String>
<String key="SceneryImage">Scenery picture</String>
<String key="PanelSplitter">Panel divider</String>
<String key="SettingsCategories">Settings categories</String>
<String key="SettingsNotSaved">Could not save the settings</String>
<String key="UnsavedChanges">Unsaved changes</String>

View File

@@ -568,6 +568,8 @@
<String key="TreeExpanded">kibontva</String>
<String key="TreeCollapsed">összecsukva</String>
<String key="SceneryImage">A pálya képe</String>
<String key="PanelSplitter">Panelelválasztó</String>
<String key="SettingsCategories">Beállítási kategóriák</String>
<String key="SettingsNotSaved">A beállításokat nem sikerült elmenteni</String>
<String key="UnsavedChanges">Nem mentett módosítások</String>

View File

@@ -594,6 +594,8 @@
<String key="TreeExpanded">rozwinięte</String>
<String key="TreeCollapsed">zwinięte</String>
<String key="SceneryImage">Obraz scenerii</String>
<String key="PanelSplitter">Rozdzielacz paneli</String>
<String key="SettingsCategories">Kategorie ustawień</String>
<String key="SettingsNotSaved">Nie udało się zapisać ustawień</String>
<String key="UnsavedChanges">Niezapisane zmiany</String>

View File

@@ -568,6 +568,8 @@
<String key="TreeExpanded">развёрнуто</String>
<String key="TreeCollapsed">свёрнуто</String>
<String key="SceneryImage">Изображение сценерии</String>
<String key="PanelSplitter">Разделитель панелей</String>
<String key="SettingsCategories">Категории настроек</String>
<String key="SettingsNotSaved">Не удалось сохранить настройки</String>
<String key="UnsavedChanges">Несохранённые изменения</String>