Files
StarterNG/StarterNG/Controls/SettingRow.cs
maj00r a83bb4a7eb fix: a screen reader names every control and Tab survives adding a vehicle
NVDA read icon buttons as "Material.Icons.Avalonia.MaterialIcon" and the
sceneries in the tree as nothing. Icon buttons are now named by their
tooltip, list and tree entries by the text they show, fields by the hint in
them, and the inputs of a setting row by its label. The lists, the tree and
the language and profile pickers have names, and a consist card says its
place and vehicles.

Adding a vehicle rebuilt the browser list and switched the add button off
for a moment, and focus fell out of the window: Tab did nothing until
something was clicked. Focus goes back to the button or the list, and Tab
with nothing focused starts from the first control. The splitters are no
longer Tab stops.
2026-11-15 17:40:51 +01:00

99 lines
3.2 KiB
C#

using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
namespace StarterNG.Controls;
public class SettingRow : ContentControl
{
public static readonly StyledProperty<string?> LabelProperty =
AvaloniaProperty.Register<SettingRow, string?>(nameof(Label));
public static readonly StyledProperty<string?> DescriptionProperty =
AvaloniaProperty.Register<SettingRow, string?>(nameof(Description));
public static readonly StyledProperty<string?> ConfigKeyProperty =
AvaloniaProperty.Register<SettingRow, string?>(nameof(ConfigKey));
public static readonly StyledProperty<string?> ValueTextProperty =
AvaloniaProperty.Register<SettingRow, string?>(nameof(ValueText));
/// <summary>
/// Why the simulator to be started would pass this setting over; the row dims
/// and says so. The input stays usable - the file may serve another build.
/// </summary>
public static readonly StyledProperty<string?> IdleNoteProperty =
AvaloniaProperty.Register<SettingRow, string?>(nameof(IdleNote));
public string? Label
{
get => GetValue(LabelProperty);
set => SetValue(LabelProperty, value);
}
public string? Description
{
get => GetValue(DescriptionProperty);
set => SetValue(DescriptionProperty, value);
}
public string? ConfigKey
{
get => GetValue(ConfigKeyProperty);
set => SetValue(ConfigKeyProperty, value);
}
public string? ValueText
{
get => GetValue(ValueTextProperty);
set => SetValue(ValueTextProperty, value);
}
public string? IdleNote
{
get => GetValue(IdleNoteProperty);
set => SetValue(IdleNoteProperty, value);
}
public SettingRow()
{
UpdatePseudoClasses();
}
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);
if (change.Property == LabelProperty ||
change.Property == DescriptionProperty ||
change.Property == ConfigKeyProperty ||
change.Property == ValueTextProperty ||
change.Property == IdleNoteProperty ||
change.Property == ContentProperty)
UpdatePseudoClasses();
if (change.Property == IdleNoteProperty)
ToolTip.SetTip(this, string.IsNullOrEmpty(IdleNote) ? null : IdleNote);
if (change.Property == LabelProperty || change.Property == ContentProperty)
ScreenReaderNames.NameInputs(Content, Label);
}
// Again once in the window: a panel given as content may be filled after it was set.
protected override void OnLoaded(RoutedEventArgs e)
{
base.OnLoaded(e);
ScreenReaderNames.NameInputs(Content, Label);
}
private void UpdatePseudoClasses()
{
PseudoClasses.Set(":no-label", string.IsNullOrEmpty(Label));
PseudoClasses.Set(":no-description", string.IsNullOrEmpty(Description));
PseudoClasses.Set(":no-key", string.IsNullOrEmpty(ConfigKey));
PseudoClasses.Set(":no-value", string.IsNullOrEmpty(ValueText));
PseudoClasses.Set(":no-content", Content is null);
PseudoClasses.Set(":idle", !string.IsNullOrEmpty(IdleNote));
}
}