pub struct NodeSize { /* private fields */ }Expand description
Reads the window’s size class inside a component, and re-renders it when the class changes.
ⓘ
let window = use_window_size();
rsx! {
if window.is_expanded() {
Row { Sidebar {} Content {} }
} else {
Content {}
}
}Only components that call this are woken, and only when the class actually changes. Resizing inside one class re-renders nothing. A node whose measured size this component follows.
The token is the name the screen gives the node, because a node id belongs to the
Renderer and never crosses back as something the Host chose. Attach it with
observe_size and read the size here.
ⓘ
let panel = use_node_size();
rsx! {
Card {
observe_size: panel.token(),
if panel.is_expanded() { Row { Left {} Right {} } } else { Left {} }
}
}A component that never calls this costs nothing: the modifier is the only thing that makes the Renderer measure, and the modifier comes from here.
Implementations§
Source§impl NodeSize
impl NodeSize
Sourcepub fn is_compact(&self) -> bool
pub fn is_compact(&self) -> bool
Phone-shaped: narrower than 600dp.
Sourcepub fn is_expanded(&self) -> bool
pub fn is_expanded(&self) -> bool
Desktop-shaped.
Sourcepub const fn measured(&self) -> WindowSize
pub const fn measured(&self) -> WindowSize
The measurement itself, zero until the Renderer has reported one.
Trait Implementations§
impl Copy for NodeSize
impl StructuralPartialEq for NodeSize
Auto Trait Implementations§
impl Freeze for NodeSize
impl RefUnwindSafe for NodeSize
impl Send for NodeSize
impl Sync for NodeSize
impl Unpin for NodeSize
impl UnsafeUnpin for NodeSize
impl UnwindSafe for NodeSize
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DependencyElement for T
Source§impl<T> InitializeFromFunction<T> for T
impl<T> InitializeFromFunction<T> for T
Source§fn initialize_from_function(f: fn() -> T) -> T
fn initialize_from_function(f: fn() -> T) -> T
Create an instance of this type from an initialization function
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<Ret> SpawnIfAsync<(), Ret> for Ret
impl<Ret> SpawnIfAsync<(), Ret> for Ret
Source§impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
Source§fn super_from(input: T) -> O
fn super_from(input: T) -> O
Convert from a type to another type.
Source§impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
Source§fn super_into(self) -> O
fn super_into(self) -> O
Convert from a type to another type.