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#[derive(Clone, Debug)]
16pub struct CarouselConfig {
17 pub modifier: Modifier,
18}
19
20impl Default for CarouselConfig {
21 fn default() -> Self {
22 Self {
23 modifier: Modifier::new(),
24 }
25 }
26}
27
28pub fn Carousel<T, F>(
33 items: Vec<T>,
34 item_width: f32,
35 peek_amount: f32,
36 state: Rc<LazyRowState>,
37 item_builder: F,
38 config: CarouselConfig,
39) -> View
40where
41 T: Clone + 'static,
42 F: Fn(T, usize) -> View + 'static,
43{
44 let padded_modifier = config.modifier.padding_values(PaddingValues {
45 left: peek_amount,
46 right: peek_amount,
47 top: 0.0,
48 bottom: 0.0,
49 });
50
51 LazyRow(
52 items,
53 item_width,
54 item_builder,
55 LazyRowConfig {
56 state,
57 modifier: padded_modifier,
58 ..Default::default()
59 },
60 )
61}