popover

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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

type KeyMap struct {
	Dismiss keymap.Binding // close the popover and deliver DismissedMsg
}

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

func New(content string, anchorX, anchorY int) Model

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

func (m Model) Bindings() []keymap.Binding

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

func (m Model) LayoutNode() layout.Node

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

func (m Model) Linearize() string

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) Open

func (m Model) Open() bool

Open reports whether the popover is currently shown.

func (Model) Rect

func (m Model) Rect() hittest.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

func (m *Model) Release(r focus.Ring) focus.Ring

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

func (m Model) Render(base string) string

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

func (m Model) SetTheme(t theme.Theme) Model

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) Show

func (m *Model) Show()

Show opens the popover.

func (Model) Tokens

func (m Model) Tokens() theme.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

func (m *Model) Trap(r focus.Ring, items int) focus.Ring

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.

func (Model) Update

func (m Model) Update(msg tui.Msg) (Model, tui.Cmd)

Update dismisses the popover on Enter or Esc while open; it's a no-op (including for Enter/Esc) once closed, so a parent doesn't need to guard forwarding to it on Model.Open().

func (Model) WithTokens

func (m Model) WithTokens(tok theme.Tokens) Model

WithTokens returns m with tok as its per-instance colour override. Nil fields inherit from the theme, so only the roles tok names change; the theme and every other widget are untouched. A second call replaces the first.

Jump to

Keyboard shortcuts

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