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
//! Select dropdown view for the showcase application.
use bevy::prelude::*;
use bevy_material_ui::prelude::*;
use bevy_material_ui::select::{SelectBuilder, SelectOption, SpawnSelectChild};
use crate::showcase::common::*;
/// Spawn the select section content.
pub fn spawn_select_section(
parent: &mut ChildSpawnerCommands,
theme: &MaterialTheme,
_icon_font: Handle<Font>,
) {
parent
.spawn(Node {
flex_direction: FlexDirection::Column,
row_gap: Val::Px(16.0),
..default()
})
.with_children(|section| {
spawn_section_header(
section,
theme,
"showcase.section.select.title",
"Select / Dropdown",
"showcase.section.select.description",
"MaterialSelect with options and selection events",
);
let options = vec![
SelectOption::new("")
.label_key("showcase.select.option.1")
.value("opt1"),
SelectOption::new("")
.label_key("showcase.select.option.2")
.value("opt2"),
SelectOption::new("")
.label_key("showcase.select.option.3")
.value("opt3"),
];
// Use enough items to demonstrate a scrollable dropdown with a max height.
let many_options = (1..=40)
.map(|i| SelectOption::new(format!("Option {i}")).value(format!("option_{i}")))
.collect::<Vec<_>>();
section
.spawn(Node {
flex_direction: FlexDirection::Row,
column_gap: Val::Px(24.0),
margin: UiRect::vertical(Val::Px(8.0)),
flex_wrap: FlexWrap::Wrap,
row_gap: Val::Px(16.0),
..default()
})
.with_children(|row| {
row.spawn(Node {
flex_direction: FlexDirection::Column,
row_gap: Val::Px(8.0),
..default()
})
.with_children(|col| {
col.spawn_select_with(
theme,
SelectBuilder::new(options.clone())
.filled()
.label_key("showcase.select.label.filled"),
);
});
row.spawn(Node {
flex_direction: FlexDirection::Column,
row_gap: Val::Px(8.0),
..default()
})
.with_children(|col| {
col.spawn_select_with(
theme,
SelectBuilder::new(options.clone())
.outlined()
.label_key("showcase.select.label.outlined"),
);
});
row.spawn(Node {
flex_direction: FlexDirection::Column,
row_gap: Val::Px(8.0),
..default()
})
.with_children(|col| {
col.spawn_select_with(
theme,
SelectBuilder::new(options.clone())
.outlined()
.label_key("showcase.select.label.with_selection")
.selected(1),
);
});
row.spawn(Node {
flex_direction: FlexDirection::Column,
row_gap: Val::Px(8.0),
..default()
})
.with_children(|col| {
col.spawn((
Text::new("Scrollable dropdown (max height)"),
TextFont {
font_size: 12.0,
..default()
},
TextColor(theme.on_surface_variant),
));
col.spawn_select_with(
theme,
SelectBuilder::new(many_options.clone())
.filled()
.label("Many Options")
.selected(0)
.dropdown_max_height(Val::Px(240.0))
.virtualize(true),
);
});
});
spawn_code_block(section, theme, include_str!("../../select_demo.rs"));
});
}