Files
StarterNG/StarterNG/Views/MenuItems.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

39 lines
1.4 KiB
C#

using System;
using Avalonia.Controls;
using Avalonia.Input;
namespace StarterNG.Views;
/// <summary>A menu entry that runs something when clicked, as nearly all of them do.</summary>
internal static class MenuItems
{
/// <param name="header">The text, or a control where a row holds more than that.</param>
public static MenuItem Item(object header, Action run, bool enabled = true, KeyGesture? gesture = null)
{
var item = new MenuItem { Header = header, IsEnabled = enabled, InputGesture = gesture };
item.Click += (_, _) => run();
return item;
}
/// <summary>
/// One of a set of entries of which one is chosen, marked as a radio entry. A dot
/// written before the text was read out as "black circle" and told no state.
/// </summary>
public static MenuItem Choice(string header, bool chosen, Action run)
{
var item = Item(header, run);
item.ToggleType = MenuItemToggleType.Radio;
item.IsChecked = chosen;
return item;
}
/// <summary>The entry at the end of a menu or a submenu.</summary>
public static MenuItem AddItem(this ItemsControl menu, object header, Action run, bool enabled = true,
KeyGesture? gesture = null)
{
var item = Item(header, run, enabled, gesture);
menu.Items.Add(item);
return item;
}
}