Files
StarterNG/StarterNG/Views/LogAndToolsWindow.cs
maj00r ff5228555e fix: a blind player can bind keys, build a consist and read the tapes
A review against WCAG 2.2 AA left places a screen reader user could not work:

- Key bindings: a key's button says the command and the key, the clear button
  which command it clears; a new key is said aloud and focus comes back to its
  row. The on-screen keyboard is reached with Tab and walked with the arrows.
- Number fields read their label; the spin buttons are named and left out of Tab.
- Dialogs: Enter presses the main button, Esc closes, focus starts on the first
  button and the message is read with it.
- Consist: every change is said - added, removed, turned, moved, replaced,
  undone - and the strip is a named list; a turned card says so.
- Searches say how many entries are left once typing pauses.
- Hasler tapes, the black box timeline, timetable and cab panel take focus, work
  from the keyboard, read their value as it changes and draw a focus frame.
- Section reset and level controls, the crew button and the tabs carry names;
  English names from Avalonia's templates are read in the starter's language;
  sort and crew menus are radio items.
- Input borders reach 3:1 against the panels; Tab starts at the top bar; the
  splash screen has a title and its progress reads the loading step.
2026-11-15 20:46:55 +01:00

108 lines
3.5 KiB
C#

using System;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Layout;
using Avalonia.Media;
using StarterNG.Infrastructure;
namespace StarterNG.Views;
/// <summary>
/// The starter's event log and the bulk depot tools. The options it used to carry
/// live in the Advanced category of the settings now, where they are found.
/// </summary>
public sealed class LogAndToolsWindow : Window
{
private readonly TextBox _log = new()
{
IsReadOnly = true,
AcceptsReturn = true,
TextWrapping = TextWrapping.NoWrap,
FontFamily = MonoFont.Family,
FontSize = 12
};
public event Action<string>? ToolRequested;
public LogAndToolsWindow()
{
Title = App.Loc["LogAndTools"];
Width = 620;
Height = 470;
MinWidth = 480;
MinHeight = 360;
WindowStartupLocation = WindowStartupLocation.CenterOwner;
var tabs = new TabControl();
Avalonia.Automation.AutomationProperties.SetName(tabs, App.Loc["LogAndTools"]);
tabs.Items.Add(new TabItem { Header = App.Loc["AdvLogPage"], Content = BuildLogPage() });
tabs.Items.Add(new TabItem { Header = App.Loc["Tools"], Content = BuildToolsPage() });
var close = new Button
{
Content = App.Loc["Close"],
MinWidth = 100,
HorizontalAlignment = HorizontalAlignment.Right,
Margin = new Avalonia.Thickness(0, 8, 0, 0),
Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Hand)
};
close.Classes.Add("Accent");
close.Click += (_, _) => Close();
close.IsCancel = true;
var root = new DockPanel { Margin = new Avalonia.Thickness(10) };
DockPanel.SetDock(close, Dock.Bottom);
root.Children.Add(close);
root.Children.Add(tabs);
Content = root;
}
private Control BuildLogPage()
{
_log.Text = Diagnostics.Text;
var clear = new Button
{
Content = App.Loc["AdvClearLog"],
Margin = new Avalonia.Thickness(0, 8, 0, 0),
HorizontalAlignment = HorizontalAlignment.Left,
Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Hand)
};
clear.Classes.Add("Flat");
clear.Click += (_, _) => { Diagnostics.Clear(); _log.Text = ""; };
ScrollViewer.SetHorizontalScrollBarVisibility(_log, ScrollBarVisibility.Auto);
ScrollViewer.SetVerticalScrollBarVisibility(_log, ScrollBarVisibility.Auto);
var panel = new DockPanel { Margin = new Avalonia.Thickness(8) };
DockPanel.SetDock(clear, Dock.Bottom);
panel.Children.Add(clear);
panel.Children.Add(_log);
return panel;
}
private Control BuildToolsPage()
{
var sp = new StackPanel { Margin = new Avalonia.Thickness(10), Spacing = 8 };
Button Tool(string key, string tag)
{
var b = new Button
{
Content = App.Loc[key],
HorizontalAlignment = HorizontalAlignment.Stretch,
HorizontalContentAlignment = HorizontalAlignment.Center,
Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Hand)
};
b.Classes.Add("Flat");
b.Click += (_, _) => ToolRequested?.Invoke(tag);
return b;
}
sp.Children.Add(Tool("AddAllCategory", "category"));
sp.Children.Add(Tool("AddUniqueMmd", "mmd"));
sp.Children.Add(Tool("RemoveAllTrains", "removeall"));
return sp;
}
}