Progress
How far along some work is, or that it is under way: a bar, a ring, a spinner or one of the apps’ activity marks, sliding smoothly between values, stepping ten times a second while nobody knows how far, and still when the app asks for reduced motion.
Upload
egui::Frame::new()
.stroke(egui::Stroke::new(1.0, theme.border))
.corner_radius(theme.shape.radius_lg)
.inner_margin(16.0)
.show(ui, |ui| {
ui.vertical(|ui| {
ui.set_width(368.0);
ui.spacing_mut().item_spacing.y = 12.0;
ui.horizontal(|ui| {
ui.label("Uploading design-assets.zip");
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
ui.label(egui::RichText::new(format!("{}%", state.value)).color(muted));
});
});
ui.add(
Progress::new()
.value(value)
.style(&progress_styles::Linear)
.size(size)
.label("Upload progress"),
);
ui.horizontal(|ui| {
ui.label(egui::RichText::new("24.8 MB of 96 MB").small().color(muted));
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
let left = if state.loading {
"Calculating…"
} else {
"About 1 min left"
};
ui.label(egui::RichText::new(left).small().color(muted));
});
});
});
});
Circular
egui::Frame::new()
.fill(theme.muted.gamma_multiply(0.4))
.corner_radius(theme.shape.radius_lg)
.inner_margin(16.0)
.show(ui, |ui| {
ui.vertical(|ui| {
ui.set_width(368.0);
ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = 20.0;
let mut ring = Progress::new()
.value(value)
.style(&progress_styles::Ring)
.width(80.0)
.label("Analysis progress");
if !state.loading {
ring = ring
.text(egui::RichText::new(format!("{}%", state.value)).strong());
}
ui.add(ring);
ui.vertical(|ui| {
ui.label("Analysing project");
let detail = if state.loading {
"Preparing analysis…"
} else {
"Scanning components and dependencies."
};
ui.label(egui::RichText::new(detail).color(muted));
});
});
});
});
Sizes
for size in [Size::XSmall, Size::Small, Size::Medium, Size::Large] {
ui.add(
Progress::new()
.value(state.value)
.style(&progress_styles::Circular)
.size(size),
);
}
ui.add(Progress::new().value(state.value).size(size).width(200.0));
Spinner
// Without a value, a spinner.
ui.add(Progress::new().size(size));
Colour
ui.add(Progress::new().size(size).color(hues.blue));
ui.add(Progress::new().size(size).color(hues.green));
Custom size
ui.add(Progress::new().width(64.0));
Icon
ui.add(
Progress::new()
.size(size)
.icon(glyph(ui.ctx(), "loader-circle")),
);
ui.add(
Progress::new()
.size(size)
.icon(glyph(ui.ctx(), "loader-circle"))
.color(hues.cyan),
);
Easing
// Linear, bounced (out and back) and ease-out-quint turns.
ui.add(Progress::new().size(size).ease(|t| t));
ui.add(Progress::new().size(size).ease(|t| {
let t = if t < 0.5 { t * 2.0 } else { 2.0 - t * 2.0 };
if t < 0.5 {
2.0 * t * t
} else {
1.0 - (2.0 - 2.0 * t).powi(2) / 2.0
}
}));
ui.add(Progress::new().size(size).ease(|t| 1.0 - (1.0 - t).powi(5)));
Styles
// Each style without a value, then with the value picked above.
let styles: [(&str, &dyn ProgressStyle); 7] = [
("Automatic", &progress_styles::Automatic),
("Linear", &progress_styles::Linear),
("Circular", &progress_styles::Circular),
("Ring", &progress_styles::Ring),
("Orbit", &progress_styles::Orbit),
("Dots", &progress_styles::Dots),
("Bars", &progress_styles::Bars),
];
egui::Grid::new("progress-styles")
.num_columns(3)
.spacing(egui::vec2(24.0, 14.0))
.show(ui, |ui| {
for (name, style) in styles {
ui.label(egui::RichText::new(name).color(muted));
// A bar fills its cell.
let cell = egui::vec2(160.0, 24.0);
ui.allocate_ui(cell, |ui| ui.add(Progress::new().style(style).size(size)));
ui.allocate_ui(cell, |ui| {
ui.add(Progress::new().value(state.value).style(style).size(size))
});
ui.end_row();
}
});
Tints
ui.add(
Progress::new()
.style(&progress_styles::Orbit)
.tint(Tint::Success),
);
ui.add(
Progress::new()
.style(&progress_styles::Dots)
.tint(Tint::Info),
);
ui.add(
Progress::new()
.style(&progress_styles::Bars)
.tint(Tint::Warning),
);
ui.add(
Progress::new()
.value(state.value)
.style(&progress_styles::Circular)
.tint(Tint::Danger),
);
A style for a whole area
// Every indicator inside takes the style and size, unless it picks
// its own.
ui.control_size(Size::Large, |ui| {
ui.progress_style(progress_styles::Dots, |ui| {
ui.add(Progress::new().label("Mara is typing"));
ui.add(Progress::new().label("Theo is typing"));
ui.add(Progress::new().style(&progress_styles::Bars));
});
});
Your own style
ui.progress_style(Blocks, |ui| {
ui.add(Progress::new().value(state.value).label("Export"));
ui.add(Progress::new().label("Searching"));
ui.add(
Progress::new()
.value(state.value)
.tint(Tint::Success)
.width(200.0),
);
});
The story above is gallery/src/stories/progress.rs, running in your browser. Every snippet on this page is cut from it.