Skip to main content

VisualView

Struct VisualView 

Source
pub struct VisualView<S: Spec> { /* private fields */ }
Expand description

Read-only per-window truth of this frame, built at the start of the compose phase (design §5.2, read path a).

Owned, not borrowed: the compose phase mutates the input engine (registrations) while hooks hold the view, so the engine views cannot be lent out; the copied state is exactly what the engines reported at phase start, which is the same-tick truth the design asks the view to be. Clicks are the last evaluated frame’s (a release is evaluated by the EndFrame of the compose that saw it and read back from the next compose on — one frame of latency, like every retained-registration immediate-mode UI).

Implementations§

Source§

impl<S: Spec> VisualView<S>

Source

pub fn hovered(&self) -> Option<&WidgetId>

The widget under the pointer, if any.

Source

pub fn is_hovered(&self, id: &WidgetId) -> bool

id is under the pointer.

Source

pub fn hover_path(&self) -> &[WidgetId]

The hovered widget and its register_child ancestors, root first: everything CSS :hover matches.

Source

pub fn is_hover_within(&self, id: &WidgetId) -> bool

id is hovered or contains the hovered widget (:hover on a parent).

Source

pub fn hover_changes(&self) -> (Vec<WidgetId>, Vec<WidgetId>)

The mouseleave / mouseenter sets since the last compose: left deepest first, entered outermost first; common ancestors get neither (they do not bubble).

Source

pub fn focus_path(&self) -> &[WidgetId]

The focused widget and its ancestors, root first (empty when nothing is focused): everything CSS :focus-within matches.

Source

pub fn is_focus_within(&self, id: &WidgetId) -> bool

id is focused or contains the focused widget (:focus-within).

Source

pub fn dispatch_focus(&self, handler: impl FnMut(FocusEvent, &mut EventCx<'_>))

Dispatch the focus move since the last compose DOM-style: blur and focusout (bubbling) on the old focus path, then focus and focusin (bubbling) on the new one. Nothing fires without a move.

Source

pub fn dispatch_clicks(&self, handler: impl FnMut(&mut EventCx<'_>, u8))

Dispatch last frame’s clicks DOM-style: per click a capture leg root → parent, the target, a bubble leg parent → root, honouring stop_propagation / prevent_default. The handler also gets the click count.

Source

pub fn pressed(&self) -> Option<&WidgetId>

The widget being pressed, if any.

Source

pub fn is_pressed(&self, id: &WidgetId) -> bool

id is being pressed.

Source

pub fn with_focus(self, id: impl Into<WidgetId>) -> Self

This view with id focused, as the engines would report it: for headless renders and app tests of a frame (a text field paints its caret and selection only when focused).

Source

pub fn focused(&self) -> Option<&WidgetId>

The widget with keyboard focus, if any.

Source

pub fn focus_visible(&self) -> bool

:focus-visible: the focus came from the keyboard. Paint focus rings only when this is true (text fields show focus regardless).

Source

pub fn is_focused(&self, id: &WidgetId) -> bool

id has keyboard focus.

Source

pub fn clicked(&self, id: &WidgetId) -> bool

id was clicked in the last evaluated frame (single, double or triple — see VisualView::click_count).

Source

pub fn click_count(&self, id: &WidgetId) -> u8

The click count id was last clicked with (0 = not clicked, 1 single, 2 double, 3 triple).

Source

pub fn clicks(&self) -> &[(WidgetId, u8)]

Every widget clicked in the last evaluated frame, with counts.

Source

pub fn scroll(&self) -> (f64, f64)

Scroll delta accumulated for this frame, in lines.

Source

pub fn scroll_precise(&self) -> bool

The frame’s scroll came from pixel deltas (trackpad / smooth wheel).

Source

pub fn pointer(&self) -> Option<(f64, f64)>

👎Deprecated:

ignores z-order; use pointer_over(id), or raw_pointer() when the raw position is really meant

Last pointer position in window coordinates, if known.

Raw position: it ignores z-order, so hover drawn from it shows through drawers, popups and modals painted on top. Prefer Self::pointer_over; opt in with Self::raw_pointer.

Source

pub fn raw_pointer(&self) -> Option<(f64, f64)>

The raw pointer position, whatever lies on top of it (opt-in, not z-order safe: never draw hover from it; ask Self::pointer_over).

Source

pub fn pointer_over(&self, id: &WidgetId) -> Option<(f64, f64)>

The pointer position when id is the one topmost hit target under it (or one of its register_child ancestors), or holds the press of a drag (pointer capture). None when anything — a drawer, popup or modal on a higher layer, an occluder — covers id there. Custom-drawn areas (terminals, canvases) register one widget and ask this before showing hover, hit-testing their content or taking a press.

Source

pub fn scroll_over(&self, id: &WidgetId) -> (f64, f64)

This frame’s wheel delta (lines) when id is the topmost target under the pointer, else zero. See Self::pointer_over.

Source

pub fn context_click(&self) -> Option<(f64, f64)>

Secondary-button (context menu) release in this frame, window coords.

Source

pub fn button_down(&self) -> bool

A pointer button is held.

Source

pub fn press_origin(&self) -> Option<(f64, f64)>

Where the held press went down (window coords), while a button is held on a widget. Drags anchor here so the grabbed point stays under the pointer: the first frame that sees the press may already see the pointer a few pixels further.

// Grab offset inside the card, fixed for the whole drag.
let (px, py) = view.pressed_at(id)?;
let grab = (px - card.0, py - card.1);
let (x, y) = view.raw_pointer()?;
Some((x - grab.0, y - grab.1)) // the card's new origin
Source

pub fn pressed_at(&self, id: &WidgetId) -> Option<(f64, f64)>

Self::press_origin when id holds the press.

Source

pub fn captured(&self) -> bool

The pointer is captured by a widget or an engine.

Source

pub fn selection(&self, id: &WidgetId) -> Option<TextSelection>

The plain-text selection of a selectable widget (reported through Widgets::selectables), to paint its highlight.

Source

pub fn overlay_open(&self, id: S::Overlay) -> bool

This overlay is open in the window.

Source

pub fn open_overlays(&self) -> &[S::Overlay]

Every open overlay of the window, bottom to top.

Trait Implementations§

Source§

impl<S: Spec> Default for VisualView<S>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<S> Forget for VisualView<S>

§

impl<S> Freeze for VisualView<S>
where Vec<<S as Spec>::Overlay>: Freeze,

§

impl<S> Move for VisualView<S>

§

impl<S> RefUnwindSafe for VisualView<S>
where Vec<<S as Spec>::Overlay>: RefUnwindSafe,

§

impl<S> Send for VisualView<S>
where Vec<<S as Spec>::Overlay>: Send,

§

impl<S> Sync for VisualView<S>
where Vec<<S as Spec>::Overlay>: Sync,

§

impl<S> Unpin for VisualView<S>
where Vec<<S as Spec>::Overlay>: Unpin,

§

impl<S> UnsafeUnpin for VisualView<S>
where Vec<<S as Spec>::Overlay>: UnsafeUnpin,

§

impl<S> UnwindSafe for VisualView<S>
where Vec<<S as Spec>::Overlay>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.