Expand description
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.
Modules§
- canvas
- Manage drawing surfaces.
- control
- Control UI elements.
- keymap
- Response to keyboard and mouse events.
- state
- The different states of the user interface.
Structs§
- Assets
- Defines the non-UI game state components.
- Button
Press - Describes a mouse button being clicked.
- Canvas
- Games
- Ordered collections of available games.
- KeyPress
- Describes a keyboard key being pressed.
- Keymap
- UiAction
- Global UI actions, which are not specific to the current State.
- User
Interface - Defines the user interface.
Enums§
- Controller
- Ping
Dest - Identify which part of the UI should respond to a “ping”.
- Ping
Sender - State
- The different user interface states.
- UiResponse
- UI responses that may be required when the UI state changes.
Traits§
- UiController
- UiState
- The methods that are required in order to manipulate the user interface.