pub struct Spacer {
pub weight: u32,
pub fixed_height: Option<Length>,
pub fixed_width: Option<Length>,
}Expand description
A flexible, invisible spacer that expands to fill available space.
The optional weight controls how much of the remaining space this spacer
claims relative to other spacers in the same layout. A spacer with weight = 2
takes twice as much space as one with weight = 1.
Place a Spacer between two widgets inside a Column
or Row to push them apart:
column()
.push( text( "Top" ) )
.push( spacer() ) // pushes "Bottom" to the bottom
.push( text( "Bottom" ) )
.into()Use .weight(n) to replace several consecutive spacers:
// These two are equivalent:
let _: Column<Msg> = column().push( spacer().weight( 3 ) );
let _: Column<Msg> = column().push( spacer() ).push( spacer() ).push( spacer() );Use .height(px) to create a fixed-size vertical spacer:
column()
.push( text( "Header" ) )
.push( spacer().height( 20.0 ) ) // Exactly 20 px gap
.push( text( "Content" ) )
.into().height(...) and .width(...) also accept any crate::Length, so the
gap can scale with the surface instead of being frozen at a px constant:
column()
.push( text( "Header" ) )
// 6 % of the surface's smaller side, never below 16 px or above 64 px.
.push( spacer().height( Length::vmin( 6.0 ).clamp( 16.0, 64.0 ) ) )
.push( text( "Content" ) )
.into()Fields§
§weight: u32Relative weight of this spacer (default 1).
fixed_height: Option<Length>Fixed height (overrides flexible behavior in a column). Accepts any
Length — pass an f32/i32/u32 for the px case (kept for
backward compatibility with existing call sites), or
Length::vmin( … ) etc. for viewport-relative gaps.
fixed_width: Option<Length>Fixed width (overrides flexible behavior in a row). Same length-type
semantics as Self::fixed_height.
Implementations§
Source§impl Spacer
impl Spacer
Sourcepub fn height(self, h: impl Into<Length>) -> Self
pub fn height(self, h: impl Into<Length>) -> Self
Set a fixed height for this spacer. Accepts any Length: a bare
24.0_f32 is treated as Length::px( 24.0 ) for source-level
backwards compatibility; a Length::vmin( 6.0 ) makes the gap
scale with the surface’s smaller dimension.
Sourcepub fn width(self, w: impl Into<Length>) -> Self
pub fn width(self, w: impl Into<Length>) -> Self
Set a fixed width for this spacer. Mirrors Self::height for the
horizontal axis.
Sourcepub fn preferred_size(&self, canvas: &Canvas) -> (f32, f32)
pub fn preferred_size(&self, canvas: &Canvas) -> (f32, f32)
Returns ( fixed_width, fixed_height ) resolved against the
current canvas viewport, falling back to 0.0 on axes that were
not pinned. The parent layout distributes leftover along its main
axis among the still-flexible spacers and Flex wrappers,
weighted by weight.
Sourcepub fn resolved_height(&self, canvas: &Canvas) -> Option<f32>
pub fn resolved_height(&self, canvas: &Canvas) -> Option<f32>
Resolved fixed height in logical pixels, or None when the
spacer is flex. Cheaper than Self::preferred_size when the
layout only needs the main-axis size for one orientation.
pub fn resolved_width(&self, canvas: &Canvas) -> Option<f32>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Spacer
impl RefUnwindSafe for Spacer
impl Send for Spacer
impl Sync for Spacer
impl Unpin for Spacer
impl UnwindSafe for Spacer
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> DowncastSync for T
impl<T> DowncastSync for T
§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