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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
//! Tooltips view for the showcase application.
use bevy::prelude::*;
use bevy_material_ui::prelude::*;
use crate::showcase::common::*;
/// Spawn the tooltip section content
pub fn spawn_tooltip_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.tooltips.title",
"Tooltips",
"showcase.section.tooltips.description",
"Contextual information on hover - Configure options below",
);
// Options panel
section
.spawn(Node {
flex_direction: FlexDirection::Column,
padding: UiRect::all(Val::Px(12.0)),
row_gap: Val::Px(12.0),
..default()
})
.with_children(|options| {
// Position options
options
.spawn(Node {
flex_direction: FlexDirection::Row,
align_items: AlignItems::Center,
column_gap: Val::Px(8.0),
..default()
})
.with_children(|row| {
row.spawn((
Text::new("Position:"),
TextFont {
font_size: 12.0,
..default()
},
TextColor(theme.on_surface_variant),
));
// Position buttons (exclusive)
for (label, pos) in [
("Top", TooltipPosition::Top),
("Bottom", TooltipPosition::Bottom),
("Left", TooltipPosition::Left),
("Right", TooltipPosition::Right),
] {
let selected = pos == TooltipPosition::Bottom;
let button = MaterialButton::new(label).with_variant(if selected {
ButtonVariant::FilledTonal
} else {
ButtonVariant::Outlined
});
let label_color = button.text_color(theme);
row.spawn((
TooltipPositionOption(pos),
Interaction::None,
MaterialButtonBuilder::new(label)
.variant(if selected {
ButtonVariant::FilledTonal
} else {
ButtonVariant::Outlined
})
.build(theme),
))
.with_children(|btn| {
btn.spawn((
ButtonLabel,
Text::new(label),
TextFont {
font_size: 12.0,
..default()
},
TextColor(label_color),
));
});
}
});
// Delay options
options
.spawn(Node {
flex_direction: FlexDirection::Row,
align_items: AlignItems::Center,
column_gap: Val::Px(8.0),
..default()
})
.with_children(|row| {
row.spawn((
Text::new("Delay:"),
TextFont {
font_size: 12.0,
..default()
},
TextColor(theme.on_surface_variant),
));
for (label, delay) in
[("0.15s", 0.15_f32), ("0.5s", 0.5_f32), ("1.0s", 1.0_f32)]
{
let selected = (delay - 0.5).abs() < 0.01;
let button = MaterialButton::new(label).with_variant(if selected {
ButtonVariant::FilledTonal
} else {
ButtonVariant::Outlined
});
let label_color = button.text_color(theme);
row.spawn((
TooltipDelayOption(delay),
Interaction::None,
MaterialButtonBuilder::new(label)
.variant(if selected {
ButtonVariant::FilledTonal
} else {
ButtonVariant::Outlined
})
.build(theme),
))
.with_children(|btn| {
btn.spawn((
ButtonLabel,
Text::new(label),
TextFont {
font_size: 12.0,
..default()
},
TextColor(label_color),
));
});
}
});
});
section
.spawn(Node {
flex_direction: FlexDirection::Row,
column_gap: Val::Px(32.0),
margin: UiRect::vertical(Val::Px(8.0)),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
..default()
})
.with_children(|row| {
// Interactive tooltip demo button
let demo_label = "Hover Me";
let demo_button =
MaterialButton::new(demo_label).with_variant(ButtonVariant::Filled);
let demo_text_color = demo_button.text_color(theme);
row.spawn((
TooltipDemoButton,
TooltipTrigger::new("Hover to see tooltip!").bottom(),
Interaction::None,
MaterialButtonBuilder::new(demo_label).filled().build(theme),
))
.with_children(|btn| {
btn.spawn((
ButtonLabel,
Text::new(demo_label),
TextFont {
font_size: 14.0,
..default()
},
TextColor(demo_text_color),
));
});
row.spawn((
Text::new("← Hover to test tooltip with selected options"),
TextFont {
font_size: 12.0,
..default()
},
TextColor(theme.on_surface_variant),
));
});
spawn_code_block(section, theme, include_str!("../../tooltip_demo.rs"));
});
}