n18ui 0.1.0

GUI for constructing 18xx maps and finding optimal routes.
Documentation

Provides a user interface for managing 18xx game maps and calculating the optimal revenue for each company.

See the rusty_train binary for an example of using this crate.

Overview

The [UserInterface] struct encapsulates map drawing and event handling. It is divided into several components:

  • [Assets]: the current [Map] and the available [Games].
  • [Canvas]: the surface on which the map is drawn.
  • [State]: the current user interface state (or "mode"), which defines the actions available to the user and how the map is drawn.
  • [Keymap]: responds to keyboard and mouse input by triggering state actions.
  • [Controller]: manages user interface elements and collects input from the user (e.g., selecting a game file to load or save).

Events and event handlers

There are three types of events that [UserInterface] handles:

  • Mouse button events, which are described by [ButtonPress] structs and are handled by [UserInterface::handle_button_press].

  • Keyboard events, which are described by [KeyPress] structs and are handled by [UserInterface::handle_key_press].

  • "Ping" events, which are triggered by something else (e.g., a message from a task running in a separate thread) and are handled by [UserInterface::ping]. Pings can be sent using a [PingSender], which can be obtained by calling Controller::ping_tx.

Note that event details, such as key identifiers, are defined by the [ButtonPress] and [KeyPress] structs, which use types from the GDK 3 library.

Responses to event handlers

Each of the [UserInterface] event handlers (listed above) return a [UiResponse] value, which indicates what actions the [UserInterface] should take (if any) once the event has been handled. These actions are performed by [UserInterface::respond].