repose_material/material3/
carousel.rs1#![allow(non_snake_case)]
2
3use std::rc::Rc;
4
5use repose_core::*;
6use repose_ui::LazyRowState;
7use repose_ui::lazy::LazyRow;
8use repose_ui::lazy_states::LazyRowConfig;
9
10
11#[derive(Clone, Debug)]
17pub struct CarouselConfig {
18 pub modifier: Modifier,
19}
20
21impl Default for CarouselConfig {
22 fn default() -> Self {
23 Self {
24 modifier: Modifier::new(),
25 }
26 }
27}
28
29pub fn Carousel<T, F>(
34 items: Vec<T>,
35 item_width: f32,
36 peek_amount: f32,
37 state: Rc<LazyRowState>,
38 item_builder: F,
39 config: CarouselConfig,
40) -> View
41where
42 T: Clone + 'static,
43 F: Fn(T, usize) -> View + 'static,
44{
45 let padded_modifier = config.modifier.padding_values(PaddingValues {
46 left: peek_amount,
47 right: peek_amount,
48 top: 0.0,
49 bottom: 0.0,
50 });
51
52 LazyRow(
53 items,
54 item_width,
55 item_builder,
56 LazyRowConfig {
57 state,
58 modifier: padded_modifier,
59 ..Default::default()
60 },
61 )
62}