1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#![allow(non_snake_case)]
use std::rc::Rc;
use repose_core::*;
use repose_ui::LazyRowState;
use repose_ui::lazy::LazyRow;
use repose_ui::lazy_states::LazyRowConfig;
/// M3 Carousel - a horizontally scrolling container with peek edges.
///
/// Uses a `LazyRow` internally. The first and last items are partially visible
/// (peek) to indicate there is more scrollable content.
/// Configuration for [`Carousel`].
#[derive(Clone, Debug)]
pub struct CarouselConfig {
pub modifier: Modifier,
}
impl Default for CarouselConfig {
fn default() -> Self {
Self {
modifier: Modifier::new(),
}
}
}
/// M3 Carousel - a horizontally scrolling container with peek edges.
///
/// Uses a `LazyRow` internally. The first and last items are partially visible
/// (peek) to indicate there is more scrollable content.
pub fn Carousel<T, F>(
items: Vec<T>,
item_width: f32,
peek_amount: f32,
state: Rc<LazyRowState>,
item_builder: F,
config: CarouselConfig,
) -> View
where
T: Clone + 'static,
F: Fn(T, usize) -> View + 'static,
{
let padded_modifier = config.modifier.padding_values(PaddingValues {
left: peek_amount,
right: peek_amount,
top: 0.0,
bottom: 0.0,
});
LazyRow(
items,
item_width,
item_builder,
LazyRowConfig {
state,
modifier: padded_modifier,
..Default::default()
},
)
}