button

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package button implements an interactive widget that can be pressed to activate.

Index

Constants

View Source
const DefaultHeight = 3

DefaultHeight is the default for the Height option.

View Source
const DefaultKeyUpDelay = 250 * time.Millisecond

DefaultKeyUpDelay is the default value for the KeyUpDelay option.

Variables

This section is empty.

Functions

This section is empty.

Types

type Button

type Button struct {
	// contains filtered or unexported fields
}

Button can be pressed using a mouse click or a configured keyboard key.

Upon each press, the button invokes a callback provided by the user.

Implements widgetapi.Widget. This object is thread-safe.

func New

func New(text string, cFn CallbackFn, opts ...Option) (*Button, error)

New returns a new Button that will display the provided text. Each press of the button will invoke the callback function.

func (*Button) Draw

func (b *Button) Draw(cvs *canvas.Canvas, meta *widgetapi.Meta) error

Draw draws the Button widget onto the canvas. Implements widgetapi.Widget.Draw.

func (*Button) Keyboard

func (b *Button) Keyboard(k *terminalapi.Keyboard) error

Keyboard processes keyboard events, acts as a button press on the configured Key.

Implements widgetapi.Widget.Keyboard.

func (*Button) Mouse

func (b *Button) Mouse(m *terminalapi.Mouse) error

Mouse processes mouse events, acts as a button press if both the press and the release happen inside the button.

Implements widgetapi.Widget.Mouse.

func (*Button) Options

func (b *Button) Options() widgetapi.Options

Options implements widgetapi.Widget.Options.

type CallbackFn

type CallbackFn func() error

CallbackFn is the function called when the button is pressed. The callback function must be light-weight, ideally just storing a value and returning, since more button presses might occur.

The callback function must be thread-safe as the mouse or keyboard events that press the button are processed in a separate goroutine.

If the function returns an error, the widget will forward it back to the termdash infrastructure which causes a panic, unless the user provided a termdash.ErrorHandler.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is used to provide options.

func FillColor

func FillColor(c cell.Color) Option

FillColor sets the fill color of the button.

func GlobalKey

func GlobalKey(k keyboard.Key) Option

GlobalKey is like Key, but makes the widget respond to the key even if its container isn't focused. When not provided, the widget ignores all keyboard events.

func Height

func Height(cells int) Option

Height sets the height of the button in cells. Must be a positive non-zero integer. Defaults to DefaultHeight.

func Key

func Key(k keyboard.Key) Option

Key configures the keyboard key that presses the button. The widget responds to this key only if its container if focused. When not provided, the widget ignores all keyboard events.

func KeyUpDelay

func KeyUpDelay(d time.Duration) Option

KeyUpDelay is the amount of time the button will remain "pressed down" after triggered by the configured key. Termbox doesn't emit events for key releases so the button simulates it by timing it. This only works if the manual termdash redraw or the periodic redraw interval are reasonably close to this delay. The duration cannot be negative. Defaults to DefaultKeyUpDelay.

func ShadowColor

func ShadowColor(c cell.Color) Option

ShadowColor sets the color of the shadow under the button.

func TextColor

func TextColor(c cell.Color) Option

TextColor sets the color of the text label in the button.

func Width

func Width(cells int) Option

Width sets the width of the button in cells. Must be a positive non-zero integer. Defaults to the auto-width based on the length of the text label.

func WidthFor

func WidthFor(text string) Option

WidthFor sets the width of the button as if it was displaying the provided text. Useful when displaying multiple buttons with the intention to set all of their sizes equal to the one with the longest text.

Directories

Path Synopsis
Binary buttondemo shows the functionality of a button widget.
Binary buttondemo shows the functionality of a button widget.

Jump to

Keyboard shortcuts

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