Skip to main content

CarouselView

Struct CarouselView 

Source
pub struct CarouselView {
Show 22 fields pub key: Option<KeyRef>, pub padding: Option<EdgeInsets>, pub background_color: Option<Color>, pub elevation: Option<f64>, pub shape: Option<ShapeBorderRef>, pub item_clip_behavior: Option<Clip>, pub overlay_color: Option<WidgetStatePropertyRef<Option<Color>>>, pub shrink_extent: f64, pub item_snapping: bool, pub controller: Option<Ref<CarouselController>>, pub scroll_direction: Axis, pub reverse: bool, pub consume_max_weight: bool, pub on_tap: Option<ValueChanged<i32>>, pub enable_splash: bool, pub item_extent: Option<f64>, pub flex_weights: Option<Vec<i32>>, pub children: Vec<WidgetRef>, pub on_index_changed: Option<ValueChanged<i32>>, pub item_builder: Option<CarouselItemBuilder>, pub item_count: Option<i32>, pub infinite: bool,
}
Expand description

A Material Design carousel widget.

The CarouselView presents a scrollable list of items, each of which can dynamically change size based on the chosen layout.

Material Design 3 introduced 4 carousel layouts:

The CarouselView::builder and CarouselView::weighted_builder constructors build their items lazily; with infinite set, the list repeats its items forever.

The properties of the items’ Material that are None come from the CarouselViewTheme, and then from the defaults documented on each field.

See also:

  • CarouselController, which controls the scroll position of this widget.
  • PageView, which is a scrollable list that works page by page.

Fields§

§key: Option<KeyRef>§padding: Option<EdgeInsets>

The amount of space surrounding each carousel item.

Defaults to EdgeInsets::all(4.0).

§background_color: Option<Color>

The background color for each carousel item.

Defaults to ColorScheme::surface.

§elevation: Option<f64>

The z-coordinate of each carousel item.

Defaults to 0.0.

§shape: Option<ShapeBorderRef>

The shape of each carousel item’s Material.

Defaults to a RoundedRectangleBorder with a circular corner radius of 28.0.

§item_clip_behavior: Option<Clip>

The clip behavior for each carousel item.

Defaults to Clip::AntiAlias.

§overlay_color: Option<WidgetStatePropertyRef<Option<Color>>>

The highlight color to indicate the carousel items are in pressed, hovered or focused states.

Defaults to ColorScheme::onSurface with opacities of 0.1 (pressed), 0.08 (hovered) and 0.1 (focused).

§shrink_extent: f64

The minimum allowable extent (size) in the main axis for carousel items in the viewport.

As the carousel scrolls, the first visible item is pinned and gradually shrinks to shrink_extent before disappearing.

Defaults to 0.0.

§item_snapping: bool

The scroll position snaps to the nearest item when scrolling ends.

Defaults to false.

§controller: Option<Ref<CarouselController>>

An object that can be used to control the position to which this scroll view is scrolled.

§scroll_direction: Axis

The Axis along which the scroll view’s offset increases with each item.

Defaults to Axis::Horizontal.

§reverse: bool

Whether the carousel list scrolls in the reading direction.

Defaults to false.

§consume_max_weight: bool

Whether the items scroll past the position of the largest weight so that every item has a chance to be the largest. Only meaningful for the weighted constructors.

Defaults to true.

§on_tap: Option<ValueChanged<i32>>

Called when one of the items is tapped, with its index.

§enable_splash: bool

Whether the items show the ink splash and the overlay colors when they are tapped, hovered or focused.

Defaults to true.

§item_extent: Option<f64>

The extent the children are forced to have in the main axis. Set by CarouselView::new and CarouselView::builder.

§flex_weights: Option<Vec<i32>>

The weights that determine the extent of each item. Set by CarouselView::weighted and CarouselView::weighted_builder.

§children: Vec<WidgetRef>

The child widgets for the carousel; empty for the builder constructors.

§on_index_changed: Option<ValueChanged<i32>>

Called when the leading item changes while the carousel is scrolled.

§item_builder: Option<CarouselItemBuilder>

The builder of the builder constructors, which build the items lazily.

§item_count: Option<i32>

The number of items the builder constructors can build; None means as many as the builder answers.

§infinite: bool

Whether the carousel loops its items forever.

Defaults to false.

Implementations§

Source§

impl CarouselView

Source

pub fn new(item_extent: f64, children: Vec<WidgetRef>) -> CarouselView

Creates a Material Design carousel whose items all have the extent item_extent.

Source

pub fn weighted( flex_weights: Vec<i32>, children: Vec<WidgetRef>, ) -> CarouselView

Creates a Material Design carousel whose items’ extents follow flex_weights.

The length of flex_weights is how many items fit in the viewport at a time.

Source

pub fn builder( item_extent: f64, item_builder: CarouselItemBuilder, ) -> CarouselView

Creates a Material Design carousel that builds its items lazily, each with the extent item_extent.

Source

pub fn weighted_builder( flex_weights: Vec<i32>, item_builder: CarouselItemBuilder, ) -> CarouselView

Creates a Material Design carousel that builds its items lazily, with extents that follow flex_weights.

Source

pub fn key(self, key: KeyRef) -> CarouselView

Dart CarouselView(key:).

Source

pub fn padding(self, padding: EdgeInsets) -> CarouselView

Dart CarouselView(padding:).

Source

pub fn background_color(self, background_color: Color) -> CarouselView

Dart CarouselView(backgroundColor:).

Source

pub fn elevation(self, elevation: f64) -> CarouselView

Dart CarouselView(elevation:).

Source

pub fn shape(self, shape: impl Into<ShapeBorderRef>) -> CarouselView

Dart CarouselView(shape:).

Source

pub fn item_clip_behavior(self, item_clip_behavior: Clip) -> CarouselView

Dart CarouselView(itemClipBehavior:).

Source

pub fn overlay_color( self, overlay_color: WidgetStatePropertyRef<Option<Color>>, ) -> CarouselView

Dart CarouselView(overlayColor:).

Source

pub fn item_snapping(self, item_snapping: bool) -> CarouselView

Dart CarouselView(itemSnapping:).

Source

pub fn shrink_extent(self, shrink_extent: f64) -> CarouselView

Dart CarouselView(shrinkExtent:).

Source

pub fn controller(self, controller: Ref<CarouselController>) -> CarouselView

Dart CarouselView(controller:).

Source

pub fn scroll_direction(self, scroll_direction: Axis) -> CarouselView

Dart CarouselView(scrollDirection:).

Source

pub fn reverse(self, reverse: bool) -> CarouselView

Dart CarouselView(reverse:).

Source

pub fn consume_max_weight(self, consume_max_weight: bool) -> CarouselView

Dart CarouselView.weighted(consumeMaxWeight:).

Source

pub fn on_tap(self, on_tap: ValueChanged<i32>) -> CarouselView

Dart CarouselView(onTap:).

Source

pub fn enable_splash(self, enable_splash: bool) -> CarouselView

Dart CarouselView(enableSplash:).

Source

pub fn on_index_changed( self, on_index_changed: ValueChanged<i32>, ) -> CarouselView

Dart CarouselView(onIndexChanged:).

Source

pub fn item_count(self, item_count: i32) -> CarouselView

Dart CarouselView.builder(itemCount:).

Source

pub fn infinite(self, infinite: bool) -> CarouselView

Dart CarouselView(infinite:).

Trait Implementations§

Source§

impl Debug for CarouselView

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl StatefulWidget for CarouselView

Source§

type State = CarouselViewState

The state this widget creates.
Source§

fn key(&self) -> Option<&KeyRef>

Source§

fn create_state(&self) -> CarouselViewState

Creates the mutable state for this widget at a given location in the tree. Read more
Source§

fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )

Dart’s debugFillProperties: the properties a dump shows for this widget, in Dart’s order. Dart’s Widget base only sets the dense tree style, which the framework does.
Source§

fn debug_check_constructor(&self)

Source§

fn as_preferred_size_widget( &self, ) -> Option<&(dyn PreferredSizeWidget + 'static)>

Source§

fn type_name(&self) -> &'static str

See Widget::type_name. A stateful form another widget kind becomes (an animated or status transition widget) names the widget it wraps.

Auto Trait Implementations§

§

impl !RefUnwindSafe for CarouselView

§

impl !Send for CarouselView

§

impl !Sync for CarouselView

§

impl !UnwindSafe for CarouselView

§

impl Forget for CarouselView

§

impl Freeze for CarouselView
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, *const RcInner<dyn ShapeBorder> is !null: Freeze, PhantomData<RcInner<dyn ShapeBorder>>: Freeze, *const RcInner<dyn WidgetStateProperty<Option<Color>>> is !null: Freeze, PhantomData<RcInner<dyn WidgetStateProperty<Option<Color>>>>: Freeze, NonZero<u32>: Freeze, PhantomData<fn() -> CarouselController>: Freeze, *const RcInner<Keep> is !null: Freeze, PhantomData<RcInner<Keep>>: Freeze, *const RcInner<dyn Fn(&mut App, i32)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, i32)>>: Freeze, *const u8 is !null: Freeze, PhantomData<i32>: Freeze, PhantomData<Rc<dyn Widget>>: Freeze, *const RcInner<dyn Fn(&mut App, AnyElement, i32) -> Option<Rc<dyn Widget>>> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, AnyElement, i32) -> Option<Rc<dyn Widget>>>>: Freeze,

§

impl Move for CarouselView

§

impl Unpin for CarouselView
where Rc<dyn Key>: Unpin, Rc<dyn ShapeBorder>: Unpin, Rc<dyn WidgetStateProperty<Option<Color>>>: Unpin, NonZero<u32>: Unpin, Rc<Keep>: Unpin, Rc<dyn Fn(&mut App, i32)>: Unpin, *const u8 is !null: Unpin, Rc<dyn Widget>: Unpin, Rc<dyn Fn(&mut App, AnyElement, i32) -> Option<Rc<dyn Widget>>>: Unpin,

§

impl UnsafeUnpin for CarouselView
where *const RcInner<dyn Key> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Key>>: UnsafeUnpin, *const RcInner<dyn ShapeBorder> is !null: UnsafeUnpin, PhantomData<RcInner<dyn ShapeBorder>>: UnsafeUnpin, *const RcInner<dyn WidgetStateProperty<Option<Color>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn WidgetStateProperty<Option<Color>>>>: UnsafeUnpin, NonZeroU32Inner: UnsafeUnpin, PhantomData<fn() -> CarouselController>: UnsafeUnpin, *const RcInner<Keep> is !null: UnsafeUnpin, PhantomData<RcInner<Keep>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, i32)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, i32)>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<i32>: UnsafeUnpin, PhantomData<Rc<dyn Widget>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, AnyElement, i32) -> Option<Rc<dyn Widget>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, AnyElement, i32) -> Option<Rc<dyn Widget>>>>: UnsafeUnpin,

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
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<W> IntoWidget<StatefulKind> for W
where W: StatefulWidget,

Source§

fn into_widget(self) -> Rc<dyn Widget>

The widget as a tree node, made where this is called: its creation_location.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> Upcast<T> for T

Source§

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