pub struct Flex<Msg: Clone> {
pub child: Box<Element<Msg>>,
pub weight: u32,
}Expand description
Wraps an Element so that a Row treats it
like a Spacer for leftover-width
distribution, but draws the child inside the allocated rect.
Use this to make a non-trivial child fill remaining width without resorting
to a hard-coded max_width. The row computes how much width is left after
the fixed-size siblings, splits it across all flex / spacer children
proportionally to their weight, and gives the flex its share. The wrapped
child sees that share as its layout rect — text inside it triggers its own
elide path on overflow, columns adjust their inner width, etc.
row()
.push( icon )
.push( flex( column().push( title ).push( subtitle ) ) )
.into()Currently only Row honours flex distribution.
Inside a Column a flex child behaves
like a regular zero-width child along the main axis — vertical flex is not
yet implemented.
Fields§
§child: Box<Element<Msg>>§weight: u32Implementations§
Source§impl<Msg: Clone> Flex<Msg>
impl<Msg: Clone> Flex<Msg>
pub fn new(child: impl Into<Element<Msg>>) -> Self
Sourcepub fn weight(self, w: u32) -> Self
pub fn weight(self, w: u32) -> Self
Relative weight when sharing leftover width with other flex / spacer
children in the same row (default 1). A flex with weight = 2
claims twice the space of a sibling with weight = 1.
pub fn preferred_size(&self, max_width: f32, canvas: &Canvas) -> (f32, f32)
Trait Implementations§
Auto Trait Implementations§
impl<Msg> Freeze for Flex<Msg>
impl<Msg> !RefUnwindSafe for Flex<Msg>
impl<Msg> !Send for Flex<Msg>
impl<Msg> !Sync for Flex<Msg>
impl<Msg> Unpin for Flex<Msg>
impl<Msg> !UnwindSafe for Flex<Msg>
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