Components / display
EmptyState builder
A centred explanation with an optional action.
A builder is RenderOnce. Construct and mount it in one expression.
use gpui_kit::display::empty::EmptyState;
Reviewed in empty-state.
Construct
new(ident: impl Into<Ident>, title: impl Into<SharedString>) -> Self
Options
Chain onto the value.
kind(kind: EmptyKind) -> Self
icon(glyph: Icon) -> Self
detail(detail: impl Into<SharedString>) -> Self
action(action: impl IntoElement) -> Self
Example · empty-state
fn empty_state(_window: &mut Window, cx: &mut App) -> AnyElement {
let theme = cx.theme().clone();
// An empty state fills the region whose contents are missing. Drawn on
// bare canvas it reads as loose centred text with no edge to be centred
// in, which is the one thing it never is in a product.
let region = |state: EmptyState| {
div()
.w_full()
.radius(&theme, Radius::Card)
.frame(&theme, Surface::Panel, Elevation::Raised)
.child(state)
};
stack(&theme)
.w(px(560.0))
.child(caption(&theme, "Nothing has been started yet"))
.child(region(
EmptyState::new("scene.empty-state.unstarted", "No runs yet")
.kind(EmptyKind::Unstarted)
.detail("A run appears here once one has been started."),
))
.child(caption(&theme, "The host refused, and says so"))
.child(region(
EmptyState::new(
"scene.empty-state.unavailable",
"The host refused the request",
)
.kind(EmptyKind::Unavailable)
.detail("Approval is required for this workspace.")
.action(
Button::new("scene.empty-state.retry")
.label("Try again")
.on_click(|_, _| {}),
),
))
.child(caption(&theme, "A collection that really is empty"))
.child(region(
EmptyState::new("scene.empty-state.empty", "No runs match “failing”")
.kind(EmptyKind::Empty)
.detail("Clear the filter to see every run."),
))
.child(caption(&theme, "It was tried, and it failed"))
.child(region(
EmptyState::new("scene.empty-state.failed", "The run could not be read")
.kind(EmptyKind::Failed)
.detail("The snapshot on disk is from a newer version of the format.")
.action(
Button::new("scene.empty-state.reload")
.label("Reload")
.on_click(|_, _| {}),
),
))
.child(caption(
&theme,
"The host refused because the reader is not allowed",
))
.child(region(
EmptyState::new("scene.empty-state.unauthorized", "This workspace is locked")
.kind(EmptyKind::Unauthorized)
.detail("Ask an owner to grant access."),
))
.into_any_element()
}