RMGui 0.15.0
C11 retained-mode UI library: layout kernel, style schema, widget painters, fonts, software framebuffer
Loading...
Searching...
No Matches
gesture.h File Reference

gesture.h — allocation-free, integer-only touch recognition. More...

#include <stddef.h>
#include <stdint.h>
#include "input.h"

Data Structures

struct  rmgui_gesture_config_t
 All distances are logical pixels, times are milliseconds. More...
struct  rmgui_gesture_result_t
 Signed Q16 values use 65536 units per pixel/scale/turn. More...
struct  rmgui_gesture_contact_t
 Caller storage, read-only between calls. More...
struct  rmgui_gesture_t
 Caller-owned recognizer, initialized by init; members are private state. More...

Macros

#define RMGUI_GESTURE_TAP   (1u << 0)
 Results can combine flags, notably PAN_END | PINCH_BEGIN on a second down.
#define RMGUI_GESTURE_DOUBLE_TAP   (1u << 1)
#define RMGUI_GESTURE_LONG_PRESS   (1u << 2)
#define RMGUI_GESTURE_PAN_BEGIN   (1u << 3)
#define RMGUI_GESTURE_PAN_UPDATE   (1u << 4)
#define RMGUI_GESTURE_PAN_END   (1u << 5)
#define RMGUI_GESTURE_PINCH_BEGIN   (1u << 6)
#define RMGUI_GESTURE_PINCH_UPDATE   (1u << 7)
#define RMGUI_GESTURE_PINCH_END   (1u << 8)
#define RMGUI_GESTURE_CANCEL   (1u << 9)

Functions

int rmgui_gesture_init (rmgui_gesture_t *state, rmgui_gesture_contact_t *contacts, size_t capacity, const rmgui_gesture_config_t *config)
 Initialize/reinitialize with capacity > 0 and non-NULL arguments.
int rmgui_gesture_input (rmgui_gesture_t *state, const rmgui_input_t *event, uint64_t now_ms, rmgui_gesture_result_t *out)
 Feed TOUCH_DOWN/MOVE/UP/CANCEL, or event == NULL to advance the clock and recognize a stationary long press.

Detailed Description

gesture.h — allocation-free, integer-only touch recognition.

Macro Definition Documentation

◆ RMGUI_GESTURE_TAP

#define RMGUI_GESTURE_TAP   (1u << 0)

Results can combine flags, notably PAN_END | PINCH_BEGIN on a second down.

A tap is reported immediately on release; a qualifying next tap reports DOUBLE_TAP instead of TAP. LONG_PRESS fires once and prevents a tap, but movement can still start a pan. Pinch excludes tap/long-press recognition.

◆ RMGUI_GESTURE_DOUBLE_TAP

#define RMGUI_GESTURE_DOUBLE_TAP   (1u << 1)

◆ RMGUI_GESTURE_LONG_PRESS

#define RMGUI_GESTURE_LONG_PRESS   (1u << 2)

◆ RMGUI_GESTURE_PAN_BEGIN

#define RMGUI_GESTURE_PAN_BEGIN   (1u << 3)

◆ RMGUI_GESTURE_PAN_UPDATE

#define RMGUI_GESTURE_PAN_UPDATE   (1u << 4)

◆ RMGUI_GESTURE_PAN_END

#define RMGUI_GESTURE_PAN_END   (1u << 5)

◆ RMGUI_GESTURE_PINCH_BEGIN

#define RMGUI_GESTURE_PINCH_BEGIN   (1u << 6)

◆ RMGUI_GESTURE_PINCH_UPDATE

#define RMGUI_GESTURE_PINCH_UPDATE   (1u << 7)

◆ RMGUI_GESTURE_PINCH_END

#define RMGUI_GESTURE_PINCH_END   (1u << 8)

◆ RMGUI_GESTURE_CANCEL

#define RMGUI_GESTURE_CANCEL   (1u << 9)

Function Documentation

◆ rmgui_gesture_init()

int rmgui_gesture_init ( rmgui_gesture_t * state,
rmgui_gesture_contact_t * contacts,
size_t capacity,
const rmgui_gesture_config_t * config )

Initialize/reinitialize with capacity > 0 and non-NULL arguments.

Refusal returns -1 without changing state or contact storage. Success returns 0, discards previous recognition and leaves contact storage untouched. state, config and contact storage must not overlap.

◆ rmgui_gesture_input()

int rmgui_gesture_input ( rmgui_gesture_t * state,
const rmgui_input_t * event,
uint64_t now_ms,
rmgui_gesture_result_t * out )

Feed TOUCH_DOWN/MOVE/UP/CANCEL, or event == NULL to advance the clock and recognize a stationary long press.

now_ms must be nondecreasing, including non-touch calls. Non-touch events are accepted but do not recognize gestures. The host supplies all times; timer calls are needed without incoming events. UP/MOVE positions count toward movement before recognition; UP never starts a long press. Duplicate down, unknown move/up/cancel, exhausted storage, backward time, uninitialized state, or NULL state/out returns -1, leaving state, contact storage and *out unchanged. Accepted calls return 0 and write *out (possibly flags == 0). event/out/state/storage must not overlap. Threshold crossings cancel a pending tap even if the contact moves back; double-tap time is measured from previous UP to next DOWN and both taps must independently satisfy tap_ms/tap_slop. All IDs, including 0, are valid.