pub struct Responsive {
pub id: Option<WidgetId>,
pub query: ResponsiveQuery,
pub cases: Vec<ResponsiveCase>,
pub fallback: Widget,
}Expand description
Selects a widget branch using declarative viewport or container breakpoints.
Prefer Responsive over manually reading view.viewport_size() when the
rule is only “render this child below or above this width”. Keep viewport
reads for cases that also depend on app state, environment values, or
measured geometry.
§Example
Responsive::new(DesktopShell)
.id(WidgetId::explicit("mail.responsive"))
.case(ResponsiveCase::max_width(900.0, PhoneShell))
.case(ResponsiveCase::between(900.0, 1200.0, TabletShell))
.into()Every branch is lowered, even though layout displays only the selected one.
Build each branch independently rather than cloning a Widget value, and
keep explicit widget IDs unique across the complete responsive tree.
Fields§
§id: Option<WidgetId>Optional stable identity for diagnostics and retained child identity.
query: ResponsiveQueryWidth source used to evaluate the responsive cases.
cases: Vec<ResponsiveCase>Ordered cases; the first matching case wins.
fallback: WidgetChild rendered when no case matches.
Implementations§
Source§impl Responsive
impl Responsive
Sourcepub fn new(fallback: impl Into<Widget>) -> Self
pub fn new(fallback: impl Into<Widget>) -> Self
Creates a responsive switch with a required fallback branch.
Sourcepub fn id(self, id: WidgetId) -> Self
pub fn id(self, id: WidgetId) -> Self
Sets an explicit identity for deterministic inspection and diffing.
Sourcepub fn case(self, case: ResponsiveCase) -> Self
pub fn case(self, case: ResponsiveCase) -> Self
Appends an ordered responsive case.
Sourcepub fn query(self, query: ResponsiveQuery) -> Self
pub fn query(self, query: ResponsiveQuery) -> Self
Selects viewport or parent-container width evaluation.
Sourcepub fn container_query(self) -> Self
pub fn container_query(self) -> Self
Evaluates cases against the immediate parent constraints.
Trait Implementations§
Source§impl Clone for Responsive
impl Clone for Responsive
Source§fn clone(&self) -> Responsive
fn clone(&self) -> Responsive
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Responsive
impl Debug for Responsive
Source§impl<'de> Deserialize<'de> for Responsive
impl<'de> Deserialize<'de> for Responsive
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<Responsive> for Widget
impl From<Responsive> for Widget
Source§fn from(w: Responsive) -> Self
fn from(w: Responsive) -> Self
Auto Trait Implementations§
impl !RefUnwindSafe for Responsive
impl !UnwindSafe for Responsive
impl Freeze for Responsive
impl Send for Responsive
impl Sync for Responsive
impl Unpin for Responsive
impl UnsafeUnpin for Responsive
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§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.Source§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.Source§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.Source§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.