dock

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (

	// PanelKeyName is the panel_name of the leaves PanelKey writes.
	PanelKeyName = "Panel"
)

The names a persisted layout gives its containers, and the panels it keeps by key alone.

Variables

This section is empty.

Functions

func PanelKeyOf

func PanelKeyOf(s PanelState) string

PanelKeyOf reads a leaf's key back: its info's "id", else its panel_name.

Types

type Area

type Area struct {
	// Layout makes the area controlled: it shows what Layout returns and
	// reports edits with OnLayoutChange, which the app passes back.
	// Without it the area keeps its own, from DefaultLayout.
	Layout         func() Layout
	DefaultLayout  Layout
	OnLayoutChange func(Layout)
	// Locked rearranges nothing: no drags, drops or closes. Selecting,
	// resizing and toggling docks still work.
	Locked func() bool
	// Compact presents the area compactly while it holds; docked when
	// nil, whatever the device or the width, which the app reads to set
	// it.
	Compact func() bool
	// Panels says what each panel allows, by key.
	Panels map[string]PanelOptions

	// RenderPanel renders a panel's content, by key.
	RenderPanel func(cx *core.Scope, key string) core.Node
	// RenderTab renders what a tab shows, the key as text without it; the
	// area makes it the tab, whose press selects and drag moves it.
	RenderTab func(cx *core.Scope, tab Tab) core.Node
	// RenderDropIndicator renders what shows where a drag would land,
	// over what it would take; a view of DropIndicatorStyle without it.
	RenderDropIndicator func(cx *core.Scope, d DropIndicator) core.Node
	// RenderDock renders a dock's own chrome, before its layout.
	RenderDock func(cx *core.Scope, d Info) core.Node
	// RenderEmpty renders what an empty center shows.
	RenderEmpty func(cx *core.Scope) core.Node
	// RenderDragPreview renders what follows the pointer as a tab is
	// dragged.
	RenderDragPreview func(cx *core.Scope, tab Tab) core.Node

	// The parts' styles: each tab group's frame, its tab bar, each tab
	// (Selected for the displayed one), the content frame its panels show
	// in, the drop indicator, each handle's line and thumb (between the
	// groups of a split and at each dock's edge; a GroupStyle follows the
	// handle's hover and press), each dock's frame, and in the compact
	// presentation the side docks' drawers, the bottom dock's sheet and
	// the backdrop behind them. Each part's Func, when set, merges over
	// its style, again when what it reads changes, and its class goes
	// under both.
	Class, GroupClass, TabBarClass, TabClass, ContentClass                     string
	DropIndicatorClass, HandleClass, HandleThumbClass                          string
	DockClass, DrawerClass, SheetClass, BackdropClass                          string
	Style, GroupStyle, TabBarStyle, TabStyle, ContentStyle                     core.Style
	StyleFunc, GroupStyleFunc, TabBarStyleFunc, TabStyleFunc, ContentStyleFunc func() core.Style
	DropIndicatorStyle, HandleStyle, HandleThumbStyle                          core.Style
	DropIndicatorStyleFunc, HandleStyleFunc, HandleThumbStyleFunc              func() core.Style
	DockStyle, DrawerStyle, SheetStyle, BackdropStyle                          core.Style
	DockStyleFunc, DrawerStyleFunc, SheetStyleFunc, BackdropStyleFunc          func() core.Style
	// HandleLabel says what dragging a handle resizes, for assistive
	// technology.
	HandleLabel string

	// OnPanelActiveChange follows a panel becoming, or stopping being,
	// its group's displayed tab; a closed dock displays none, and a panel
	// that leaves hears OnPanelRemove instead.
	OnPanelActiveChange func(key string, active bool)
	// OnPanelRemove reports a panel that left the area for good.
	OnPanelRemove func(key string)
	// OnZoomChange reports the displayed panel of the group zoomed in, or
	// "" as it zooms out.
	OnZoomChange func(key string)
	// OnDockOpenChange reports a dock showing or going, in either
	// presentation, and as the area mounts the docks whose shown state
	// differs from the layout's.
	OnDockOpenChange func(p Placement, open bool)
	// Ref, when set, is bound to the area's methods.
	Ref    *AreaRef
	TestID string
	// OnLayout and Tooltip are its view's, as a core.View's.
	OnLayout func(core.Bounds)
	Tooltip  core.Node
}

Area is a dockable workspace, as gpui-base's and NSH's: a center and optional left, right and bottom docks, each a tree of splits and tab groups the user rearranges by dragging tabs between groups and docks, resizes with the handles between them and zooms into. Its layout is data the app passes and hears back whole on every edit, and persists in gpui-base's format (Layout's JSON). It draws nothing: the app styles every part and renders each panel and tab.

An area the app makes Compact, as one on a phone or in a narrow window or column, keeps the same layout and presents it compactly: the center shows one tab group at a time, its tab bar listing every panel of the center, a tab drag reorders within it, and the docks are drawers from their edges and a sheet at the bottom.

A panel's content keeps its state while its group lives, across tab switches, resizes, zooms, docks closing and the compact presentation in the center; a panel moved to another group, or a dock's panel as the presentation changes, is rendered anew.

func (Area) Render

func (d Area) Render(cx *core.Scope) core.Node

Render implements core.Node.

type AreaRef

type AreaRef struct {
	// contains filtered or unexported fields
}

AreaRef is a Area's methods, bound once it mounts. Each edit is reported with OnLayoutChange, as the user's are.

func (*AreaRef) AddPanel

func (r *AreaRef) AddPanel(key string, p Placement, size core.Points)

AddPanel adds panel key to the first tab group of region p, displayed; a dock missing is made, size across (200 when 0). A panel the area holds moves there.

func (*AreaRef) ClosePanel

func (r *AreaRef) ClosePanel(key string)

ClosePanel takes panel key out of the area as its tab would: unless the area is locked, the panel is not closable, or it is the last panel of a group with nothing beside it.

func (*AreaRef) GroupOf

func (r *AreaRef) GroupOf(key string) (uint64, bool)

GroupOf returns the ID of the tab group holding panel key, and whether one does.

func (*AreaRef) Layout

func (r *AreaRef) Layout() Layout

Layout returns the layout the area shows.

func (*AreaRef) MovePanel

func (r *AreaRef) MovePanel(key string, t Target)

MovePanel moves panel key to t; a panel the area does not hold is added there.

func (*AreaRef) RemovePanel

func (r *AreaRef) RemovePanel(key string)

RemovePanel takes panel key out of the area, whatever its options say.

func (*AreaRef) SelectPanel

func (r *AreaRef) SelectPanel(key string)

SelectPanel displays panel key in its group.

func (*AreaRef) SelectTab

func (r *AreaRef) SelectTab(group uint64, index int)

SelectTab displays the index'th panel of tab group group.

func (*AreaRef) SetDockOpen

func (r *AreaRef) SetDockOpen(p Placement, open bool)

SetDockOpen opens or closes dock p; at compact width it presents it, dismissing the other, or dismisses it.

func (*AreaRef) SetDockSize

func (r *AreaRef) SetDockSize(p Placement, size core.Points)

SetDockSize sets dock p's size across its edge, at least PanelMinSize.

func (*AreaRef) SplitAt

func (r *AreaRef) SplitAt(group uint64, key string, side core.Placement)

SplitAt puts panel key in a new tab group on side of container group.

func (*AreaRef) ToggleDock

func (r *AreaRef) ToggleDock(p Placement)

ToggleDock opens dock p when it is closed and closes it otherwise.

func (*AreaRef) ToggleZoom

func (r *AreaRef) ToggleZoom(group uint64)

ToggleZoom zooms tab group group in, so it fills the area, or out when it is zoomed; 0 zooms the zoomed group out.

func (*AreaRef) ZoomedGroup

func (r *AreaRef) ZoomedGroup() (uint64, bool)

ZoomedGroup returns the zoomed tab group's ID, and whether one is.

type AreaState

type AreaState struct {
	Version    *int       `json:"version"`
	Center     PanelState `json:"center"`
	LeftDock   *State     `json:"left_dock,omitempty"`
	RightDock  *State     `json:"right_dock,omitempty"`
	BottomDock *State     `json:"bottom_dock,omitempty"`
}

AreaState is gpui-base's persisted dock layout, its field names and tags frozen, so a layout file is the same in both. It is machine written: Layout's MarshalJSON and UnmarshalJSON go through it with each panel kept by its key.

func NewAreaState

func NewAreaState(l Layout, leaf func(key string) PanelState) AreaState

NewAreaState writes l in gpui-base's format, each panel's leaf by leaf (PanelKey when nil).

func (AreaState) Layout

func (s AreaState) Layout(key func(PanelState) string) Layout

Layout reads s back, each leaf's key by key (PanelKeyOf when nil), with NSH's compatibility rules: a tab group of tab groups is flattened, a bare leaf where a container belongs is a tab group of it, and a "TabPanel" holding panel info is an empty tab group.

type DropIndicator

type DropIndicator struct {
	Group uint64
	Side  core.Placement
	Index int
}

DropIndicator is where a drag would land: into Group, or in a new group on Side of it. Index is the slot in Group's tab bar a drop on the bar goes to, -1 elsewhere.

type Info

type Info struct {
	Placement Placement
	Open      func() bool
	// Size is its size across its edge, Collapsible whether dragging it
	// below PanelMinSize closes it.
	Size        func() core.Points
	Collapsible func() bool
	Toggle      func()
}

Info is what RenderDock gets about a dock.

type Layout

type Layout struct {
	Center              Node
	Left, Right, Bottom *Region
}

Layout is a whole Area's layout: the center and the docks.

func (Layout) Clone

func (l Layout) Clone() Layout

Clone returns a deep copy of l.

func (Layout) MarshalJSON

func (l Layout) MarshalJSON() ([]byte, error)

MarshalJSON writes l in gpui-base's layout format, each panel as {"id": key}.

func (*Layout) Region

func (l *Layout) Region(p Placement) *Region

Region returns the dock at p, or nil; the center is no dock.

func (*Layout) UnmarshalJSON

func (l *Layout) UnmarshalJSON(data []byte) error

UnmarshalJSON reads a gpui-base layout file into l, each panel keyed by its "id", else its panel_name.

type Node

type Node struct {
	// ID names the container across edits. A layout the app writes may
	// leave it 0; the area assigns it, and reports layouts with it.
	ID       uint64
	Tabs     bool
	Panels   []string
	Active   int
	Axis     base.Axis
	Children []Node
	Sizes    []core.Points
}

Node is one container of a dock layout: a tab group (Tabs) of Panels, Active the one displayed, or a split of Children along Axis with their slot Sizes (0 for none: the child shares what the others leave).

func Split

func Split(axis base.Axis, children ...Node) Node

Split returns a split of children along axis, sharing it evenly.

func Tabs

func Tabs(panels ...string) Node

Tabs returns a tab group of panels, the first displayed.

type PanelInfo

type PanelInfo struct {
	Stack *StackInfo
	Tabs  *TabsInfo
	Panel json.RawMessage
}

PanelInfo is what a PanelState holds: a split's sizes and axis (0 horizontal, 1 vertical), a tab group's active index, or a panel's own data, written as gpui-base's externally tagged enum.

func (PanelInfo) MarshalJSON

func (i PanelInfo) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*PanelInfo) UnmarshalJSON

func (i *PanelInfo) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

type PanelOptions

type PanelOptions struct {
	NoClose bool
	NoZoom  bool
	// Hidden keeps the panel's tab out of its tab bar.
	Hidden bool
}

PanelOptions are what a panel allows; a panel Panels does not list allows everything.

type PanelState

type PanelState struct {
	PanelName string       `json:"panel_name"`
	Children  []PanelState `json:"children"`
	Info      PanelInfo    `json:"info"`
}

PanelState is a persisted container or panel: a split ("StackPanel" with stack info), a tab group ("TabPanel" with tabs info) or a panel's leaf, whose info is the app's.

func PanelKey

func PanelKey(key string) PanelState

PanelKey is a panel kept by its key alone: a leaf named PanelKeyName with info {"id": key}.

type Placement

type Placement uint8

Placement is a region of a Area.

const (
	Center Placement = iota
	Left
	Bottom
	Right
)

func (Placement) String

func (p Placement) String() string

type Region

type Region struct {
	Root       Node
	Size       core.Points
	Closed     bool
	NoCollapse bool
}

Region is a dock: its tree, its size across its edge (200 when 0, never below PanelMinSize) and whether it is closed. A collapsible dock dragged below 50 points closes, keeping its size; NoCollapse keeps it open.

type StackInfo

type StackInfo struct {
	Sizes []core.Points `json:"sizes"`
	Axis  int           `json:"axis"`
}

StackInfo is a split's persisted info.

type State

type State struct {
	Panel     PanelState  `json:"panel"`
	Placement string      `json:"placement"`
	Size      core.Points `json:"size"`
	Open      bool        `json:"open"`
}

State is one dock's persisted state.

type Tab

type Tab struct {
	Key   string
	Group uint64
	// Index is its place among its group's shown tabs.
	Index func() int
	// Selected reports whether it is its group's displayed tab, Zoomed
	// whether its group is zoomed in.
	Selected, Zoomed func() bool
	// Closable reports whether the area would close it: the panel may
	// close, the area is not locked, and it is not the last panel of a
	// group with nothing beside it.
	Closable func() bool
	// Close closes the panel, where it may.
	Close func()
}

Tab is what RenderTab and RenderDragPreview get about a tab.

type TabsInfo

type TabsInfo struct {
	ActiveIndex int `json:"active_index"`
}

TabsInfo is a tab group's persisted info.

type Target

type Target struct {
	Group uint64
	Side  core.Placement
	// Before is the tab it goes before; it goes last without one.
	Before string
	// NoActivate keeps the group's displayed tab.
	NoActivate bool
	// Size is the new group's length along a split, half of what it lands
	// beside when 0.
	Size core.Points
}

Target is where AreaRef.MovePanel puts a panel: into tab group Group, or with Side in a new tab group on that side of container Group.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL