Documentation
¶
Overview ¶
Package input is the contract between a backend's input and whynot. A backend reports what the user did as Event values: pointer movements and buttons (PointerMove, PointerLeave, PointerButton), scrolling (Wheel) and touches (TouchStart, TouchMove, TouchEnd, TouchCancel). A whynot.Controller turns them into scrolling, hovering, clicking and so on.
A backend's input reader is a Source: each call to its Events method returns what happened since the previous call, in order. A program calls it once per frame and passes the events to its Controller or Panel.
Units ¶
Positions are in the coordinate space of the Canvas the View is drawn on (device pixels for whynot's own backends): see the Coordinates section of package whynot's documentation. A Wheel's deltas are an amount to scroll rather than a position, so they're in logical pixels, independent of the screen's density: a Controller scales them.
A backend reports all the input it sees. A Controller acts on the events inside its View's bounds, except that a press inside them captures the pointer until it's released.
Keyboard input isn't part of it: keys belong to the program, which binds them to commands such as a Panel's PageDown.
Without a Controller ¶
A program driving a View by hand reads the events itself, acting on the ones it cares about. This scrolls with the wheel:
for _, e := range source.Events() {
if w, ok := e.(input.Wheel); ok {
view.ScrollBy(w.DY * view.Scale()) // logical pixels, scaled to the View's
}
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event interface {
// contains filtered or unexported methods
}
Event is something the user did. Only this package defines kinds of Event, so new kinds can be added without breaking backends or handlers: a backend that doesn't know a kind never reports it, and a handler ignores kinds it doesn't know.
type PointerButton ¶
PointerButton is a mouse button going down or up, with the pointer at (X, Y).
type PointerLeave ¶
type PointerLeave struct{}
PointerLeave is the mouse pointer leaving the area the backend reports input for.
type PointerMove ¶
type PointerMove struct{ X, Y int }
PointerMove is the mouse pointer moving to (X, Y).
type Source ¶
type Source interface {
Events() []Event
}
Source is a backend's input reader. Each call to Events returns what the user did since the previous call, in order, as this package's events.
type TouchCancel ¶
type TouchCancel struct{ ID int }
TouchCancel is the touch ID being taken away, e.g. by a system gesture: unlike TouchEnd, it's never a tap.
type TouchStart ¶
type TouchStart struct{ ID, X, Y int }
TouchStart is a finger touching at (X, Y). ID tells simultaneous touches apart, until the touch ends.
type Wheel ¶
Wheel is a scroll, e.g. by a mouse wheel or a trackpad, with the pointer at (X, Y). DX and DY are how far to scroll, positive towards the end of the content (right and down), in logical pixels: a backend doesn't need to know the screen's density, and a Controller converts them to the View's pixels with its scale, so a wheel scrolls the same distance on any screen.