Skip to main content

WindowState

Struct WindowState 

Source
pub struct WindowState { /* private fields */ }
Expand description

Encapsulates and owns the global state of the application,

Implementations§

Source§

impl WindowState

Source

pub fn new(root_view_id: ViewId, os_theme: Option<Theme>, os_scale: f64) -> Self

Source

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:

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.

Source

pub fn remove_view(&mut self, id: ViewId)

This removes a view from the app state.

Source

pub fn is_hovered(&self, id: impl Into<ElementId>) -> bool

Source

pub fn is_file_hover(&self, id: impl Into<ElementId>) -> bool

Source

pub fn is_focused(&self, id: impl Into<ElementId>) -> bool

Source

pub fn is_focus_within(&self, id: impl Into<ElementId>) -> bool

Source

pub fn is_clicking(&self, id: impl Into<ElementId>) -> bool

👎Deprecated:

use ViewId::is_active instead

Source

pub fn is_active(&self, id: impl Into<ElementId>) -> bool

Source

pub fn has_capture(&self, id: impl Into<ElementId>) -> bool

Check if a view has pointer capture for any pointer.

Source

pub fn is_dark_mode(&self) -> bool

Source

pub fn is_dragging(&self) -> bool

Source

pub fn set_root_size(&mut self, size: Size)

Source

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.

Source

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.

Source

pub fn compute_layout(&mut self)

Source

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.

Source

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.

Source

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.

Source

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:

  1. Apply drag-preview world position override (if an active drag preview exists)
  2. Apply overlay parent-space remap (apply_overlay_parent_transforms)
  3. Apply fixed-position viewport placement (apply_fixed_positioning_transforms)
  4. Commit the box tree, producing dirty/damage regions
  5. 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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn request_paint(&mut self, _id: impl Into<ElementId>)

Source

pub fn set_cursor( &mut self, id: impl Into<ElementId>, cursor: CursorStyle, ) -> Option<CursorStyle>

returns the previously set cursor if there was one

Source

pub fn clear_cursor(&mut self, id: impl Into<ElementId>) -> Option<CursorStyle>

returns the previously set cursor if there was one

Source§

impl WindowState

Source

pub fn mark_style_dirty_with( &mut self, element_id: ElementId, reason: StyleReason, )

Source

pub fn mark_style_dirty(&mut self, element_id: ElementId)

Source

pub fn mark_style_dirty_animation(&mut self, element_id: ElementId)

Source

pub fn mark_style_dirty_transition(&mut self, element_id: ElementId)

Source

pub fn mark_style_dirty_selector( &mut self, element_id: ElementId, selector: StyleSelector, )

Auto Trait Implementations§

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
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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