layout

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package layout provides GTK widget abstractions and layout management for the pane system. It defines interfaces that wrap GTK types, enabling unit testing without GTK runtime.

Index

Constants

View Source
const (
	OrientationHorizontal = gtk.OrientationHorizontalValue
	OrientationVertical   = gtk.OrientationVerticalValue
)

Orientation constants matching GTK values.

Variables

View Source
var ErrCannotRemoveLastPane = errors.New("cannot remove last pane from stack")

ErrCannotRemoveLastPane is returned when trying to remove the last pane from a stack.

View Source
var ErrIndexOutOfBounds = errors.New("index out of bounds")

ErrIndexOutOfBounds is returned when an index is out of range.

View Source
var ErrNilRoot = errors.New("root node is nil")

ErrNilRoot is returned when attempting to build from a nil root node.

View Source
var ErrNodeNotFound = errors.New("node not found")

ErrNodeNotFound is returned when a node lookup fails.

View Source
var ErrStackEmpty = errors.New("stack is empty")

ErrStackEmpty is returned when operating on an empty stack.

Functions

This section is empty.

Types

type BoxWidget

type BoxWidget interface {
	Widget

	// Child management
	Append(child Widget)
	Prepend(child Widget)
	Remove(child Widget)
	InsertChildAfter(child Widget, sibling Widget)
	ReorderChildAfter(child Widget, sibling Widget)

	// Configuration
	SetHomogeneous(homogeneous bool)
	GetHomogeneous() bool
	SetSpacing(spacing int)
	GetSpacing() int
	SetOrientation(orientation Orientation)
	GetOrientation() Orientation
}

BoxWidget wraps gtk.Box for linear layouts. It arranges children in a single row or column.

type ButtonWidget

type ButtonWidget interface {
	Widget

	SetLabel(label string)
	GetLabel() string
	SetChild(child Widget)
	GetChild() Widget
	SetIconName(iconName string)

	// Connect click handler, returns signal ID for disconnection
	ConnectClicked(callback func()) uint32
}

ButtonWidget wraps gtk.Button for clickable elements.

type EllipsizeMode

type EllipsizeMode = int

EllipsizeMode represents pango ellipsize modes.

const (
	EllipsizeNone   EllipsizeMode = 0
	EllipsizeStart  EllipsizeMode = 1
	EllipsizeMiddle EllipsizeMode = 2
	EllipsizeEnd    EllipsizeMode = 3
)

Ellipsize mode constants.

type GtkWidgetFactory

type GtkWidgetFactory struct{}

GtkWidgetFactory creates real GTK widgets.

func NewGtkWidgetFactory

func NewGtkWidgetFactory() *GtkWidgetFactory

NewGtkWidgetFactory creates a new factory for real GTK widgets.

func (*GtkWidgetFactory) NewBox

func (f *GtkWidgetFactory) NewBox(orientation Orientation, spacing int) BoxWidget

func (*GtkWidgetFactory) NewButton

func (f *GtkWidgetFactory) NewButton() ButtonWidget

func (*GtkWidgetFactory) NewImage

func (f *GtkWidgetFactory) NewImage() ImageWidget

func (*GtkWidgetFactory) NewLabel

func (f *GtkWidgetFactory) NewLabel(text string) LabelWidget

func (*GtkWidgetFactory) NewOverlay

func (f *GtkWidgetFactory) NewOverlay() OverlayWidget

func (*GtkWidgetFactory) NewPaned

func (f *GtkWidgetFactory) NewPaned(orientation Orientation) PanedWidget

func (*GtkWidgetFactory) NewProgressBar

func (f *GtkWidgetFactory) NewProgressBar() ProgressBarWidget

func (*GtkWidgetFactory) NewSpinner added in v0.22.0

func (f *GtkWidgetFactory) NewSpinner() SpinnerWidget

func (*GtkWidgetFactory) WrapWidget

func (f *GtkWidgetFactory) WrapWidget(w *gtk.Widget) Widget

type ImageWidget

type ImageWidget interface {
	Widget

	SetFromIconName(iconName string)
	SetFromFile(filename string)
	SetFromPaintable(paintable Paintable)
	SetPixelSize(pixelSize int)
	Clear()
}

ImageWidget wraps gtk.Image for displaying images.

type LabelWidget

type LabelWidget interface {
	Widget

	SetText(text string)
	GetText() string
	SetMarkup(markup string)
	SetEllipsize(mode EllipsizeMode)
	SetMaxWidthChars(nChars int)
	SetXalign(xalign float32)
}

LabelWidget wraps gtk.Label for text display.

type Orientation

type Orientation = gtk.Orientation

Orientation represents the orientation for layout widgets.

type OverlayWidget

type OverlayWidget interface {
	Widget

	// Main child
	SetChild(child Widget)
	GetChild() Widget

	// Overlay management
	AddOverlay(overlay Widget)
	RemoveOverlay(overlay Widget)

	// Overlay configuration
	SetClipOverlay(overlay Widget, clip bool)
	GetClipOverlay(overlay Widget) bool
	SetMeasureOverlay(overlay Widget, measure bool)
	GetMeasureOverlay(overlay Widget) bool
}

OverlayWidget wraps gtk.Overlay for layered content. It displays overlay widgets on top of a main child widget.

type Paintable

type Paintable interface {
	GoPointer() uintptr
}

Paintable represents a graphics texture that can be displayed in an image. This interface abstracts over gdk.Paintable/gdk.Texture.

type PaneRenderer

type PaneRenderer interface {
	// RenderPane creates a widget for a pane node.
	// The webViewWidget is the GTK widget from the WebView.
	RenderPane(paneID string, webViewWidget Widget) Widget
}

PaneRenderer creates pane view widgets from domain entities. This decouples the tree renderer from concrete PaneView implementation.

type PaneViewFactory

type PaneViewFactory interface {
	// CreatePaneView creates a widget for a leaf pane node.
	CreatePaneView(node *entity.PaneNode) Widget
}

PaneViewFactory creates pane view widgets from pane nodes. This decouples the TreeRenderer from concrete PaneView implementation.

type PanedWidget

type PanedWidget interface {
	Widget

	// Child management
	SetStartChild(child Widget)
	SetEndChild(child Widget)
	GetStartChild() Widget
	GetEndChild() Widget

	// Divider position
	SetPosition(position int)
	GetPosition() int

	// Resize behavior
	SetResizeStartChild(resize bool)
	SetResizeEndChild(resize bool)
	GetResizeStartChild() bool
	GetResizeEndChild() bool

	// Shrink behavior (whether child can be smaller than its minimum size)
	SetShrinkStartChild(shrink bool)
	SetShrinkEndChild(shrink bool)
	GetShrinkStartChild() bool
	GetShrinkEndChild() bool

	// Signals
	ConnectMap(callback func()) uint32
	ConnectNotifyPosition(callback func()) uint32

	// Tick callback for frame-based updates (returns signal ID)
	// Callback returns true to continue, false to stop
	AddTickCallback(callback func() bool) uint

	// Handle appearance
	SetWideHandle(wide bool)
	GetWideHandle() bool
}

PanedWidget wraps gtk.Paned for creating split views. It manages two child widgets separated by a draggable divider.

type ProgressBarWidget

type ProgressBarWidget interface {
	Widget

	// SetFraction sets the progress value (0.0 to 1.0).
	SetFraction(fraction float64)
	// GetFraction returns the current progress value.
	GetFraction() float64
}

ProgressBarWidget wraps gtk.ProgressBar for displaying loading progress. Implementations may include smooth animation behavior.

type SpinnerWidget added in v0.22.0

type SpinnerWidget interface {
	Widget

	Start()
	Stop()
	SetSpinning(spinning bool)
	GetSpinning() bool
}

SpinnerWidget wraps gtk.Spinner for displaying indefinite loading.

type SplitView

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

SplitView wraps a GTK Paned widget for creating split pane layouts. It manages two child widgets separated by a draggable divider.

func NewSplitView

func NewSplitView(
	ctx context.Context, factory WidgetFactory, orientation Orientation,
	startChild, endChild Widget, ratio float64,
) *SplitView

NewSplitView creates a new split view with the given orientation and children. The ratio determines the initial divider position (0.0-1.0).

func (*SplitView) ApplyRatio

func (sv *SplitView) ApplyRatio() bool

ApplyRatio converts the ratio to a pixel position and applies it. This should be called after the widget has been mapped and has an allocated size. Returns true if the ratio was successfully applied, false if the widget is not yet allocated.

func (*SplitView) EndChild

func (sv *SplitView) EndChild() Widget

EndChild returns the current end (right/bottom) child.

func (*SplitView) GetPosition

func (sv *SplitView) GetPosition() int

GetPosition returns the current divider position in pixels.

func (*SplitView) GetRatio

func (sv *SplitView) GetRatio() float64

GetRatio returns the current ratio setting.

func (*SplitView) Orientation

func (sv *SplitView) Orientation() Orientation

Orientation returns the split orientation.

func (*SplitView) Paned

func (sv *SplitView) Paned() PanedWidget

Paned returns the underlying PanedWidget for direct access.

func (*SplitView) SetOnRatioChanged added in v0.21.0

func (sv *SplitView) SetOnRatioChanged(fn func(ratio float64))

func (*SplitView) SetPosition

func (sv *SplitView) SetPosition(position int)

SetPosition sets the divider position in pixels.

func (*SplitView) SetRatio

func (sv *SplitView) SetRatio(ratio float64)

SetRatio updates the divider position. The ratio is clamped to the range [0.0, 1.0]. Note: This sets the position based on ratio; actual pixel position depends on the allocated size of the paned widget.

func (*SplitView) SetWideHandle

func (sv *SplitView) SetWideHandle(wide bool)

SetWideHandle sets whether the handle has a wide appearance.

func (*SplitView) StartChild

func (sv *SplitView) StartChild() Widget

StartChild returns the current start (left/top) child.

func (*SplitView) SwapEnd

func (sv *SplitView) SwapEnd(newWidget Widget)

SwapEnd replaces the end (right/bottom) child widget. The old child is unparented before the new child is set.

func (*SplitView) SwapStart

func (sv *SplitView) SwapStart(newWidget Widget)

SwapStart replaces the start (left/top) child widget. The old child is unparented before the new child is set.

func (*SplitView) Widget

func (sv *SplitView) Widget() Widget

Widget returns the underlying PanedWidget for embedding in containers.

type StackedView

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

StackedView manages a stack of panes where only one is visible at a time. Inactive panes show title bars that can be clicked to activate them.

func NewStackedView

func NewStackedView(factory WidgetFactory) *StackedView

NewStackedView creates a new stacked pane container.

func (*StackedView) ActiveIndex

func (sv *StackedView) ActiveIndex() int

ActiveIndex returns the index of the currently active pane. Returns -1 if the stack is empty.

func (*StackedView) AddPane

func (sv *StackedView) AddPane(ctx context.Context, paneID, title, faviconIconName string, container Widget) int

AddPane adds a new pane to the stack. The new pane becomes active (visible).

func (*StackedView) Box

func (sv *StackedView) Box() BoxWidget

Box returns the underlying BoxWidget for direct access.

func (*StackedView) Count

func (sv *StackedView) Count() int

Count returns the number of panes in the stack.

func (*StackedView) FindPaneIndex added in v0.20.1

func (sv *StackedView) FindPaneIndex(paneID string) int

FindPaneIndex returns the index of the pane with the given ID. Returns -1 if not found.

func (*StackedView) GetContainer

func (sv *StackedView) GetContainer(index int) (Widget, error)

GetContainer returns the container widget for the pane at the given index.

func (*StackedView) InsertPaneAfter

func (sv *StackedView) InsertPaneAfter(
	ctx context.Context, afterIndex int, paneID, title, faviconIconName string, container Widget,
) int

InsertPaneAfter inserts a new pane after the specified index position. Use afterIndex=-1 to insert at the beginning. The new pane becomes active (visible). Returns the index where the pane was inserted.

func (*StackedView) NavigateNext

func (sv *StackedView) NavigateNext(ctx context.Context) error

NavigateNext moves to the next pane in the stack (wraps around).

func (*StackedView) NavigatePrevious

func (sv *StackedView) NavigatePrevious(ctx context.Context) error

NavigatePrevious moves to the previous pane in the stack (wraps around).

func (*StackedView) RemovePane

func (sv *StackedView) RemovePane(ctx context.Context, index int) error

RemovePane removes a pane from the stack by index. Returns an error if trying to remove the last pane.

func (*StackedView) SetActive

func (sv *StackedView) SetActive(ctx context.Context, index int) error

SetActive activates the pane at the given index. The active pane's container is shown; inactive panes show only title bars.

func (*StackedView) SetOnActivate

func (sv *StackedView) SetOnActivate(fn func(index int))

SetOnActivate sets the callback for when a pane is activated via title bar click.

func (*StackedView) SetOnClosePane added in v0.24.0

func (sv *StackedView) SetOnClosePane(fn func(paneID string))

SetOnClosePane sets the callback for when a pane's close button is clicked.

func (*StackedView) UpdateFavicon

func (sv *StackedView) UpdateFavicon(index int, iconName string) error

UpdateFavicon updates the favicon of a pane at the given index using an icon name.

func (*StackedView) UpdateFaviconTexture

func (sv *StackedView) UpdateFaviconTexture(index int, texture Paintable) error

UpdateFaviconTexture updates the favicon of a pane at the given index using a texture. If texture is nil, falls back to the default web-browser-symbolic icon.

func (*StackedView) UpdateTitle

func (sv *StackedView) UpdateTitle(index int, title string) error

UpdateTitle updates the title of a pane at the given index.

func (*StackedView) Widget

func (sv *StackedView) Widget() Widget

Widget returns the underlying BoxWidget for embedding in containers.

type TreeRenderer

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

TreeRenderer builds GTK widget trees from domain PaneNode trees. It maps each node to its corresponding GTK widget and maintains a lookup table for finding widgets by node ID.

func NewTreeRenderer

func NewTreeRenderer(ctx context.Context, factory WidgetFactory, paneViewFactory PaneViewFactory) *TreeRenderer

NewTreeRenderer creates a new tree renderer.

func (*TreeRenderer) Build

func (tr *TreeRenderer) Build(ctx context.Context, root *entity.PaneNode) (Widget, error)

Build constructs the entire widget tree from a root PaneNode. Returns the root widget that can be embedded in a container.

func (*TreeRenderer) Clear

func (tr *TreeRenderer) Clear()

Clear removes all node-to-widget mappings.

func (*TreeRenderer) GetNodeIDs

func (tr *TreeRenderer) GetNodeIDs() []string

GetNodeIDs returns all tracked node IDs.

func (*TreeRenderer) GetStackedViewForPane

func (tr *TreeRenderer) GetStackedViewForPane(paneID string) *StackedView

GetStackedViewForPane returns the StackedView containing the given pane. Returns nil if the pane is not found.

func (*TreeRenderer) Lookup

func (tr *TreeRenderer) Lookup(nodeID string) Widget

Lookup finds the widget associated with a node ID. Returns nil if the node was not found or hasn't been rendered.

func (*TreeRenderer) LookupNode

func (tr *TreeRenderer) LookupNode(nodeID string) (Widget, bool)

LookupNode finds both the widget and verifies the node ID exists. Returns the widget and true if found, nil and false otherwise.

func (*TreeRenderer) NodeCount

func (tr *TreeRenderer) NodeCount() int

NodeCount returns the number of nodes currently tracked.

func (*TreeRenderer) RegisterPaneInStack

func (tr *TreeRenderer) RegisterPaneInStack(paneID string, stackedView *StackedView)

RegisterPaneInStack adds a pane to the paneToStack mapping. Use this when adding a pane to an existing stack without rebuild.

func (*TreeRenderer) RegisterSplit added in v0.21.0

func (tr *TreeRenderer) RegisterSplit(nodeID string, widget Widget, orientation Orientation)

RegisterSplit registers a split widget with its orientation.

func (*TreeRenderer) RegisterWidget

func (tr *TreeRenderer) RegisterWidget(nodeID string, widget Widget)

RegisterWidget adds or updates a node-to-widget mapping. Use this for incremental updates when you don't want to rebuild the entire tree.

func (*TreeRenderer) SetOnSplitRatioChanged added in v0.21.0

func (tr *TreeRenderer) SetOnSplitRatioChanged(fn func(nodeID string, ratio float64))

func (*TreeRenderer) UnregisterPane

func (tr *TreeRenderer) UnregisterPane(paneID string)

UnregisterPane removes a pane from the paneToStack mapping.

func (*TreeRenderer) UnregisterWidget

func (tr *TreeRenderer) UnregisterWidget(nodeID string)

UnregisterWidget removes a node-to-widget mapping. Use this when a node is removed or replaced during incremental operations.

func (*TreeRenderer) UpdateSplitRatio

func (tr *TreeRenderer) UpdateSplitRatio(nodeID string, ratio float64) error

UpdateSplitRatio updates the ratio of a split view by node ID. Returns an error if the node is not found or is not a split.

type Widget

type Widget interface {
	// Visibility
	Show()
	Hide()
	SetVisible(visible bool)
	IsVisible() bool

	// Focus
	GrabFocus() bool
	HasFocus() bool
	SetCanFocus(canFocus bool)
	SetFocusable(focusable bool) // GTK4: makes widget able to receive keyboard focus
	SetFocusOnClick(focusOnClick bool)

	// Pointer events
	SetCanTarget(canTarget bool) // If false, widget won't receive pointer events

	// Layout
	SetHexpand(expand bool)
	SetVexpand(expand bool)
	GetHexpand() bool
	GetVexpand() bool
	SetHalign(align gtk.Align)
	SetValign(align gtk.Align)
	SetSizeRequest(width, height int)

	// Geometry - for focus navigation
	GetAllocatedWidth() int
	GetAllocatedHeight() int
	// ComputePoint returns the position of this widget's origin (0,0) relative to
	// the target widget's coordinate space. If target is nil, returns position
	// relative to the native window. Returns ok=false if computation fails.
	ComputePoint(target Widget) (x, y float64, ok bool)

	// CSS styling
	AddCssClass(cssClass string)
	RemoveCssClass(cssClass string)
	HasCssClass(cssClass string) bool

	// Parent management
	Unparent()
	GetParent() Widget

	// GTK interop - returns the underlying GTK widget for embedding
	GtkWidget() *gtk.Widget

	// AddController adds an event controller to the widget
	AddController(controller *gtk.EventController)
}

Widget is the base interface that all GTK widgets implement. It provides common widget operations needed for layout management.

type WidgetFactory

type WidgetFactory interface {
	// Container widgets
	NewPaned(orientation Orientation) PanedWidget
	NewBox(orientation Orientation, spacing int) BoxWidget
	NewOverlay() OverlayWidget

	// Display widgets
	NewLabel(text string) LabelWidget
	NewButton() ButtonWidget
	NewImage() ImageWidget
	NewProgressBar() ProgressBarWidget
	NewSpinner() SpinnerWidget

	// Wrap existing GTK widget
	WrapWidget(w *gtk.Widget) Widget
}

WidgetFactory creates widget instances. This abstraction allows tests to inject mock factories.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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