TouchControls class final
A thumb stick and some buttons, drawn over a game that has no keyboard, with numbered slots and switches where a game has them.
The third translator, beside DesktopInput and PadInput, and the one the
device-independent input was written for in the first place —
InputState.setStickAxis has said "for a stick or a d-pad" since before
either existed, and its class doc has always promised that the touch build
and the desktop build run the same game code. This is that promise being
collected.
Where each control goes
A game with two or three verbs is a stick and a row of buttons. A game with six is not served by adding circles to the row, because its verbs are not six of the same kind:
| control | kind | where |
|---|---|---|
| the TouchStick | analogue, held | bottom left, under the left thumb |
| buttons | held | bottom right, the last nearest the thumb |
| toggles | set, and stays set | a row just above buttons |
| slots | chosen, occasionally | up the right edge, out of the cluster |
| corner | set, and rarely wanted | top right corner, on its own |
The two axes are how often and how bad a mistake is. What is pressed every second and costs nothing by accident sits where the thumb rests; what is wanted twice a minute and loses the game when pressed by mistake takes a deliberate reach. Nothing that is tapped by accident is next to something that is held.
A drag-to-look layer under this is the other half of the same rule: every pixel a control covers is a pixel the player cannot turn the view with, so the slots and the corner hug the edges.
Until 1.0.0-rc.1 the stick-and-row and the layout with slots and a corner
were two widgets, TouchControls and TouchCluster, doing one job. This
is both: a game that hands no slots and no corner gets the row it
always had.
Labelled, even though a blind player is not playing this
Each button says what it does to a screen reader. That is not the contradiction it looks like: a player with low vision, or one whose reader is on for something else entirely, meets these controls and gets "jump" rather than an unnamed circle. The stick is not labelled, because a thumb stick under a reader is a gesture nobody can perform.
One finger per control
Every control tracks the pointer id that claimed it, which is the whole of multi-touch and is not optional: a player walking and jumping is holding two fingers down at once, and a control that took the most recent pointer would snap the stick to the jump button.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- TouchControls
Constructors
-
TouchControls({Key? key, required InputState state, required List<
TouchAction> buttons, List<TouchToggle> toggles = const <TouchToggle>[], List<TouchSlot> slots = const <TouchSlot>[], int current = -1, TouchToggle? corner, double stickRadius = 64.0, double buttonRadius = 34.0, double margin = 28.0, DualAxisAction stickAction = DualAxisAction.move}) -
A stick and
buttonsoverstate, with no toggles, slots or corner unless given; sizes are in logical pixels.const
Properties
-
Each button's radius, in logical pixels.
final
-
What the buttons on the right do, in the order they are drawn: the last is
nearest the thumb.
final
- corner → TouchToggle?
-
The one switch that is wanted rarely and costs something when pressed
by mistake — a map, say — in the corner nothing else uses, or null.
final
- current → int
-
Which of slots is in use, or −1 for none.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- margin → double
-
How far the controls sit from the edges, in logical pixels. Generous,
because the edges of a phone are where the system's own gestures live.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
slots
→ List<
TouchSlot> -
The numbered slots, or none for a game without them. See TouchSlots.
final
- state → InputState
-
The input every control writes into, as a device would.
final
- stickAction → DualAxisAction
-
What the stick asks for — walking unless the game says otherwise. See
TouchStick.action.
final
- stickRadius → double
-
The stick's radius, in logical pixels.
final
-
toggles
→ List<
TouchToggle> -
Controls that are set rather than held — see TouchToggle — and wanted
often enough to sit by the thumb.
final
Methods
-
build(
BuildContext context) → Widget -
Describes the part of the user interface represented by this widget.
override
-
createElement(
) → StatelessElement -
Creates a StatelessElement to manage this widget's location in the tree.
inherited
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited