Documentation
¶
Overview ¶
Package tabs is a horizontal tab bar — InkUI's "Tabs". It only manages which tab is active and renders the bar itself; actual per-tab content switching stays app-owned (the parent reads Active() and renders whichever content it has for that index), the same way picker doesn't own what "selected" means beyond reporting an index.
Example ¶
Tabs track which one is active; the right arrow moves to the next.
package main
import (
"fmt"
"github.com/ows4444/tui"
"github.com/ows4444/tui/tabs"
)
func main() {
m := tabs.New("files", "search", "settings")
m, _ = m.Update(tui.Key{Type: tui.KeyRight})
fmt.Println(m.Active())
}
Output: 1
Index ¶
- type ChangedMsg
- type KeyMap
- type Model
- func (m Model) Active() int
- func (m Model) Bindings() []keymap.Binding
- func (m Model) LayoutNode() layout.Node
- func (m Model) Linearize() string
- func (m *Model) SetActive(i int)
- func (m Model) SetTheme(t theme.Theme) Model
- func (m Model) Tokens() theme.Tokens
- func (m Model) Update(msg tui.Msg) (Model, tui.Cmd)
- func (m Model) View() string
- func (m Model) WithTokens(tok theme.Tokens) Model
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChangedMsg ¶
type ChangedMsg struct{ Index int }
ChangedMsg is delivered (via the Cmd Update returns) when the active tab changes.
type KeyMap ¶
KeyMap is the set of keys Update reacts to.
func DefaultKeyMap ¶
func DefaultKeyMap() KeyMap
DefaultKeyMap returns the default bindings: left and right move, tab cycles with wrap-around.
type Model ¶
type Model struct {
Labels []string
Theme theme.Theme
// KeyMap holds the key bindings Update obeys. New fills it with
// DefaultKeyMap; a Model built as a literal with no bindings set behaves
// as if it held DefaultKeyMap.
KeyMap KeyMap
// Mouse, when true, makes Update handle tui.MouseEvent: a left click on
// a tab label activates it. Off (the default) ignores the mouse.
Mouse bool
// Bounds is the screen rectangle where the app draws the bar (its first
// row holds the tabs); clicks outside it are ignored.
Bounds hittest.Rect
// contains filtered or unexported fields
}
Model is a horizontal tab bar: Left/Right move the active tab (clamped at the ends), Tab wraps around.
func (Model) LayoutNode ¶
LayoutNode adapts the tab bar to a layout.Node. Measure reports its natural size (every tab " label " with one space between, one row). Render fits the allotted Size: when the bar is wider than the space, it scrolls so the active tab is always visible (its right edge if it fits, its left edge if the tab itself is wider than the space). The Model is not changed.
func (Model) Linearize ¶
Linearize renders the tab bar as plain text for accessible output (see tui.Linearizer): one line per tab with its label and position, and ", selected" on the active tab, e.g. "Logs, tab 2 of 3, selected". No padding or reverse-video styling. With no tabs it reads "No tabs".
func (*Model) SetActive ¶
SetActive sets the active tab to i, clamped to a valid index (or 0 with no labels).
func (Model) SetTheme ¶
SetTheme returns m with t applied. It makes Model a tui.ThemeSetter, so a root model can forward the Program's theme (see tui.WithTheme).
func (Model) Tokens ¶
Tokens returns the colour tokens the widget renders with: its theme's roles, overridden by any theme.WithTokens(theme.ComponentTabs, ...) and then by WithTokens.
func (Model) Update ¶
Update moves the active tab on the Prev/Next bindings (clamped at the ends) or Cycle (wrapping around). With Mouse on, a left click on a tab label activates it. Any other Msg is a no-op.