button

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package button renders a horizontal row of focusable buttons - "No Yes", or a lone "OK" - the affordance a confirm dialog puts under its prompt. One button holds focus; the arrow keys (via Row.Step) move it with wrap, and Row.Hit maps a clicked column back to a button so a mouse can press one directly.

Like pill and titlebox it is style-agnostic: each button carries its own focused and blurred styles, so a caller renders a green Yes and a red No - or any other pair - without the package knowing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Button

type Button struct {
	Label   string
	Focused lg.Style
	Blurred lg.Style
}

Button is one pressable label with its two looks. The focused style renders when the button holds the row's focus, the blurred style otherwise; padding and background belong to the styles, so a pill-shaped button is just a style with a background and Padding(0, 1).

type Row

type Row struct {
	Buttons []Button
	// Focus is the focused button's index; out-of-range renders every button
	// blurred.
	Focus int
	// Gap separates adjacent buttons; empty means two spaces.
	Gap string
}

Row is an ordered set of buttons with one focus. The zero value renders nothing and hits nothing.

func (*Row) Hit

func (r *Row) Hit(x int) int

Hit returns the index of the button occupying column x of the rendered row (0-based from the row's first column), or -1 when x falls in a gap or outside the row. Widths are measured on the styled rendering, so a style's padding counts as pressable surface.

func (*Row) Step

func (r *Row) Step(delta int)

Step moves the focus by delta, wrapping at both ends.

func (*Row) View

func (r *Row) View() string

View renders the buttons side by side, the focused one in its focused style.

Jump to

Keyboard shortcuts

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