Documentation
¶
Overview ¶
Package popover is a click/key-triggered overlay holding arbitrary (possibly multi-line) content, anchored near a given point rather than centered over the whole base — unlike dialog.Model, which always centers. Its open/dismiss lifecycle mirrors dialog.Model exactly.
Example ¶
A popover draws a small box anchored at a cell over the base screen.
package main
import (
"fmt"
"strings"
"github.com/ows4444/tui/ansi"
"github.com/ows4444/tui/popover"
)
func main() {
base := strings.TrimRight(strings.Repeat(strings.Repeat(".", 14)+"\n", 5), "\n")
m := popover.New("tip", 2, 1)
m.Show()
fmt.Println(strings.Contains(ansi.StripANSI(m.Render(base)), "tip"))
}
Output: true
Index ¶
- type DismissedMsg
- type KeyMap
- type Model
- func (m Model) Bindings() []keymap.Binding
- func (m *Model) Hide()
- func (m Model) LayoutNode() layout.Node
- func (m Model) Linearize() string
- func (m Model) Open() bool
- func (m Model) Rect() hittest.Rect
- func (m *Model) Release(r focus.Ring) focus.Ring
- func (m Model) Render(base string) string
- func (m Model) SetTheme(t theme.Theme) Model
- func (m *Model) Show()
- func (m Model) Tokens() theme.Tokens
- func (m *Model) Trap(r focus.Ring, items int) focus.Ring
- func (m Model) Update(msg tui.Msg) (Model, tui.Cmd)
- 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 DismissedMsg ¶
type DismissedMsg struct{}
DismissedMsg is delivered (via the Cmd Update returns) when the popover is dismissed with Enter or Esc.
type KeyMap ¶
KeyMap names the keys of each action of a Model.
func DefaultKeyMap ¶
func DefaultKeyMap() KeyMap
DefaultKeyMap returns the keys a Model used before KeyMap existed.
type Model ¶
type Model struct {
// Content holds arbitrary, possibly multi-line text rendered inside
// the popover's bordered box, unwrapped and unsplit (unlike
// dialog.Model's Title/Message split).
Content string
Theme theme.Theme
// AnchorX, AnchorY is the point the popover is placed near. Default
// placement is below and right of the anchor, matching
// widgets.TooltipOverlay; Render clamps/flips it to stay within base.
AnchorX, AnchorY int
// KeyMap holds the keys that dismiss the popover. New fills it with
// DefaultKeyMap; a Model built as a struct literal with a zero KeyMap
// behaves as if it held DefaultKeyMap.
KeyMap KeyMap
// Mouse, when true, makes Update handle tui.MouseEvent while the popover
// is open: a left click outside the popover dismisses it (DismissedMsg, as
// Esc does) and a click inside it is swallowed. Off (the default) ignores
// the mouse.
Mouse bool
// Bounds is the screen rectangle of the base view the popover is rendered
// over; the popover's own rectangle is worked out from it as Render does.
Bounds hittest.Rect
// contains filtered or unexported fields
}
Model is an anchored popover. Render composites it over a base view when open; when closed, Render returns base unchanged, so a parent can unconditionally call it every frame without checking Open itself.
func New ¶
New returns an already-open Model anchored at (anchorX, anchorY) — the common case is showing a popover immediately in response to some trigger, not constructing one ahead of time and opening it later (though Show/Hide support that too).
func (Model) Bindings ¶
Bindings returns the actions the popover currently honours, with descriptions, for help text. A closed popover honours none.
func (*Model) Hide ¶
func (m *Model) Hide()
Hide closes the popover without dismissing it via Update (no DismissedMsg is sent).
func (Model) LayoutNode ¶
LayoutNode returns the popover's bordered box as an ordinary layout.Node (Content unwrapped, as Render draws it), cut to the size it is given. While the popover is closed it measures as nothing and renders blank. The Model is not changed.
func (Model) Linearize ¶
Linearize renders the popover as plain text for accessible output (see tui.Linearizer): "Popover" and then its content, or "" while it is closed.
func (Model) Rect ¶
Rect is the screen rectangle the popover occupies when rendered over a base view filling Bounds. It is the zero Rect while the popover is closed.
func (*Model) Release ¶
Release hides the popover and pops the scope Trap pushed, returning the Ring with focus back on the widget that had it before the popover opened. Call it when DismissedMsg arrives, then Sync the Ring so that widget is told it has focus again. On a Ring with no open scope it only hides the popover.
func (Model) Render ¶
Render composites the popover, anchored near (AnchorX, AnchorY), over base. If the popover is closed, it returns base unchanged.
Default placement is below and right-aligned to the anchor: the popover's top-left corner starts at (AnchorX, AnchorY+1). If that would push the popover's right edge past base's rendered width, it's shifted left just enough to stay within bounds. If placing it below the anchor would push it past base's last line, it's placed above the anchor instead — the same semantics as widgets.TooltipOverlay.
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.ComponentPopover, ...) and then by WithTokens.
func (*Model) Trap ¶
Trap shows the popover and traps focus in it: it pushes a focus scope of items focusable items (at least 1) over r and returns the new Ring. While the scope is open Tab and Shift+Tab cycle among those items only, never reaching the widgets behind the popover. Call Release with the Ring when the popover closes.