core/tabview/painter.go
Functions
func PaintTabBar
func (p DefaultPainter) PaintTabBar(canvas widget.Canvas, ps PaintState) {
if ps.Bounds.IsEmpty() {
return
}
hasScheme := ps.ColorScheme != (TabColorScheme{})
// Tab bar background.
bg := defaultTabBarBg
if hasScheme {
bg = ps.ColorScheme.Background
}
canvas.DrawRect(ps.Bounds, bg)
// Draw each tab.
for i := range ps.Tabs {
ts := &ps.Tabs[i]
paintDefaultTab(canvas, ts, hasScheme, ps.ColorScheme)
}
// Draw indicator under selected tab.
if ps.SelectedIdx >= 0 && ps.SelectedIdx < len(ps.Tabs) {
selected := &ps.Tabs[ps.SelectedIdx]
indicatorColor := defaultIndicatorColor
if hasScheme {
indicatorColor = ps.ColorScheme.Indicator
}
tabW := selected.Bounds.Width()
indicatorBounds := geometry.NewRect(
selected.Bounds.Min.X,
selected.Bounds.Max.Y-indicatorHeight,
tabW,
indicatorHeight,
)
if ps.Position == Bottom {
indicatorBounds = geometry.NewRect(
selected.Bounds.Min.X,
selected.Bounds.Min.Y,
tabW,
indicatorHeight,
)
}
canvas.DrawRect(indicatorBounds, indicatorColor)
}
// Focus ring.
if ps.Focused {
ringColor := defaultFocusRingColor
if hasScheme {
ringColor = ps.ColorScheme.FocusRing
}
canvas.StrokeRect(ps.Bounds, ringColor, defaultFocusRingStroke)
}
}
Structs
type PaintState struct
PaintState provides the current tab bar state to the painter.
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
}
type TabState struct
TabState provides the state of a single tab to the painter.
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
}
type TabColorScheme struct
TabColorScheme provides theme-derived colors for tab bar painting.
Zero value means the painter should use its built-in defaults.
type TabColorScheme struct {
Background widget.Color
SelectedText widget.Color
UnselectedText widget.Color
Indicator widget.Color
HoverBackground widget.Color
CloseButton widget.Color
FocusRing widget.Color
}
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.
type DefaultPainter struct{}
Interfaces
type Painter interface
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 Painter interface {
PaintTabBar(canvas widget.Canvas, state PaintState)
}
PaintTabBar renders a minimal tab bar with basic styling.