docking

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 3 Imported by: 0

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

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

func (p DefaultPainter) PaintZoneBorder(canvas widget.Canvas, borderRect geometry.Rect, _ Zone)

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

func (h *Host) ActivePanelIndex(zone Zone) int

ActivePanelIndex returns the active tab index for the given zone. Returns -1 if the zone is empty.

func (*Host) Children

func (h *Host) Children() []widget.Widget

Children returns all visible content widgets (zone panels + center).

func (*Host) Dock

func (h *Host) Dock(panel *Panel, zone Zone)

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) Draw

func (h *Host) Draw(ctx widget.Context, canvas widget.Canvas)

Draw renders the dock layout to the canvas.

func (*Host) Event

func (h *Host) Event(ctx widget.Context, e event.Event) bool

Event handles input events for the dock host.

func (*Host) Layout

func (h *Host) Layout(ctx widget.Context, constraints geometry.Constraints) geometry.Size

Layout calculates zone sizes and positions all children.

func (*Host) MovePanel

func (h *Host) MovePanel(panel *Panel, targetZone Zone) bool

MovePanel moves a panel from its current zone to a new zone. Returns true if the panel was found and moved.

func (*Host) PanelCount

func (h *Host) PanelCount(zone Zone) int

PanelCount returns the number of panels in the given zone.

func (*Host) PanelZone

func (h *Host) PanelZone(panel *Panel) (Zone, bool)

PanelZone returns the zone a panel is docked to, and whether it was found.

func (*Host) SetActivePanelIndex

func (h *Host) SetActivePanelIndex(zone Zone, idx int)

SetActivePanelIndex sets the active tab index for the given zone. Does nothing if the index is out of range.

func (*Host) Undock

func (h *Host) Undock(panel *Panel) bool

Undock removes a panel from its current zone. Returns true if the panel was found and removed.

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) Content

func (p *Panel) Content() widget.Widget

Content returns the panel's content widget, or nil if no content is set.

func (*Panel) IsCloseable

func (p *Panel) IsCloseable() bool

IsCloseable reports whether the panel has a close button.

func (*Panel) Title

func (p *Panel) Title() string

Title returns the panel's display title.

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.

const (
	// Left is the left edge zone.
	Left Zone = iota

	// Right is the right edge zone.
	Right

	// Top is the top edge zone.
	Top

	// Bottom is the bottom edge zone.
	Bottom

	// Center is the center zone (main content).
	Center
)

Zone constants.

func (Zone) String

func (z Zone) String() string

String returns a human-readable name for the zone.

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.

Jump to

Keyboard shortcuts

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