-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Input API
The high level API for Fyne aims to be device agnostic. This is an important part of offering a truly cross-platform framework. We want to support apps that could work on desktop with mouse and keyboard, touch screens on mobile devices and more.
The APIs are split into multiple levels, the input abstractions, widget callbacks and driver specific APIs.
The input device abstraction focuses on the user intent of an action. On a desktop clicking a mouse button is the same as a touch screen tapping. A scrollwheel motion for a desktop interaction is the same as a tap and drag on a smart phone.
A PointerEvent is passed to each of these functions. It has a Position parameter so that calculations can be made based on the location of a tap/click.
Function | Desktop | Mobile example | Fields |
---|---|---|---|
Tapped | left mouse click | single finger tap | n/a |
?AltTapped | right mouse click | single finger long tap | n/a |
Scrolled | scroll wheel | finger tap and drag | X/Y delta |
Zoomed | CTRL + scroll wheel | two finger "pinch" | zoom delta |
Key input is split into two types - text (visible) and key (control keys). A visible input has a String property that can be printed or appended. An invisible one has a Name - that can be compared to a list of key names like KeyReturn or ShortcutCopy.
Function | Example | Desktop | Mobile example |
---|---|---|---|
Typed | c | c key | c virtual key |
D | Shift + d | D virtual upper | |
% | Shift + 5 | % symbol picker | |
?Control | Escape | Esc key | n/a |
Up | Up key | up virtual key / keyboard swipe up | |
Delete | Del key | del virtual key | |
Shortcut | Copy | Ctrl + c | Double tap and selecting from popup |
Undo | Ctrl + z | Shake |
Callbacks that the API user can set should begin with "On" and then the verb - derived from the list above.
Widget | Callback | Notes |
---|---|---|
Button | OnTap | When a Tap event is called on the button |
Check | OnChange | The widget handles interactions, mouse or keyboard, and this is a value changing |
Form | OnCancel | Called when a form is cancelled - this could be due to cancel being clicked, Escape key pressed etc |
Each (class of) driver may choose to provide specific access to lower level device event information. Using these APIs will mean that the drivers must be available at compile time. Also be careful to check that the current driver is of the type you expect - callbacks may not fire in the way you expect if a different driver is loaded. For example requiring a MouseDown callback will never call when a mobile driver is loaded.
MouseDown, MouseUp, MouseScroll will provide hardware triggered events before being interpreted for the higher level APIs.
KeyDown, KeyUp will be triggered for the hardware down/up signals which are focussed on key presses rather than the symbol created by such actions.