ViewId

Struct ViewId 

Source
pub struct ViewId(/* private fields */);
Expand description

A small unique identifier for an instance of a View.

This id is how you can access and modify a view, including accessing children views and updating state.

Implementations§

Source§

impl ViewId

Source

pub fn new() -> ViewId

Create a new unique Viewid.

Source

pub fn is_valid(&self) -> bool

Check if this ViewId is still valid (exists in VIEW_STORAGE).

A ViewId becomes invalid when it has been removed from the view tree. This is useful for filtering out stale ViewIds from collections.

Source

pub fn remove(&self)

Remove this view id and all of its children from the VIEW_STORAGE.

Note: For full cleanup including taffy nodes and cleanup listeners, use window_state.remove_view() or send an UpdateMessage::RemoveViews.

Source

pub fn taffy(&self) -> Rc<RefCell<TaffyTree>>

Get access to the taffy tree

Source

pub fn new_taffy_node(&self) -> NodeId

Create a new taffy layout node

Source

pub fn set_taffy_style(&self, node: NodeId, style: Style)

Set the layout properties on a taffy node

Source

pub fn taffy_layout(&self, node: NodeId) -> Option<Layout>

Get the layout for a taffy node relative to it’s parent

Source

pub fn mark_view_layout_dirty(&self) -> TaffyResult<()>

Mark the taffy node associated with this view as dirty.

Source

pub fn taffy_node(&self) -> NodeId

Get the taffy node associated with this Id

Source

pub fn set_transform(&self, transform: Affine)

set the transform on a view that is applied after style transforms

Source

pub fn add_child(&self, child: Box<dyn View>)

Add a child View to this Id’s list of children

Source

pub fn append_children(&self, children: Vec<Box<dyn View>>)

Append multiple children to this Id’s list of children.

This is more efficient than calling add_child multiple times as it only borrows VIEW_STORAGE once.

Takes a Vec to ensure views are fully constructed before borrowing VIEW_STORAGE, avoiding potential borrow conflicts.

Source

pub fn set_children<const N: usize, V: IntoView>(&self, children: [V; N])

Set the children views of this Id See also Self::set_children_vec

Source

pub fn set_children_vec(&self, children: Vec<impl IntoView>)

Set the children views of this Id using a Vector See also Self::set_children and Self::set_children_iter

Source

pub fn set_children_iter(&self, children: impl Iterator<Item = Box<dyn View>>)

Set the children views of this Id using an iterator of boxed views.

This is the most efficient way to set children when you already have an iterator of Box<dyn View>, as it avoids intermediate allocations.

See also Self::set_children and Self::set_children_vec

Source

pub fn set_view(&self, view: Box<dyn View>)

Set the view that should be associated with this Id

Source

pub fn set_parent(&self, parent: ViewId)

Set the Id that should be used as the parent of this Id

Source

pub fn set_children_ids(&self, children: Vec<ViewId>)

Set the Ids that should be used as the children of this Id

Source

pub fn children(&self) -> Vec<ViewId>

Get the list of ViewIds that are associated with the children views of this ViewId

Source

pub fn with_children<R>(&self, children: impl FnMut(&[ViewId]) -> R) -> R

Get access to the list of ViewIds that are associated with the children views of this ViewId

Source

pub fn parent(&self) -> Option<ViewId>

Get the ViewId that has been set as this ViewId’s parent

Source

pub fn root(&self) -> Option<ViewId>

Get the root view of the window that the given view is in

Source

pub fn layout_rect(&self) -> Rect

Get the computed rectangle that covers the area of this View

Source

pub fn get_size(&self) -> Option<Size>

Get the size of this View

Source

pub fn parent_size(&self) -> Option<Size>

Get the Size of the parent View

Source

pub fn get_content_rect(&self) -> Rect

Returns the layout rect excluding borders, padding and position. This is relative to the view.

Source

pub fn get_layout(&self) -> Option<Layout>

This gets the Taffy Layout and adjusts it to be relative to the parent View.

Source

pub fn get_layout_relative_to(&self, relative_to: ViewId) -> Option<Layout>

Get the taffy layout of this id relative to a parent/ancestor ID

Source

pub fn get_layout_relative_to_root(&self) -> Option<Layout>

Get the taffy layout of this id relative to the root

Source

pub fn get_transform(&self) -> Affine

Returns the CSS transform applied to this view.

This returns the view’s local transform (not including parent transforms). The transform includes translate, rotate, and scale operations.

Source

pub fn get_visual_origin(&self) -> Point

Returns the view’s visual position in window coordinates.

This is derived from visual_transform, which is the single source of truth for a view’s position. For views without CSS scale/rotate transforms, this equals the layout position plus CSS translate. For views with scale/rotate, this includes the effect of center-based transforms.

Source

pub fn get_window_origin(&self) -> Point

Returns the view’s window origin (layout position after CSS translate).

This is the position used for child layout and does NOT include scale/rotate effects. For the position including all CSS transforms (scale, rotate), use get_visual_origin().

The difference between window_origin and visual_origin:

  • window_origin: Position from layout + CSS translate (used for child positioning)
  • visual_origin: Position from visual_transform (includes center-based scale/rotate)

For views without scale/rotate transforms, these values are identical.

Source

pub fn get_layout_rect(&self) -> Rect

Returns the layout rect in window coordinates.

This is the bounding rect that encompasses this view and its children, positioned at the window origin. Useful for hit testing and paint bounds.

Source

pub fn get_visual_transform(&self) -> Affine

Returns the complete local-to-window coordinate transform.

This transform converts coordinates from this view’s local space to window coordinates. It combines:

  • The view’s position in the window
  • Any CSS transforms (scale, rotate)

To convert a local point to window coordinates: visual_transform * point To convert a window point to local coordinates: visual_transform.inverse() * point

This is the transform used by event dispatch to convert pointer coordinates.

Source

pub fn is_hidden(&self) -> bool

Returns true if this view is hidden.

Source

pub fn pointer_events_none(&self) -> bool

if the view has pointer events none

Source

pub fn is_disabled(&self) -> bool

Returns true if the view is disabled

This is done by checking if the style for this view has Disabled set to true.

Source

pub fn is_selected(&self) -> bool

Returns true if the view is selected

This is done by checking if the parent has set this view as selected via parent_set_selected().

Source

pub fn can_focus(&self) -> bool

Check if this id can be focused.

This is done by checking if the style for this view has Focusable set to true.

Source

pub fn can_drag(&self) -> bool

Check if this id can be dragged.

This is done by checking if the style for this view has Draggable set to true.

Source

pub fn request_all(&self)

Request that this the id view be styled, laid out and painted again. This will recursively request this for all parents.

Source

pub fn request_layout(&self)

Request that this view have it’s layout pass run

Source

pub fn window_id(&self) -> Option<WindowId>

Get the window id of the window containing this view, if there is one.

Source

pub fn request_paint(&self)

Request that this view have it’s paint pass run

Source

pub fn request_style(&self)

request that this node be styled again This will recursively request style for all parents.

Source

pub fn request_view_style(&self)

Use this when you want the view_style method from the View trait to be rerun.

Source

pub fn request_style_recursive(&self)

Requests style for this view and all direct and indirect children.

Source

pub fn request_style_for_selector_recursive(&self, selector: StyleSelector)

Requests style for this view and descendants that have the specified selector.

This is more efficient than request_style_recursive when only views with certain selectors (like :focus, :active) need to be updated. Views without the selector in their has_style_selectors are skipped.

§Arguments
  • selector - The selector type to check for (e.g., StyleSelector::Focus)
Source

pub fn request_focus(&self)

Request that this view gain the window focus

Source

pub fn clear_focus(&self)

Clear the focus from this window

Source

pub fn update_context_menu(&self, menu: impl Fn() -> Menu + 'static)

Set the system context menu that should be shown when this view is right-clicked

Source

pub fn update_popout_menu(&self, menu: impl Fn() -> Menu + 'static)

Set the system popout menu that should be shown when this view is clicked

Adds a primary-click context menu, which opens below the view.

Source

pub fn request_active(&self)

Request that this view receive the active state (mark that this element is currently being interacted with)

When an View has Active, it will receive events such as mouse events, even if the mouse is not directly over this view. This is usefor for views such as Sliders, where the mouse event should be sent to the slider view as long as the mouse is pressed down, even if the mouse moves out of the view, or even out of the Window.

Source

pub fn clear_active(&self)

Request that the active state be removed from this View

Source

pub fn set_pointer_capture(&self, pointer_id: PointerId)

Set pointer capture for this view.

When a view has pointer capture for a pointer, all subsequent pointer events for that pointer are dispatched directly to this view, regardless of where the pointer moves. This is useful for:

  • Drag operations that should continue even when the pointer leaves the view
  • Sliders and scrollbars that need to track pointer movement globally
  • Any interaction that requires reliable pointer tracking

The capture will be applied on the next pointer event for this pointer ID. When capture is set:

  • GotPointerCapture event is fired to this view
  • All subsequent pointer events for this pointer are routed here
  • When released, LostPointerCapture event is fired

Capture is automatically released on PointerUp for the captured pointer.

§Example
fn event_before_children(&mut self, cx: &mut EventCx, event: &Event) -> EventPropagation {
    if let Event::Pointer(PointerEvent::Down(e)) = event {
        if let Some(pointer_id) = e.pointer.pointer_id {
            self.id().set_pointer_capture(pointer_id);
        }
    }
    EventPropagation::Continue
}
Source

pub fn release_pointer_capture(&self, pointer_id: PointerId)

Release pointer capture from this view.

If this view has capture for the specified pointer, the capture will be released on the next pointer event. A LostPointerCapture event will be fired when the release takes effect.

Note: This only releases capture if this view currently has it. It’s safe to call even if this view doesn’t have capture.

Source

pub fn inspect(&self)

Send a message to the application to open the Inspector for this Window

Source

pub fn scroll_to(&self, rect: Option<Rect>)

Scrolls the view and all direct and indirect children to bring the view to be visible. The optional rectangle can be used to add an additional offset and intersection.

Source

pub fn update_state(&self, state: impl Any)

Send a state update to the update method of the associated View

Source

pub fn add_event_listener( &self, listener: EventListener, action: Box<EventCallback>, )

Add an callback on an action for a given EventListener

Source

pub fn add_resize_listener(&self, action: Rc<ResizeCallback>)

Set a callback that should be run when the size of the view changes

Source

pub fn add_move_listener(&self, action: Rc<dyn Fn(Point)>)

Set a callback that should be run when the position of the view changes

Source

pub fn add_cleanup_listener(&self, action: Rc<dyn Fn()>)

Set a callback that should be run when the view is removed from the view tree

Source

pub fn get_combined_style(&self) -> Style

Get the combined style that is associated with this View.

This will have all of the style properties set in it that are relevant to this view, including all properties from relevant classes.

§Warning

The view styles do not store property transition states, only markers of which properties should be transitioned over time on change.

If you have a property that could be transitioned over time, make sure to use a prop extractor that is updated in a style method of the View to extract the property.

Source

pub fn add_class(&self, class: StyleClassRef)

Add a class to the list of style classes that are associated with this ViewId

Source

pub fn remove_class(&self, class: StyleClassRef)

Remove a class from the list of style classes that are associated with this ViewId

Source

pub fn disable_default_event(&self, event: EventListener)

Disables the default view behavior for the specified event.

Children will still see the event, but the view event function will not be called nor the event listeners on the view

Source

pub fn remove_disable_default_event(&self, event: EventListener)

Re-enables the default view behavior for a previously disabled event.

Source

pub fn window_visible(&self, visible: bool)

Alter the visibility of the current window the view represented by this ID is in.

Source

pub fn request_remove_views(&self, view_ids: Vec<ViewId>)

Request removal of views during the update phase.

This schedules the views to be removed with proper cleanup (cleanup listeners, taffy nodes, recursive children removal). Used by keyed_children for efficient keyed diffing.

Source

pub fn add_child_deferred(&self, child_fn: impl FnOnce() -> AnyView + 'static)

Queue a child to be added during the next update cycle.

The child will be constructed when the message is processed. The scope is resolved at build time by looking up the parent’s context scope in the view hierarchy, enabling proper context propagation.

Source

pub fn add_children_deferred( &self, children_fn: impl FnOnce() -> Vec<AnyView> + 'static, )

Queue multiple children to be added during the next update cycle.

The children will be constructed when the message is processed. The scope is resolved at build time by looking up the parent’s context scope in the view hierarchy, enabling proper context propagation.

Source

pub fn setup_reactive_children_deferred(&self, setup: impl FnOnce() + 'static)

Queue a reactive children setup to run during the next update cycle.

The setup function will be called inside the view’s scope (resolved via find_scope()) when the message is processed. This enables lazy setup of reactive children (derived_children, derived_child, keyed_children) inside the correct scope for context access.

Source

pub fn update_state_deferred(&self, state: impl Any)

Send a state update that will be placed in deferred messages

Source

pub fn screen_layout(&self) -> Option<ScreenLayout>

Get a layout in screen-coordinates for this view, if possible.

Source

pub fn set_style_parent(&self, parent_id: ViewId)

Set the custom style parent to make it so that a view will pull it’s style context from a different parent. This is useful for overlays that are children of the window root but should pull their style cx from the creating view

Source

pub fn clear_style_parent(&self)

Clear the custom style parent

Source

pub fn set_children_scope(&self, scope: Scope)

Set the children scope for reactive children.

This stores the scope used by ParentView::derived_children so that when children are updated, the old scope can be properly disposed.

Source

pub fn take_children_scope(&self) -> Option<Scope>

Take and dispose the children scope, returning the old scope if it existed.

This is called when reactive children are updated to clean up the old scope.

Source

pub fn set_keyed_children(&self, children: Vec<(ViewId, Scope)>)

Set the keyed children state for reactive keyed children.

This stores the children and their scopes used by ParentView::keyed_children. Each child has its own scope that gets disposed when the child is removed.

Source

pub fn take_keyed_children(&self) -> Option<Vec<(ViewId, Scope)>>

Take the keyed children state, returning it if it existed.

This is called when keyed children are updated to apply diffs.

Source

pub fn set_scope(&self, scope: Scope)

Set the scope for this view.

Views that provide context to children (like Combobox, Dialog, etc.) should call this in their into_view() to store their scope. This scope is then used when processing deferred children so they have access to the context.

The scope hierarchy is kept in sync with the view hierarchy, so when a parent scope is disposed, all child scopes are also disposed.

Source

pub fn scope(&self) -> Option<Scope>

Get the scope for this view, if one was set.

Source

pub fn find_scope(&self) -> Option<Scope>

Find the nearest ancestor (including self) that has a scope.

This walks up the view tree to find the first view with a scope, which should be used when building deferred children.

Source§

impl ViewId

Source

pub fn parent_set_selected(&self)

Set the selected state for child views during styling. This should be used by parent views to propagate selected state to their children. Only requests a style update if the state actually changes.

Source

pub fn parent_clear_selected(&self)

Clear the selected state for child views during styling. This should be used by parent views to clear selected state propagation to their children. Only requests a style update if the state actually changes.

Source

pub fn parent_set_disabled(&self)

Set the disabled state for child views during styling. This should be used by parent views to propagate disabled state to their children. Only requests a style update if the state actually changes.

Source

pub fn parent_clear_disabled(&self)

Clear the disabled state for child views during styling. This should be used by parent views to clear disabled state propagation to their children. Only requests a style update if the state actually changes.

Source

pub fn set_hidden(&self)

Hide this view from layout. Sets the visibility state directly. Skips the normal transition animation logic.

Source

pub fn set_visible(&self)

Show this view in layout. Clears the force-hidden state.

Trait Implementations§

Source§

impl Clone for ViewId

Source§

fn clone(&self) -> ViewId

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ViewId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ViewId

Source§

fn default() -> ViewId

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

impl From<KeyData> for ViewId

Source§

fn from(k: KeyData) -> Self

Converts to this type from the input type.
Source§

impl Hash for ViewId

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Key for ViewId

Source§

fn data(&self) -> KeyData

Gets the KeyData stored in this key. Read more
Source§

fn null() -> Self

Creates a new key that is always invalid and distinct from any non-null key. A null key can only be created through this method (or default initialization of keys made with new_key_type!, which calls this method). Read more
Source§

fn is_null(&self) -> bool

Checks if a key is null. There is only a single null key, that is a.is_null() && b.is_null() implies a == b. Read more
Source§

impl Ord for ViewId

Source§

fn cmp(&self, other: &ViewId) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for ViewId

Source§

fn eq(&self, other: &ViewId) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for ViewId

Source§

fn partial_cmp(&self, other: &ViewId) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for ViewId

Source§

impl Eq for ViewId

Source§

impl StructuralPartialEq for ViewId

Auto Trait Implementations§

§

impl Freeze for ViewId

§

impl RefUnwindSafe for ViewId

§

impl Send for ViewId

§

impl Sync for ViewId

§

impl Unpin for ViewId

§

impl UnwindSafe for ViewId

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

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

Source§

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

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,