Documentation
¶
Overview ¶
Package docking provides an IDE-style dockable panel system.
Construction uses functional options for immutable configuration:
host := docking.NewHost(
docking.CenterContent(mainEditor),
docking.PainterOpt(myPainter),
)
explorer := docking.NewPanel(
docking.PanelTitle("Explorer"),
docking.PanelContent(explorerWidget),
docking.Closeable(true),
)
host.Dock(explorer, docking.Left)
host.Dock(terminal, docking.Bottom)
Layout ¶
The dock host manages a border layout with five zones:
+---------------------------------------------------+ | Top Zone | +--------+----------------------------------+-------+ | | | | | Left | Center Zone | Right | | Zone | (main content) | Zone | | [tabs] | | [tabs]| | | | | +--------+----------------------------------+-------+ | Bottom Zone | | [tabs] | +---------------------------------------------------+
Zones ¶
Five zones are available: Left, Right, Top, Bottom, and Center. When multiple panels are docked to the same zone, they form a tabbed group. The active tab shows its content while others remain hidden.
Zone sizes are controlled by ratios (0.0 to 1.0), configurable via LeftRatio, RightRatio, TopRatio, and BottomRatio. Zones with no panels are automatically collapsed.
Panels ¶
Each Panel has a title, optional content widget, and can be closeable. Panels are docked to zones programmatically via Host.Dock. Removing a panel via Host.Undock or closing it removes it from the zone. If the zone becomes empty, it collapses.
Signal Binding ¶
The active panel index within each zone can be bound to a reactive signal for external observation. Use Host.ActivePanelIndex to query the active tab in a zone.
Visual Style ¶
Zone borders, tab headers, and backgrounds are rendered by a Painter. If no painter is set, DefaultPainter is used.
Simplified Scope (Phase 4) ¶
The initial implementation provides:
- Programmatic docking only (no drag-to-dock)
- Zone sizes as ratios
- Tab switching in groups
- Panel close
- MovePanel between zones
Drag-to-dock using the dnd package is planned for a future iteration.
Index ¶
- type DefaultPainter
- type Host
- func (h *Host) ActivePanelIndex(zone Zone) int
- func (h *Host) Children() []widget.Widget
- func (h *Host) Dock(panel *Panel, zone Zone)
- func (h *Host) Draw(ctx widget.Context, canvas widget.Canvas)
- func (h *Host) Event(ctx widget.Context, e event.Event) bool
- func (h *Host) Layout(ctx widget.Context, constraints geometry.Constraints) geometry.Size
- func (h *Host) MovePanel(panel *Panel, targetZone Zone) bool
- func (h *Host) PanelCount(zone Zone) int
- func (h *Host) PanelZone(panel *Panel) (Zone, bool)
- func (h *Host) SetActivePanelIndex(zone Zone, idx int)
- func (h *Host) Undock(panel *Panel) bool
- type HostOption
- func BottomRatio(r float32) HostOption
- func CenterContent(w widget.Widget) HostOption
- func ColorSchemeOpt(cs ZoneColorScheme) HostOption
- func LeftRatio(r float32) HostOption
- func OnPanelClose(fn func(panel *Panel, zone Zone)) HostOption
- func PainterOpt(p Painter) HostOption
- func RightRatio(r float32) HostOption
- func TopRatio(r float32) HostOption
- type Painter
- type Panel
- type PanelOption
- type Zone
- type ZoneColorScheme
- type ZoneTabState
- type ZoneTabsPaintState
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DefaultPainter ¶
type DefaultPainter struct{}
DefaultPainter provides a minimal fallback painter with no design system styling. It draws simple tab headers and zone borders suitable for testing and prototyping.
func (DefaultPainter) PaintZoneBorder ¶
PaintZoneBorder renders a simple 1px border between a zone and the center.
func (DefaultPainter) PaintZoneTabs ¶
func (p DefaultPainter) PaintZoneTabs(canvas widget.Canvas, ps ZoneTabsPaintState)
PaintZoneTabs renders a minimal tab header bar for a zone.
type Host ¶
type Host struct {
widget.WidgetBase
// contains filtered or unexported fields
}
Host is the root container managing the dock layout.
It arranges docked panels into five zones (Left, Right, Top, Bottom, Center) and renders tab headers for zones with multiple panels.
A host is created with NewHost using functional options:
host := docking.NewHost(
docking.CenterContent(mainEditor),
docking.LeftRatio(0.25),
)
func NewHost ¶
func NewHost(opts ...HostOption) *Host
NewHost creates a new dock host with the given options.
The returned widget is visible and enabled by default.
func (*Host) ActivePanelIndex ¶
ActivePanelIndex returns the active tab index for the given zone. Returns -1 if the zone is empty.
func (*Host) Dock ¶
Dock adds a panel to the specified zone. If the zone already has panels, the new panel becomes an additional tab. The new panel becomes the active tab in its zone.
func (*Host) MovePanel ¶
MovePanel moves a panel from its current zone to a new zone. Returns true if the panel was found and moved.
func (*Host) PanelCount ¶
PanelCount returns the number of panels in the given zone.
func (*Host) SetActivePanelIndex ¶
SetActivePanelIndex sets the active tab index for the given zone. Does nothing if the index is out of range.
type HostOption ¶
type HostOption func(*hostConfig)
HostOption configures a dock host during construction.
func BottomRatio ¶
func BottomRatio(r float32) HostOption
BottomRatio sets the size ratio of the bottom zone (0.0 to 1.0). Default is 0.2 (20% of available height).
func CenterContent ¶
func CenterContent(w widget.Widget) HostOption
CenterContent sets the main content widget displayed in the center zone.
func ColorSchemeOpt ¶
func ColorSchemeOpt(cs ZoneColorScheme) HostOption
ColorSchemeOpt sets the theme-derived color scheme for the dock host.
func LeftRatio ¶
func LeftRatio(r float32) HostOption
LeftRatio sets the size ratio of the left zone (0.0 to 1.0). Default is 0.2 (20% of available width).
func OnPanelClose ¶
func OnPanelClose(fn func(panel *Panel, zone Zone)) HostOption
OnPanelClose sets the callback invoked when a panel's close button is clicked. The callback receives the panel and the zone it belonged to.
func PainterOpt ¶
func PainterOpt(p Painter) HostOption
PainterOpt sets the painter used to render zone borders and tab headers. If not set, DefaultPainter is used.
func RightRatio ¶
func RightRatio(r float32) HostOption
RightRatio sets the size ratio of the right zone (0.0 to 1.0). Default is 0.2 (20% of available width).
func TopRatio ¶
func TopRatio(r float32) HostOption
TopRatio sets the size ratio of the top zone (0.0 to 1.0). Default is 0.2 (20% of available height).
type Painter ¶
type Painter interface {
// PaintZoneTabs renders the tab header bar for a zone group.
PaintZoneTabs(canvas widget.Canvas, state ZoneTabsPaintState)
// PaintZoneBorder renders the border between a zone and the center.
PaintZoneBorder(canvas widget.Canvas, borderRect geometry.Rect, zone Zone)
}
Painter draws the visual representation of the docking system. Each design system (Material 3, Fluent, Cupertino) provides its own Painter implementation to render zone borders and tab headers.
If no Painter is set, the host uses DefaultPainter.
type Panel ¶
type Panel struct {
// contains filtered or unexported fields
}
Panel represents an individual dockable panel with a title, content widget, and optional close button.
Panels are created with NewPanel and docked to a Host via Host.Dock.
func NewPanel ¶
func NewPanel(opts ...PanelOption) *Panel
NewPanel creates a new dockable panel with the given options.
p := docking.NewPanel(
docking.PanelTitle("Explorer"),
docking.PanelContent(explorerWidget),
docking.Closeable(true),
)
func (*Panel) IsCloseable ¶
IsCloseable reports whether the panel has a close button.
type PanelOption ¶
type PanelOption func(*panelConfig)
PanelOption configures a panel during construction.
func Closeable ¶
func Closeable(v bool) PanelOption
Closeable enables the close button on this panel.
func PanelContent ¶
func PanelContent(w widget.Widget) PanelOption
PanelContent sets the panel's content widget.
func PanelTitle ¶
func PanelTitle(title string) PanelOption
PanelTitle sets the panel's display title shown in the tab header.
type Zone ¶
type Zone uint8
Zone identifies a docking zone within the host layout.
type ZoneColorScheme ¶
type ZoneColorScheme struct {
TabBarBackground widget.Color
ActiveTabText widget.Color
InactiveTabText widget.Color
ActiveTabBackground widget.Color
HoverBackground widget.Color
Border widget.Color
CloseButton widget.Color
}
ZoneColorScheme provides theme-derived colors for zone painting. Zero value means the painter should use its built-in defaults.
type ZoneTabState ¶
type ZoneTabState struct {
// Title is the panel's display text.
Title string
// Bounds is the tab's clickable area within the tab bar.
Bounds geometry.Rect
// Active is true when this tab is the currently selected tab.
Active bool
// Hovered is true when the mouse is over this tab.
Hovered bool
// Closeable is true when this tab shows a close button.
Closeable bool
// CloseButtonBounds is the clickable area for the close button.
// Empty if not closeable.
CloseButtonBounds geometry.Rect
}
ZoneTabState provides the state of a single tab within a zone.
type ZoneTabsPaintState ¶
type ZoneTabsPaintState struct {
// Zone identifies which zone this tab bar belongs to.
Zone Zone
// TabBarBounds is the tab bar area.
TabBarBounds geometry.Rect
// Tabs contains the state of each tab in the zone.
Tabs []ZoneTabState
// ActiveIdx is the index of the currently active tab.
ActiveIdx int
// ColorScheme provides theme-derived colors for painting.
// Zero value means the painter should use its built-in defaults.
ColorScheme ZoneColorScheme
}
ZoneTabsPaintState provides the current zone tab bar state to the painter.