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
impl ViewId
Sourcepub fn is_valid(&self) -> bool
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.
Sourcepub fn remove(&self)
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.
Sourcepub fn new_taffy_node(&self) -> NodeId
pub fn new_taffy_node(&self) -> NodeId
Create a new taffy layout node
Sourcepub fn set_taffy_style(&self, node: NodeId, style: Style)
pub fn set_taffy_style(&self, node: NodeId, style: Style)
Set the layout properties on a taffy node
Sourcepub fn taffy_layout(&self, node: NodeId) -> Option<Layout>
pub fn taffy_layout(&self, node: NodeId) -> Option<Layout>
Get the layout for a taffy node relative to it’s parent
Sourcepub fn mark_view_layout_dirty(&self) -> TaffyResult<()>
pub fn mark_view_layout_dirty(&self) -> TaffyResult<()>
Mark the taffy node associated with this view as dirty.
Sourcepub fn taffy_node(&self) -> NodeId
pub fn taffy_node(&self) -> NodeId
Get the taffy node associated with this Id
Sourcepub fn set_transform(&self, transform: Affine)
pub fn set_transform(&self, transform: Affine)
set the transform on a view that is applied after style transforms
Sourcepub fn append_children(&self, children: Vec<Box<dyn View>>)
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.
Sourcepub fn set_children<const N: usize, V: IntoView>(&self, children: [V; N])
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
Sourcepub fn set_children_vec(&self, children: Vec<impl IntoView>)
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
Sourcepub fn set_children_iter(&self, children: impl Iterator<Item = Box<dyn View>>)
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
Sourcepub fn set_view(&self, view: Box<dyn View>)
pub fn set_view(&self, view: Box<dyn View>)
Set the view that should be associated with this Id
Sourcepub fn set_parent(&self, parent: ViewId)
pub fn set_parent(&self, parent: ViewId)
Set the Id that should be used as the parent of this Id
Sourcepub fn set_children_ids(&self, children: Vec<ViewId>)
pub fn set_children_ids(&self, children: Vec<ViewId>)
Set the Ids that should be used as the children of this Id
Sourcepub fn children(&self) -> Vec<ViewId>
pub fn children(&self) -> Vec<ViewId>
Get the list of ViewIds that are associated with the children views of this ViewId
Sourcepub fn with_children<R>(&self, children: impl FnMut(&[ViewId]) -> R) -> R
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
Sourcepub fn parent(&self) -> Option<ViewId>
pub fn parent(&self) -> Option<ViewId>
Get the ViewId that has been set as this ViewId’s parent
Sourcepub fn layout_rect(&self) -> Rect
pub fn layout_rect(&self) -> Rect
Get the computed rectangle that covers the area of this View
Sourcepub fn parent_size(&self) -> Option<Size>
pub fn parent_size(&self) -> Option<Size>
Get the Size of the parent View
Sourcepub fn get_content_rect(&self) -> Rect
pub fn get_content_rect(&self) -> Rect
Returns the layout rect excluding borders, padding and position. This is relative to the view.
Sourcepub fn get_layout(&self) -> Option<Layout>
pub fn get_layout(&self) -> Option<Layout>
This gets the Taffy Layout and adjusts it to be relative to the parent View.
Sourcepub fn get_layout_relative_to(&self, relative_to: ViewId) -> Option<Layout>
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
Sourcepub fn get_layout_relative_to_root(&self) -> Option<Layout>
pub fn get_layout_relative_to_root(&self) -> Option<Layout>
Get the taffy layout of this id relative to the root
Sourcepub fn get_transform(&self) -> Affine
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.
Sourcepub fn get_visual_origin(&self) -> Point
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.
Sourcepub fn get_window_origin(&self) -> Point
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.
Sourcepub fn get_layout_rect(&self) -> Rect
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.
Sourcepub fn get_visual_transform(&self) -> Affine
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.
Returns true if this view is hidden.
Sourcepub fn pointer_events_none(&self) -> bool
pub fn pointer_events_none(&self) -> bool
if the view has pointer events none
Sourcepub fn is_disabled(&self) -> bool
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.
Sourcepub fn is_selected(&self) -> bool
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().
Sourcepub fn can_focus(&self) -> bool
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.
Sourcepub fn can_drag(&self) -> bool
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.
Sourcepub fn request_all(&self)
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.
Sourcepub fn request_layout(&self)
pub fn request_layout(&self)
Request that this view have it’s layout pass run
Sourcepub fn window_id(&self) -> Option<WindowId>
pub fn window_id(&self) -> Option<WindowId>
Get the window id of the window containing this view, if there is one.
Sourcepub fn request_paint(&self)
pub fn request_paint(&self)
Request that this view have it’s paint pass run
Sourcepub fn request_style(&self)
pub fn request_style(&self)
request that this node be styled again This will recursively request style for all parents.
Sourcepub fn request_view_style(&self)
pub fn request_view_style(&self)
Use this when you want the view_style method from the View trait to be rerun.
Sourcepub fn request_style_recursive(&self)
pub fn request_style_recursive(&self)
Requests style for this view and all direct and indirect children.
Sourcepub fn request_style_for_selector_recursive(&self, selector: StyleSelector)
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)
Sourcepub fn request_focus(&self)
pub fn request_focus(&self)
Request that this view gain the window focus
Sourcepub fn clear_focus(&self)
pub fn clear_focus(&self)
Clear the focus from this window
Set the system context menu that should be shown when this view is right-clicked
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.
Sourcepub fn request_active(&self)
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.
Sourcepub fn clear_active(&self)
pub fn clear_active(&self)
Request that the active state be removed from this View
Sourcepub fn set_pointer_capture(&self, pointer_id: PointerId)
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:
GotPointerCaptureevent is fired to this view- All subsequent pointer events for this pointer are routed here
- When released,
LostPointerCaptureevent 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
}Sourcepub fn release_pointer_capture(&self, pointer_id: PointerId)
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.
Sourcepub fn scroll_to(&self, rect: Option<Rect>)
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.
Sourcepub fn update_state(&self, state: impl Any)
pub fn update_state(&self, state: impl Any)
Send a state update to the update method of the associated View
Sourcepub fn add_event_listener(
&self,
listener: EventListener,
action: Box<EventCallback>,
)
pub fn add_event_listener( &self, listener: EventListener, action: Box<EventCallback>, )
Add an callback on an action for a given EventListener
Sourcepub fn add_resize_listener(&self, action: Rc<ResizeCallback>)
pub fn add_resize_listener(&self, action: Rc<ResizeCallback>)
Set a callback that should be run when the size of the view changes
Sourcepub fn add_move_listener(&self, action: Rc<dyn Fn(Point)>)
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
Sourcepub fn add_cleanup_listener(&self, action: Rc<dyn Fn()>)
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
Sourcepub fn get_combined_style(&self) -> Style
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.
Sourcepub fn add_class(&self, class: StyleClassRef)
pub fn add_class(&self, class: StyleClassRef)
Add a class to the list of style classes that are associated with this ViewId
Sourcepub fn remove_class(&self, class: StyleClassRef)
pub fn remove_class(&self, class: StyleClassRef)
Remove a class from the list of style classes that are associated with this ViewId
Sourcepub fn disable_default_event(&self, event: EventListener)
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
Sourcepub fn remove_disable_default_event(&self, event: EventListener)
pub fn remove_disable_default_event(&self, event: EventListener)
Re-enables the default view behavior for a previously disabled event.
Sourcepub fn window_visible(&self, visible: bool)
pub fn window_visible(&self, visible: bool)
Alter the visibility of the current window the view represented by this ID is in.
Sourcepub fn request_remove_views(&self, view_ids: Vec<ViewId>)
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.
Sourcepub fn add_child_deferred(&self, child_fn: impl FnOnce() -> AnyView + 'static)
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.
Sourcepub fn add_children_deferred(
&self,
children_fn: impl FnOnce() -> Vec<AnyView> + 'static,
)
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.
Sourcepub fn setup_reactive_children_deferred(&self, setup: impl FnOnce() + 'static)
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.
Sourcepub fn update_state_deferred(&self, state: impl Any)
pub fn update_state_deferred(&self, state: impl Any)
Send a state update that will be placed in deferred messages
Sourcepub fn screen_layout(&self) -> Option<ScreenLayout>
pub fn screen_layout(&self) -> Option<ScreenLayout>
Get a layout in screen-coordinates for this view, if possible.
Sourcepub fn set_style_parent(&self, parent_id: ViewId)
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
Sourcepub fn clear_style_parent(&self)
pub fn clear_style_parent(&self)
Clear the custom style parent
Sourcepub fn set_children_scope(&self, scope: Scope)
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.
Sourcepub fn take_children_scope(&self) -> Option<Scope>
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.
Sourcepub fn set_keyed_children(&self, children: Vec<(ViewId, Scope)>)
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.
Sourcepub fn take_keyed_children(&self) -> Option<Vec<(ViewId, Scope)>>
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.
Sourcepub fn set_scope(&self, scope: Scope)
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.
Sourcepub fn find_scope(&self) -> Option<Scope>
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
impl ViewId
Sourcepub fn parent_set_selected(&self)
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.
Sourcepub fn parent_clear_selected(&self)
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.
Sourcepub fn parent_set_disabled(&self)
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.
Sourcepub fn parent_clear_disabled(&self)
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.
Hide this view from layout. Sets the visibility state directly. Skips the normal transition animation logic.
Sourcepub fn set_visible(&self)
pub fn set_visible(&self)
Show this view in layout. Clears the force-hidden state.
Trait Implementations§
Source§impl Key for ViewId
impl Key for ViewId
Source§fn null() -> Self
fn null() -> Self
new_key_type!, which calls this
method). Read moreSource§impl Ord for ViewId
impl Ord for ViewId
Source§impl PartialOrd for ViewId
impl PartialOrd for ViewId
impl Copy for ViewId
impl Eq for ViewId
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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