Attachment
A file chip or card with an icon by type, its name and size, upload progress, and remove and retry controls.
File types
for (name, bytes) in [
("report.pdf", 2_400_000),
("cover.png", 840_000),
("intro.mov", 48_000_000),
("voice-note.m4a", 320_000),
("archive.zip", 12_400_000),
("main.rs", 18_000),
("budget.xlsx", 64_000),
("LICENSE", 1_100),
] {
Attachment::new(name).bytes(bytes).show(ui);
}
Status
Attachment::new("queued.pdf")
.bytes(2_400_000)
.status(AttachmentStatus::Pending)
.show(ui);
Attachment::new("uploading.pdf")
.bytes(2_400_000)
.status(AttachmentStatus::Uploading)
.progress(42.0)
.show(ui);
Attachment::new("processing.mov")
.bytes(48_000_000)
.status(AttachmentStatus::Processing)
.show(ui);
let failed = Attachment::new("failed.pdf")
.description("Upload failed")
.status(AttachmentStatus::Failed)
.retryable(true)
.show(ui);
if failed.retry_clicked {
state.retried += 1;
}
Attachment::new("done.pdf").bytes(2_400_000).show(ui);
Removable
let mut removed = None;
AttachmentGroup::new("composer-files").show(ui, |ui| {
for (index, (name, bytes)) in state.files.iter().enumerate() {
let shown = Attachment::new(*name)
.bytes(*bytes)
.removable(true)
.id_salt(*name)
.show(ui);
if shown.remove_clicked {
removed = Some(index);
}
}
});
if let Some(index) = removed {
state.files.remove(index);
}
Cards
Attachment::new("design-notes.pdf")
.bytes(2_400_000)
.vertical(true)
.show(ui);
Attachment::new("intro.mov")
.kind(AttachmentKind::Video)
.description("Uploading")
.vertical(true)
.status(AttachmentStatus::Uploading)
.progress(64.0)
.show(ui);
Attachment::new("")
.kind(AttachmentKind::Image)
.vertical(true)
.removable(true)
.show(ui);
Sizes
for size in [Size::XSmall, Size::Small, Size::Medium, Size::Large] {
Attachment::new("report.pdf")
.bytes(2_400_000)
.size(size)
.show(ui);
}
Actions
let shown = Attachment::new("sales-dashboard.pdf")
.bytes(2_400_000)
.clickable(true)
.tooltip("Open sales-dashboard.pdf")
.show_with_actions(ui, |ui| ui.add(Button::ghost("Open").small()).clicked());
if shown.clicked || shown.actions == Some(true) {
state.opened += 1;
}
The story above is gallery/src/stories/attachment.rs, running in your browser. Every snippet on this page is cut from it.