ltk/input/pointer/
helpers.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
// SPDX-License-Identifier: LGPL-2.1-only
// Copyright (C) 2026 Liberux Labs, S. L. <info@liberux.net>

use crate::app::App;
use crate::event_loop::{ AppData, SurfaceFocus };
use crate::tree::find_handlers;

use super::super::gesture::SwipeConfig;

/// Pointer-side helpers on `AppData`. Split out so touch can call the
/// same swipe-config factory; `apply_*` helpers live in `dispatch.rs`
/// because they are shared.
impl<A: App> AppData<A>
{
	/// Snapshot the swipe thresholds + surface dimensions into a
	/// [`SwipeConfig`] for the gesture machine. Called once per
	/// motion / release event.
	pub( crate ) fn swipe_config( &self, focus: SurfaceFocus ) -> SwipeConfig
	{
		let ss = self.surface( focus );
		SwipeConfig
		{
			up_thresh:         self.app.swipe_threshold(),
			down_thresh:       self.app.swipe_down_threshold(),
			down_edge:         self.app.swipe_down_edge(),
			horizontal_thresh: self.app.swipe_horizontal_threshold(),
			surface_width:     ss.physical_width(),
			surface_height:    ss.physical_height(),
		}
	}
}

pub( crate ) fn hover_affects_paint<Msg: Clone>(
	widget_rects: &[crate::widget::LaidOutWidget<Msg>],
	idx:          Option<usize>,
) -> bool
{
	idx.and_then( |i| find_handlers( widget_rects, i ) )
		.map( |h| !h.is_slider() )
		.unwrap_or( false )
}