Skip to main content

fret_ui_kit/declarative/
pointer_queries.rs

1use fret_core::PointerType;
2use fret_ui::{ElementContextAccess, Invalidation, UiHost};
3
4/// Returns the most recent committed primary pointer type for the window (ADR 0232).
5#[track_caller]
6pub fn primary_pointer_type<'a, H: UiHost + 'a, Cx>(
7    cx: &mut Cx,
8    invalidation: Invalidation,
9) -> PointerType
10where
11    Cx: ElementContextAccess<'a, H>,
12{
13    cx.elements().environment_primary_pointer_type(invalidation)
14}
15
16/// Returns whether the primary pointer is expected to support hover-driven affordances.
17///
18/// Notes:
19/// - This is a **policy helper**; it is intentionally small and may evolve as runners provide more
20///   precise capability data.
21/// - When the pointer type is `Unknown`, `default_when_unknown` is returned.
22#[track_caller]
23pub fn primary_pointer_can_hover<'a, H: UiHost + 'a, Cx>(
24    cx: &mut Cx,
25    invalidation: Invalidation,
26    default_when_unknown: bool,
27) -> bool
28where
29    Cx: ElementContextAccess<'a, H>,
30{
31    cx.elements()
32        .environment_primary_pointer_can_hover(invalidation, default_when_unknown)
33}
34
35/// Returns whether the primary pointer is expected to be coarse (touch-first).
36///
37/// When the pointer type is `Unknown`, `default_when_unknown` is returned.
38#[track_caller]
39pub fn primary_pointer_is_coarse<'a, H: UiHost + 'a, Cx>(
40    cx: &mut Cx,
41    invalidation: Invalidation,
42    default_when_unknown: bool,
43) -> bool
44where
45    Cx: ElementContextAccess<'a, H>,
46{
47    cx.elements()
48        .environment_primary_pointer_is_coarse(invalidation, default_when_unknown)
49}