You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Dock: allow empty zones, show a default view, and hide empty sides.
#3981
Keep the Entity<Dock2>. Dock2::area() exposes the underlying DockArea
for queries and DockEvent subscriptions; Dock2::skin() exposes the
existing DockSkin settings.
Zone policy
Zone
State
ZoneDefault
Result
Centre
content
any
content
Centre
empty
custom
custom default
Centre
empty
none
built-in empty state, visible
Left / Right / Bottom
content
any
content, visible
Left / Right / Bottom
empty
set
default, visible
Left / Right / Bottom
empty
none
hidden automatically
Left / Right / Bottom
user hidden
any
hidden until explicitly opened
Hiding means is_dock_open == false. The dock, its tree, and its size are
kept, so reopening restores the previous layout. Dock2 never removes a dock
automatically.
Zone defaults
ZoneDefault is a view factory, not a panel. It has no PanelId, tab, drag
state, close action, zoom, or persisted layout entry.
use gpui_kit::component::{
button::Button,
dock2::ZoneDefault,
empty::{Empty,EmptyContent,EmptyDescription,EmptyHeader,EmptyTitle},};
dock2.update(cx, |dock2, cx| {
dock2.set_zone_default(DockPlacement::Left,Some(ZoneDefault::empty(|_, _| {Empty::new().border_0().p_4().header(EmptyHeader::new().title(EmptyTitle::new().child("No explorer")).description(EmptyDescription::new().child("Open a folder to browse files."),),).content(EmptyContent::new().child(Button::new("open-folder").label("Open folder…"),))})),
window,
cx,);});
Use ZoneDefault::new for an arbitrary element, ZoneDefault::empty for an Empty factory, ZoneDefault::view for a stateful AnyView, and with_focus_handle when focus should return to the default after its panel
closes.
Setting a default on an absent side creates the dock at the default size and
opens it. Removing the default from an empty side hides that side. The centre
is special: removing its default restores the built-in empty state.
Auto-hide and user-hidden state
An auto-hidden side opens when content or a default appears.
A side the user closed stays hidden when content is added.
set_zone_open(placement, true, …) opens a side only when it has content or
a default.
Panel::starts_open (component panel trait) opens the zone and clears the
user-hidden flag when the panel is added.
Dock2 emits ZoneVisibilityChanged only when effective visibility changes,
and ZoneDefaultChanged only when the presence of a default changes.
Persistence
let state = dock2.read(cx).dump(cx);let json = serde_json::to_string(&state)?;
Dock2State contains a schema version, the existing DockAreaState, and
optional flags for the left, right, and bottom zones. load reads older DockAreaState values without zone flags, derives them, and normalizes
contradictory flags. A schema newer than the running build is rejected before
the layout changes.
ZoneDefault is not serialized: closures and view handles cannot be stored.
Register defaults at startup, before or immediately after load, so an empty
side with a default does not get auto-hidden before the default exists. load_area imports a plain DockAreaState.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Extend the Dock component that keeps the same panels, layouts, drag-and-drop, and skin, but allows a zone to become
empty:
ZoneDefault, usually built fromEmpty;
Dockkeeps its existing last-tab protection. Applications chooseDock2explicitly.
Create
Keep the
Entity<Dock2>.Dock2::area()exposes the underlyingDockAreafor queries and
DockEventsubscriptions;Dock2::skin()exposes theexisting
DockSkinsettings.Zone policy
ZoneDefaultHiding means
is_dock_open == false. The dock, its tree, and its size arekept, so reopening restores the previous layout.
Dock2never removes a dockautomatically.
Zone defaults
ZoneDefaultis a view factory, not a panel. It has noPanelId, tab, dragstate, close action, zoom, or persisted layout entry.
Use
ZoneDefault::newfor an arbitrary element,ZoneDefault::emptyfor anEmptyfactory,ZoneDefault::viewfor a statefulAnyView, andwith_focus_handlewhen focus should return to the default after its panelcloses.
Setting a default on an absent side creates the dock at the default size and
opens it. Removing the default from an empty side hides that side. The centre
is special: removing its default restores the built-in empty state.
Auto-hide and user-hidden state
set_zone_open(placement, true, …)opens a side only when it has content ora default.
Panel::starts_open(component panel trait) opens the zone and clears theuser-hidden flag when the panel is added.
Dock2emitsZoneVisibilityChangedonly when effective visibility changes,and
ZoneDefaultChangedonly when the presence of a default changes.Persistence
Dock2Statecontains a schema version, the existingDockAreaState, andoptional flags for the left, right, and bottom zones.
loadreads olderDockAreaStatevalues without zone flags, derives them, and normalizescontradictory flags. A schema newer than the running build is rejected before
the layout changes.
ZoneDefaultis not serialized: closures and view handles cannot be stored.Register defaults at startup, before or immediately after
load, so an emptyside with a default does not get auto-hidden before the default exists.
load_areaimports a plainDockAreaState.All reactions