MCPcopy Create free account
hub / github.com/NativeScript/SimDeck / gesture_coordinates

Function gesture_coordinates

packages/server/src/main/input_helpers.rs:1–72  ·  view source on GitHub ↗
(
    bridge: &NativeBridge,
    udid: &str,
    preset: &str,
    screen_width: Option<f64>,
    screen_height: Option<f64>,
    normalized: bool,
    delta: Option<f64>,
)

Source from the content-addressed store, hash-verified

1fn gesture_coordinates(
2 bridge: &NativeBridge,
3 udid: &str,
4 preset: &str,
5 screen_width: Option<f64>,
6 screen_height: Option<f64>,
7 normalized: bool,
8 delta: Option<f64>,
9) -> Result<GestureCoordinates, crate::error::AppError> {
10 let (width, height) = if normalized {
11 (1.0, 1.0)
12 } else {
13 match (screen_width, screen_height) {
14 (Some(width), Some(height)) => (width, height),
15 _ => accessibility_root_size(bridge, udid)
16 .or_else(|| chrome_screen_size(bridge, udid))
17 .unwrap_or((390.0, 844.0)),
18 }
19 };
20 let center_x = width / 2.0;
21 let center_y = height / 2.0;
22 let edge = if normalized { 0.02 } else { 20.0 };
23 let distance = delta.unwrap_or(if normalized { 0.25 } else { 200.0 });
24 let (start_x, start_y, end_x, end_y, duration_ms) = match preset {
25 "scroll-up" => (
26 center_x,
27 center_y + distance / 2.0,
28 center_x,
29 center_y - distance / 2.0,
30 500,
31 ),
32 "scroll-down" => (
33 center_x,
34 center_y - distance / 2.0,
35 center_x,
36 center_y + distance / 2.0,
37 500,
38 ),
39 "scroll-left" => (
40 center_x + distance / 2.0,
41 center_y,
42 center_x - distance / 2.0,
43 center_y,
44 500,
45 ),
46 "scroll-right" => (
47 center_x - distance / 2.0,
48 center_y,
49 center_x + distance / 2.0,
50 center_y,
51 500,
52 ),
53 "swipe-from-left-edge" => (edge, center_y, width - edge, center_y, 300),
54 "swipe-from-right-edge" => (width - edge, center_y, edge, center_y, 300),
55 "swipe-from-top-edge" => (center_x, edge, center_x, height - edge, 300),
56 "swipe-from-bottom-edge" => (center_x, height - edge, center_x, edge, 300),
57 _ => {
58 return Err(crate::error::AppError::bad_request(format!(
59 "Unsupported gesture preset `{preset}`."
60 )))

Callers 2

mainFunction · 0.85
run_batch_stepFunction · 0.85

Calls 3

accessibility_root_sizeFunction · 0.85
chrome_screen_sizeFunction · 0.85
resolve_touch_pointFunction · 0.85

Tested by

no test coverage detected