Raxol.Animation.Gestures (Raxol v0.2.0)

View Source

Gesture-driven interactions for Raxol animations.

This module provides a system for detecting and handling gestures in terminal UI, which can be used to trigger physics-based animations.

Supported gestures include:

  • Swipe (rapid movement in a direction)
  • Tap (quick press and release)
  • Long press (press and hold)
  • Drag (press, move, release)
  • Pinch/zoom (simulated in terminal context)
  • Multi-tap (multiple quick taps)

Summary

Functions

Gets the current state of all objects in active animations. This is used for rendering.

Initializes the gesture system.

Registers a handler for a specific gesture type.

Updates all active physics-based animations. Should be called on each frame.

Types

direction()

@type direction() :: :up | :down | :left | :right

gesture_type()

@type gesture_type() :: :swipe | :tap | :long_press | :drag | :pinch | :multi_tap

handler()

@type handler() :: (map() -> any())

position()

@type position() :: {integer(), integer()}

Functions

get_animation_objects()

Gets the current state of all objects in active animations. This is used for rendering.

init()

Initializes the gesture system.

register_handler(gesture_type, handler)

Registers a handler for a specific gesture type.

Examples

iex> register_handler(:swipe, fn %{direction: :left} -> handle_left_swipe() end)
:ok

touch_down(position, time \\ System.monotonic_time(:millisecond))

Handles a touch/mouse down event.

touch_move(position, time \\ System.monotonic_time(:millisecond))

Handles a touch/mouse move event.

touch_up(position, time \\ System.monotonic_time(:millisecond))

Handles a touch/mouse up event.

update_animations(delta_time \\ nil)

Updates all active physics-based animations. Should be called on each frame.