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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//! Scroll view for the showcase application.
use bevy::prelude::*;
use bevy_material_ui::prelude::*;
use crate::showcase::common::*;
/// Spawn the scroll section content
pub fn spawn_scroll_section(parent: &mut ChildSpawnerCommands, theme: &MaterialTheme) {
parent
.spawn(Node {
flex_direction: FlexDirection::Column,
row_gap: Val::Px(20.0),
..default()
})
.with_children(|section| {
spawn_section_header(
section,
theme,
"showcase.section.scroll.title",
"Scroll",
"showcase.section.scroll.description",
"Material scroll containers with customizable scrollbars",
);
// Vertical scroller
section
.spawn(Node {
flex_direction: FlexDirection::Column,
row_gap: Val::Px(8.0),
..default()
})
.with_children(|col| {
col.spawn((
Text::new("Vertical scrollbar"),
TextFont {
font_size: 14.0,
..default()
},
TextColor(theme.on_surface_variant),
));
col.spawn((
ScrollContainerBuilder::new().vertical().build(),
ScrollPosition::default(),
Node {
width: Val::Px(360.0),
height: Val::Px(140.0),
overflow: Overflow::scroll(),
padding: UiRect::all(Val::Px(12.0)),
flex_direction: FlexDirection::Column,
row_gap: Val::Px(8.0),
border_radius: BorderRadius::all(Val::Px(12.0)),
..default()
},
BackgroundColor(theme.surface_container_low),
))
.with_children(|content| {
for i in 1..=20 {
content.spawn((
Text::new(format!("Item {i}")),
TextFont {
font_size: 14.0,
..default()
},
TextColor(theme.on_surface),
));
}
});
});
// Horizontal scroller
section
.spawn(Node {
flex_direction: FlexDirection::Column,
row_gap: Val::Px(8.0),
..default()
})
.with_children(|col| {
col.spawn((
Text::new("Horizontal scrollbar"),
TextFont {
font_size: 14.0,
..default()
},
TextColor(theme.on_surface_variant),
));
col.spawn((
ScrollContainerBuilder::new().horizontal().build(),
ScrollPosition::default(),
Node {
width: Val::Px(360.0),
height: Val::Px(100.0),
overflow: Overflow::scroll(),
padding: UiRect::all(Val::Px(12.0)),
flex_direction: FlexDirection::Row,
column_gap: Val::Px(12.0),
border_radius: BorderRadius::all(Val::Px(12.0)),
..default()
},
BackgroundColor(theme.surface_container_low),
))
.with_children(|content| {
for i in 1..=20 {
content
.spawn((
Node {
width: Val::Px(80.0),
height: Val::Px(60.0),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
flex_shrink: 0.0,
border_radius: BorderRadius::all(Val::Px(8.0)),
..default()
},
BackgroundColor(theme.surface_container_high),
))
.with_children(|card| {
card.spawn((
Text::new(format!("{i}")),
TextFont {
font_size: 14.0,
..default()
},
TextColor(theme.on_surface),
));
});
}
});
});
spawn_code_block(section, theme, include_str!("../../scroll_demo.rs"));
});
}