Documentation
¶
Overview ¶
Package tabview provides a tabbed navigation widget.
Construction uses functional options for immutable configuration:
tv := tabview.New(
[]tabview.Tab{
{Label: "Home", Content: homeWidget},
{Label: "Settings", Content: settingsWidget},
},
tabview.PositionOpt(tabview.Top),
tabview.Closeable(true),
tabview.OnSelect(func(idx int) { fmt.Println("selected:", idx) }),
)
Tab Position ¶
Tabs can be placed at the top or bottom of the content area:
Keyboard Navigation ¶
When the tab bar is focused, the following keys are supported:
- Left/Right arrows -- navigate between tabs (skipping disabled tabs)
- Home -- select first enabled tab
- End -- select last enabled tab
Closeable Tabs ¶
When closeable is enabled (globally or per-tab), a close button appears on each tab. Clicking it triggers the OnClose callback.
Signal Binding ¶
The selected tab index can be bound to a reactive signal:
selected := state.NewSignal(0) tv := tabview.New(tabs, tabview.SelectedSignalOpt(selected)) selected.Set(2) // switches to third tab
Visual Style ¶
The visual rendering is provided by a Painter implementation. Each design system (Material 3, Fluent, Cupertino) supplies its own painter to render the tab bar in the appropriate visual style.
If no painter is set, DefaultPainter is used.
Focus ¶
TabView implements widget.Focusable and participates in tab navigation. A focus ring is drawn around the tab bar when focused.
Index ¶
- type DefaultPainter
- type Option
- func Closeable(v bool) Option
- func OnClose(fn func(index int)) Option
- func OnSelect(fn func(index int)) Option
- func PainterOpt(p Painter) Option
- func PositionOpt(p TabPosition) Option
- func SelectedIndex(idx int) Option
- func SelectedReadonlySignalOpt(sig state.ReadonlySignal[int]) Option
- func SelectedSignalOpt(sig state.Signal[int]) Option
- type PaintState
- type Painter
- type Tab
- type TabColorScheme
- type TabPosition
- type TabState
- type Widget
- func (w *Widget) Children() []widget.Widget
- func (w *Widget) Draw(ctx widget.Context, canvas widget.Canvas)
- func (w *Widget) Event(ctx widget.Context, e event.Event) bool
- func (w *Widget) IsFocusable() bool
- func (w *Widget) Layout(ctx widget.Context, constraints geometry.Constraints) geometry.Size
- func (w *Widget) Mount(ctx widget.Context)
- func (w *Widget) SelectedIndex() int
- func (w *Widget) TabCount() int
- func (w *Widget) Unmount()
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 a simple tab bar useful for testing and prototyping.
func (DefaultPainter) PaintTabBar ¶
func (p DefaultPainter) PaintTabBar(canvas widget.Canvas, ps PaintState)
PaintTabBar renders a minimal tab bar with basic styling.
type Option ¶
type Option func(*config)
Option configures a tabview during construction.
func Closeable ¶
Closeable enables close buttons on all tabs. Individual tabs can override this via [Tab.Closeable].
func OnClose ¶
OnClose sets the callback invoked when a tab's close button is clicked. The callback receives the index of the tab being closed.
func OnSelect ¶
OnSelect sets the callback invoked when a tab is selected. The callback receives the index of the newly selected tab.
func PainterOpt ¶
PainterOpt sets the painter used to render the tab bar. Each design system provides its own painter. If not set, DefaultPainter is used.
func PositionOpt ¶
func PositionOpt(p TabPosition) Option
PositionOpt sets the tab bar position (top or bottom).
func SelectedIndex ¶
SelectedIndex sets the initially selected tab index.
func SelectedReadonlySignalOpt ¶
func SelectedReadonlySignalOpt(sig state.ReadonlySignal[int]) Option
SelectedReadonlySignalOpt binds the selected tab index to a read-only signal. This is useful for computed signals. When set, it takes highest precedence.
func SelectedSignalOpt ¶
SelectedSignalOpt binds the selected tab index to a writable reactive signal. When set, the signal value takes precedence over SelectedIndex but not over SelectedReadonlySignalOpt.
type PaintState ¶
type PaintState struct {
// Bounds is the tab bar area.
Bounds geometry.Rect
// Tabs contains the state of each tab.
Tabs []TabState
// SelectedIdx is the index of the currently selected tab.
SelectedIdx int
// Position is the tab bar position (top or bottom).
Position TabPosition
// Focused is true when the tab bar has keyboard focus.
Focused bool
// ColorScheme provides theme-derived colors for tab bar painting.
// Zero value means the painter should use its built-in defaults.
ColorScheme TabColorScheme
}
PaintState provides the current tab bar state to the painter.
type Painter ¶
type Painter interface {
PaintTabBar(canvas widget.Canvas, state PaintState)
}
Painter draws the visual representation of a tab bar. Each design system (Material 3, Fluent, Cupertino) provides its own Painter implementation to render the tab bar in its visual style.
If no Painter is set, the tabview uses DefaultPainter.
type Tab ¶
type Tab struct {
// Label is the display text shown in the tab bar.
Label string
// Content is the widget displayed when this tab is selected.
// If nil, the tab area is empty when selected.
Content widget.Widget
// Closeable enables the close button for this specific tab.
// This overrides the widget-level closeable setting when true.
Closeable bool
// Disabled prevents the tab from being selected.
Disabled bool
}
Tab represents a single tab with a label, content widget, and options.
type TabColorScheme ¶
type TabColorScheme struct {
Background widget.Color
SelectedText widget.Color
UnselectedText widget.Color
Indicator widget.Color
HoverBackground widget.Color
CloseButton widget.Color
FocusRing widget.Color
}
TabColorScheme provides theme-derived colors for tab bar painting. Zero value means the painter should use its built-in defaults.
type TabPosition ¶
type TabPosition uint8
TabPosition controls where the tab bar is rendered relative to the content.
const ( // Top places the tab bar above the content area. Top TabPosition = iota // Bottom places the tab bar below the content area. Bottom )
Tab position constants.
func (TabPosition) String ¶
func (p TabPosition) String() string
String returns a human-readable name for the tab position.
type TabState ¶
type TabState struct {
// Label is the display text.
Label string
// Bounds is the tab's clickable area within the tab bar.
Bounds geometry.Rect
// Selected is true when this tab is the active tab.
Selected bool
// Hovered is true when the mouse is over this tab.
Hovered bool
// Disabled is true when this tab cannot be selected.
Disabled 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
}
TabState provides the state of a single tab to the painter.
type Widget ¶
type Widget struct {
widget.WidgetBase
// contains filtered or unexported fields
}
Widget implements a tabbed navigation container with configurable appearance.
A tabview is created with New using functional options:
tv := tabview.New(
[]tabview.Tab{
{Label: "Home", Content: homeWidget},
{Label: "Settings", Content: settingsWidget},
},
tabview.PositionOpt(tabview.Top),
tabview.OnSelect(func(idx int) { log.Println("selected:", idx) }),
)
func New ¶
New creates a new tabview Widget with the given tabs and options.
The returned widget is visible, enabled, and focusable by default.
func (*Widget) Children ¶
Children returns the content widgets of all tabs. Only the selected tab's content is laid out and drawn, but all content widgets are reported for tree traversal purposes.
func (*Widget) Draw ¶
Draw renders the tabview to the canvas. Only the selected tab's content is drawn (lazy).
func (*Widget) Event ¶
Event handles an input event and returns true if consumed.
Mouse and wheel event positions are translated from parent-local space to TabView-local space before hit-testing and child dispatch, matching the coordinate convention used by [splitview.Widget].
func (*Widget) IsFocusable ¶
IsFocusable reports whether the tabview can currently receive focus.
func (*Widget) Layout ¶
Layout calculates the tabview's preferred size within the given constraints. Only the selected tab's content is laid out (lazy).
func (*Widget) Mount ¶
Mount creates signal bindings for push-based invalidation. Implements widget.Lifecycle.
func (*Widget) SelectedIndex ¶
SelectedIndex returns the currently selected tab index.
func (*Widget) Unmount ¶
func (w *Widget) Unmount()
Unmount is called when the tabview is removed from the widget tree. Implements widget.Lifecycle.