Empty
Stands in for content that is not there yet: media, a title, a description and the actions that fill it.
Default
if let Some(project) = state.project {
ui.vertical_centered(|ui| {
ui.set_min_height(288.0);
ui.add_space(120.0);
ui.label(project);
if ui.add(Button::new("Reset example")).clicked() {
state.project = None;
}
});
} else {
Empty::new()
.icon(glyph(ui.ctx(), "folder"))
.title("No projects yet")
.description("You haven't created any projects yet. Get started by creating your first project.")
.min_height(288.0)
.show(ui, |ui| {
if ui.add(Button::primary("Create project")).clicked() {
state.project = Some("Untitled project");
}
if ui.add(Button::new("Import sample")).clicked() {
state.project = Some("Starter project");
}
});
}
Outline
Empty::new()
.outline()
.icon(glyph(ui.ctx(), "hard-drive"))
.title("Cloud storage is empty")
.description("Upload files to your cloud storage to access them anywhere.")
.show(ui, |ui| ui.add(Button::new("Upload files…").small()));
Background
let muted = tokens(ui.ctx()).muted.gamma_multiply(0.3);
Empty::new()
.fill(muted)
.min_height(256.0)
.icon(glyph(ui.ctx(), "bell"))
.title("No notifications")
.description("You're all caught up. New notifications will appear here.")
.show(ui, |ui| {
ui.add(Button::new("Refresh").icon(glyph(ui.ctx(), "refresh")))
});
Avatar
Empty::new()
.media(|ui| {
ui.add(
Avatar::new()
.name("Alex Morgan")
.image(portrait(ui.ctx(), 1)),
);
})
.title("Alex is offline")
.description("You can leave a message for Alex to read when they're back.")
.show(ui, |ui| ui.add(Button::primary("Leave a message…").small()));
Avatar group
Empty::new()
.media(|ui| {
ui.add(
AvatarGroup::new()
.child(
Avatar::new()
.name("Alex Morgan")
.image(portrait(ui.ctx(), 1)),
)
.child(
Avatar::new()
.name("Taylor Lee")
.image(portrait(ui.ctx(), 3)),
)
.child(Avatar::new().name("Sam Chen").image(portrait(ui.ctx(), 2))),
);
})
.title("No team members")
.description("Invite your team to collaborate on this project.")
.show(ui, |ui| {
ui.add(
Button::primary("Invite members…")
.small()
.icon(glyph(ui.ctx(), "plus")),
)
});
Search
ui.add(egui::TextEdit::singleline(&mut state.query).hint_text("Search projects"));
let query = state.query.to_lowercase();
let found: Vec<&str> = ["Design system", "Website", "Mobile app"]
.into_iter()
.filter(|name| name.to_lowercase().contains(&query))
.collect();
if found.is_empty() {
Empty::new()
.icon(glyph(ui.ctx(), "search"))
.title("No projects found")
.description(format!(
"Nothing matches \"{}\". Try another search.",
state.query
))
.show(ui, |ui| {
if ui.add(Button::new("Clear search")).clicked() {
state.query.clear();
}
});
} else {
for name in found {
ui.label(name);
}
}
The story above is gallery/src/stories/empty.rs, running in your browser. Every snippet on this page is cut from it.