pub struct WindowState { /* private fields */ }Expand description
Encapsulates and owns the global state of the application,
Implementations§
Source§impl WindowState
impl WindowState
pub fn new(root_view_id: ViewId, os_theme: Option<Theme>, os_scale: f64) -> Self
Sourcepub fn effective_scale(&self) -> f64
pub fn effective_scale(&self) -> f64
Returns the effective window scale used when converting between logical layout units and physical pixels.
This is the scale that rendering and input coordinate conversion should use. It combines:
Self::os_scale: platform DPI scalingSelf::user_scale: application zoom
Layout should usually not use this directly. Layout operates in logical
coordinates and already accounts for user zoom by dividing the root layout
space by Self::user_scale.
Sourcepub fn remove_view(&mut self, id: ViewId)
pub fn remove_view(&mut self, id: ViewId)
This removes a view from the app state.
pub fn is_hovered(&self, id: impl Into<ElementId>) -> bool
pub fn is_file_hover(&self, id: impl Into<ElementId>) -> bool
pub fn is_focused(&self, id: impl Into<ElementId>) -> bool
pub fn is_focus_within(&self, id: impl Into<ElementId>) -> bool
pub fn is_clicking(&self, id: impl Into<ElementId>) -> bool
use ViewId::is_active instead
pub fn is_active(&self, id: impl Into<ElementId>) -> bool
Sourcepub fn has_capture(&self, id: impl Into<ElementId>) -> bool
pub fn has_capture(&self, id: impl Into<ElementId>) -> bool
Check if a view has pointer capture for any pointer.
pub fn is_dark_mode(&self) -> bool
pub fn is_dragging(&self) -> bool
pub fn set_root_size(&mut self, size: Size)
Sourcepub fn register_fixed_element(&mut self, id: ViewId)
pub fn register_fixed_element(&mut self, id: ViewId)
Register a view as having fixed positioning. Called when a view’s style sets IsFixed to true.
Sourcepub fn unregister_fixed_element(&mut self, id: ViewId)
pub fn unregister_fixed_element(&mut self, id: ViewId)
Unregister a view from fixed positioning. Called when a view’s style sets IsFixed to false.
pub fn compute_layout(&mut self)
Sourcepub fn update_box_tree_from_layout(&mut self)
pub fn update_box_tree_from_layout(&mut self)
Update the box tree from the layout tree by walking the entire tree.
This pass performs a full local-space sync from layout/view state into the box tree. It recursively updates every view’s:
- local bounds (from layout size)
- local clip (from style transform props)
- local transform (layout position + parent scroll + view/style transforms)
Important: this does not finalize world-space behavior for features that
intentionally diverge from logical parentage (e.g. overlays reparented to root)
or viewport anchoring (fixed-position). Those are resolved in commit_box_tree()
via apply_overlay_parent_transforms() and apply_fixed_positioning_transforms().
Call this after layout completes; then run commit_box_tree() to finalize world
transforms, damage, and hit-testing consistency.
Sourcepub fn update_box_tree_for_view(&mut self, view_id: ViewId)
pub fn update_box_tree_for_view(&mut self, view_id: ViewId)
Update the box tree for a specific view only (non-recursive). This is efficient for updating a single view’s transform, scroll offset, or clip without walking the layout tree. Children’s transforms are not recalculated here; they’ll be handled by the box tree’s hierarchical transform system during commit.
Sourcepub fn process_pending_box_tree_updates(&mut self)
pub fn process_pending_box_tree_updates(&mut self)
Process all pending individual box tree updates. This should be called after layout and before commit.
Sourcepub fn commit_box_tree(&mut self)
pub fn commit_box_tree(&mut self)
Finalize box-tree state for this frame and produce damage.
commit_box_tree is the world-space resolution boundary of the update pipeline.
After local-space updates (update_box_tree_from_layout and/or
update_box_tree_for_view), this method applies global adjustments and then
commits the underlying box tree so transforms, clipping, and spatial indexing are
consistent for paint + hit testing.
Order of operations:
- Apply drag-preview world position override (if an active drag preview exists)
- Apply overlay parent-space remap (
apply_overlay_parent_transforms) - Apply fixed-position viewport placement (
apply_fixed_positioning_transforms) - Commit the box tree, producing dirty/damage regions
- If pointer lies in damaged region, clear hit-test cache and refresh under-cursor routing
Why this happens at commit time:
- Overlay and fixed positioning depend on global/world context, not only local layout.
- Separating local updates from commit allows batching many updates into one world resolve + one damage computation.
Call this after any box-tree local update before relying on paint order, hit-test correctness, or damage-driven cursor/hover updates.
Sourcepub fn schedule_style(&mut self, id: ViewId, reason: StyleReason)
pub fn schedule_style(&mut self, id: ViewId, reason: StyleReason)
Requests that the style pass will run for id on the next frame, and ensures new frame is
scheduled to happen.
Sourcepub fn schedule_style_with_target(
&mut self,
element_id: ElementId,
reason: StyleReason,
)
pub fn schedule_style_with_target( &mut self, element_id: ElementId, reason: StyleReason, )
Requests that the style pass will run for a specific element target on the next frame.
Use this when a style update should be scoped to a sub-element owned by a view, rather than always targeting the owning view element.
Sourcepub fn schedule_layout(&mut self)
pub fn schedule_layout(&mut self)
Requests that the layout pass will run for id on the next frame, and ensures new frame is
scheduled to happen.
Sourcepub fn schedule_box_tree_commit(&mut self)
pub fn schedule_box_tree_commit(&mut self)
Requests that the box tree be commited pass will run for id on the next frame, and ensures new frame is
scheduled to happen.
Sourcepub fn schedule_paint(&mut self, id: ViewId)
pub fn schedule_paint(&mut self, id: ViewId)
Requests that the paint pass will run for id on the next frame, and ensures new frame is
scheduled to happen.
pub fn request_paint(&mut self, _id: impl Into<ElementId>)
Sourcepub fn set_cursor(
&mut self,
id: impl Into<ElementId>,
cursor: CursorStyle,
) -> Option<CursorStyle>
pub fn set_cursor( &mut self, id: impl Into<ElementId>, cursor: CursorStyle, ) -> Option<CursorStyle>
returns the previously set cursor if there was one
Sourcepub fn clear_cursor(&mut self, id: impl Into<ElementId>) -> Option<CursorStyle>
pub fn clear_cursor(&mut self, id: impl Into<ElementId>) -> Option<CursorStyle>
returns the previously set cursor if there was one
Source§impl WindowState
impl WindowState
pub fn mark_style_dirty_with( &mut self, element_id: ElementId, reason: StyleReason, )
pub fn mark_style_dirty(&mut self, element_id: ElementId)
pub fn mark_style_dirty_animation(&mut self, element_id: ElementId)
pub fn mark_style_dirty_transition(&mut self, element_id: ElementId)
pub fn mark_style_dirty_selector( &mut self, element_id: ElementId, selector: StyleSelector, )
Auto Trait Implementations§
impl Freeze for WindowState
impl !RefUnwindSafe for WindowState
impl !Send for WindowState
impl !Sync for WindowState
impl Unpin for WindowState
impl UnsafeUnpin for WindowState
impl !UnwindSafe for WindowState
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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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