Skip to main content

MaterialCarousel

Struct MaterialCarousel 

Source
pub struct MaterialCarousel<'a> { /* private fields */ }
Expand description

A Material Design 3 Carousel component.

Carousels display a horizontally scrollable list of items where edge items compress to a smaller size, creating a peek effect.

§Example

let mut offset = 0.0f32;
ui.add(MaterialCarousel::new(&mut offset)
    .item_text("Item 0")
    .item_text("Item 1")
    .item_text("Item 2"));

Implementations§

Source§

impl<'a> MaterialCarousel<'a>

Source

pub fn new(scroll_offset: &'a mut f32) -> Self

Create a new carousel widget.

§Arguments
  • scroll_offset - Mutable reference to persistent scroll state
Source

pub fn item(self, content: impl FnOnce(&mut Ui, Rect) + 'a) -> Self

Add a custom item with a rendering closure.

The closure receives (&mut Ui, Rect) where Rect is the available area.

Source

pub fn item_text(self, label: impl Into<String>) -> Self

Add a simple text-label item.

Source

pub fn item_extent(self, extent: f32) -> Self

Set the full-size width of each item (default: 180.0).

Source

pub fn shrink_extent(self, extent: f32) -> Self

Set the minimum width for edge items (default: 100.0).

Source

pub fn height(self, height: f32) -> Self

Set the height of the carousel (default: 150.0).

Source

pub fn padding(self, padding: f32) -> Self

Set the padding around each item (default: 4.0).

Source

pub fn corner_radius(self, radius: f32) -> Self

Set the corner radius for item shapes (default: 10.0).

Source

pub fn item_snapping(self, snapping: bool) -> Self

Enable or disable item snapping (default: false).

Source

pub fn id_salt(self, salt: impl Into<String>) -> Self

Set an ID salt for unique widget identification.

Trait Implementations§

Source§

impl<'a> Widget for MaterialCarousel<'a>

Source§

fn ui(self, ui: &mut Ui) -> Response

Allocate space, interact, paint, and return a Response. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for MaterialCarousel<'a>

§

impl<'a> !RefUnwindSafe for MaterialCarousel<'a>

§

impl<'a> !Send for MaterialCarousel<'a>

§

impl<'a> !Sync for MaterialCarousel<'a>

§

impl<'a> Unpin for MaterialCarousel<'a>

§

impl<'a> UnsafeUnpin for MaterialCarousel<'a>

§

impl<'a> !UnwindSafe for MaterialCarousel<'a>

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more