ltk/input/gesture/
outcomes.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// SPDX-License-Identifier: LGPL-2.1-only
// Copyright (C) 2026 Liberux Labs, S. L. <info@liberux.net>

use crate::types::Point;

/// Result of [`GestureState::on_press`]. Handler uses `hit_idx` to set
/// keyboard focus; pushes `initial_slider_msg` to the pending queue
/// when present.
pub struct PressOutcome<Msg>
{
	pub hit_idx:            Option<usize>,
	pub initial_slider_msg: Option<Msg>,
}

/// Result of [`GestureState::on_move`]. Handler turns this into app
/// callbacks + redraw flags.
pub enum MoveOutcome<Msg>
{
	/// Nothing gesture-level fired. Hovered index may still have
	/// changed — pointer handler updates it separately before calling
	/// on_move.
	Idle,
	/// Long-press drag in flight — fire `app.on_drag_move(pos)`.
	Drag   { pos: Point },
	/// Slider value changed. `None` when the slider has no change
	/// handler for this value (typically unreachable — sliders always
	/// carry a change msg — but the gesture machine stays general).
	Slider { msg: Option<Msg> },
	/// Scroll viewport offset updated. Handler just requests a redraw.
	Scroll,
	/// Swipe progress. Each axis is `Some(value)` when it has a valid
	/// progress reading for this move (not every motion updates all
	/// axes). Handler fires the matching app callback.
	Swipe  { up: Option<f32>, down: Option<f32>, horizontal: Option<f32> },
}

/// Events emitted by [`GestureState::on_release`], in the order the
/// handler should dispatch them. Multiple events per release are
/// possible (see the horizontal fall-through case).
pub enum ReleaseEvent<Msg>
{
	/// Long-press drop — `app.on_drop(pos)`, kick main redraw, clear
	/// long-press drag.
	Drop { pos: Point },
	/// Horizontal swipe committed left.
	SwipeLeft,
	/// Horizontal swipe committed right.
	SwipeRight,
	/// Vertical swipe committed up.
	SwipeUp,
	/// Vertical swipe committed down.
	SwipeDown,
	/// Horizontal swipe did not commit — fire
	/// `app.on_swipe_horizontal_progress(0.0)` + main redraw.
	HorizontalFellThrough,
	/// Vertical swipe did not commit — fire
	/// `app.on_swipe_progress(0.0)` + `app.on_swipe_down_progress(0.0)`.
	VerticalFellThrough,
	/// Push a widget-level message (button press or final slider
	/// value on release).
	PushMsg( Msg ),
	/// Release on empty area — handler calls `app.on_tap()` on Main
	/// focus or `overlay_dismiss_msg(id)` on Overlay focus.
	EmptyRelease,
}

/// Swipe thresholds + surface dimensions snapshotted from the app +
/// current surface, passed into gesture methods so the machine stays
/// decoupled from `App` and `SurfaceState`.
pub struct SwipeConfig
{
	/// Up-swipe commit fraction of surface height (e.g. 0.3 = 30 %).
	pub up_thresh:         f32,
	/// Down-swipe commit fraction of surface height.
	pub down_thresh:       f32,
	/// Down-swipe start zone fraction — the press must land within
	/// `surface_height * down_edge` of the top for a down-swipe to
	/// arm.
	pub down_edge:         f32,
	/// Horizontal commit fraction of surface width.
	pub horizontal_thresh: f32,
	pub surface_width:     u32,
	pub surface_height:    u32,
}