GPUI Box GitHub

Components / display

ProgressBar builder

A horizontal bar for work whose extent is known.

A builder is RenderOnce. Construct and mount it in one expression.

use gpui_kit::display::progress::ProgressBar;

Reviewed in progress-bar.

Also drawn by motion-state, which arranges components rather than reviewing them.

Construct
new(ident: impl Into<Ident>) -> Self
Options

Chain onto the value.

label(label: impl Into<SharedString>) -> Self
fraction(fraction: f32) -> Self
count(done: usize, total: usize) -> Self
display(display: impl Into<SharedString>) -> Self
stalled(stalled: bool) -> Self
paused(paused: bool) -> Self
on_cancel(handler: impl Fn(&mut Window, &mut App) + 'static) -> Self
Example · progress-bar
fn progress_bar(_window: &mut Window, cx: &mut App) -> AnyElement {
    let theme = cx.theme().clone();
    stack(&theme)
        .w(px(420.0))
        .child(caption(&theme, "A count the host reported"))
        .child(
            ProgressBar::new("scene.progress-bar.counted")
                .label("Indexing workspace")
                .count(3, 12),
        )
        .child(
            ProgressBar::new("scene.progress-bar.nearly")
                .label("Uploading")
                .count(11, 12),
        )
        .child(caption(
            &theme,
            "No count yet. The bar says it is working, and does not invent a fraction",
        ))
        .child(ProgressBar::new("scene.progress-bar.unknown").label("Contacting host"))
        .child(caption(&theme, "Stopped, without inventing a fraction"))
        .child(
            ProgressBar::new("scene.progress-bar.stalled")
                .label("Indexing workspace")
                .count(3, 12)
                .stalled(true),
        )
        .child(
            ProgressBar::new("scene.progress-bar.paused")
                .label("Uploading")
                .count(6, 12)
                .paused(true)
                .on_cancel(|_, _| {}),
        )
        .into_any_element()
}

Source: crates/gpui-kit/src/display/progress.rs