Components / layout
Dock builder
Panels arranged in regions around a centre.
A builder is RenderOnce. Construct and mount it in one expression.
use gpui_kit::layout::Dock;
Reviewed in ide-shell.
Construct
new(ident: impl Into<Ident>) -> Self
Options
Chain onto the value.
panel(region: DockRegion, panel: DockPanel) -> Self
panels(region: DockRegion, panels: impl IntoIterator<Item = DockPanel>) -> Self
active(region: DockRegion, panel: impl Into<SharedString>) -> Self
collapsed(region: DockRegion, collapsed: bool) -> Self
share(region: DockRegion, share: f32) -> Self
min_size(region: DockRegion, min: f32) -> Self
on_event(handler: impl Fn(DockEvent, &mut Window, &mut App) + 'static) -> Self
Reports
The variants of the event it emits. It never applies the change itself.
- PanelSelected
- PanelMoved
- RegionCollapsed
- RegionResized
Example · ide-shell
fn ide_shell(_window: &mut Window, cx: &mut App) -> AnyElement {
let theme = cx.theme().clone();
let mut branch = AsyncValue::<SharedString, String>::ready("main@a1b2c3".into());
branch.refresh();
branch.fail_refresh("the host is unreachable".into());
div()
.column()
.w(px(900.0))
.h(px(940.0))
.bg(theme.colors.canvas)
.text_color(theme.colors.text)
.font_family(theme.typography.sans.clone())
.child(
div().flex_1().min_h(px(0.0)).child(
Dock::new("scene.shell")
.share(DockRegion::Left, 0.24)
// The bottom region holds one refused panel, and a refusal
// is a sentence rather than a document: given a third of
// the frame it reads as a region that lost its content
// instead of as a panel the host would not open.
.share(DockRegion::Bottom, 0.17)
.panel(
DockRegion::Left,
DockPanel::new("files", "Files")
.icon(Icon::Folder)
.content(filler(&theme, "Workspace", 8)),
)
.panel(
DockRegion::Left,
DockPanel::new("search", "Search")
.icon(Icon::Magnifier)
.badge("12"),
)
.active(DockRegion::Left, "files")
.panel(
DockRegion::Centre,
DockPanel::new("editor", "main.rs")
.icon(Icon::Document)
.content(filler(&theme, "fn main()", 12)),
)
.panel(
DockRegion::Right,
DockPanel::new("outline", "Outline").icon(Icon::List),
)
.panel(
DockRegion::Right,
DockPanel::new("history", "History").icon(Icon::GitBranch),
)
.collapsed(DockRegion::Right, true)
.panel(
DockRegion::Bottom,
DockPanel::new("terminal", "Terminal")
.icon(Icon::Terminal)
.content(filler(&theme, "$ cargo test", 4)),
)
.panel(
DockRegion::Bottom,
// No badge: a panel that cannot list problems cannot
// count them either, and one unavailable reason is the
// whole claim. Gluing "there is nothing here" onto it
// would report Empty and Unavailable at once.
DockPanel::new("problems", "Problems")
.icon(Icon::Danger)
.unavailable(
"The language server is not running, so problems cannot be listed.",
),
)
// The refused panel is the one on top, because a refusal
// nobody can see is a refusal nobody was told about.
.active(DockRegion::Bottom, "problems")
.on_event(|_, _, _| {}),
),
)
.child(
StatusBar::new("scene.shell.status")
.label("Workspace status")
.start([
StatusItem::text("branch", "main")
.icon(Icon::GitBranch)
.tracking(&branch),
StatusItem::state("build", "Build passing", Tone::Success),
])
.centre([StatusItem::progress("index", "Indexing the workspace")
.count(7, 12)
.state_name("loading")])
.end([
StatusItem::text("position", "Ln 42, Col 7"),
StatusItem::action("encoding", "UTF-8").on_click(|_, _| {}),
]),
)
.into_any_element()
}