Documentation ¶
Overview ¶
Package button implements an interactive widget that can be pressed to activate.
Index ¶
- Constants
- type Button
- type CallbackFn
- type Option
- func FillColor(c cell.Color) Option
- func GlobalKey(k keyboard.Key) Option
- func Height(cells int) Option
- func Key(k keyboard.Key) Option
- func KeyUpDelay(d time.Duration) Option
- func ShadowColor(c cell.Color) Option
- func TextColor(c cell.Color) Option
- func Width(cells int) Option
- func WidthFor(text string) Option
Constants ¶
const DefaultHeight = 3
DefaultHeight is the default for the Height option.
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 ¶
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.
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 GlobalKey ¶
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 ¶
Height sets the height of the button in cells. Must be a positive non-zero integer. Defaults to DefaultHeight.
func Key ¶
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 ¶
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 ¶
ShadowColor sets the color of the shadow under the button.
Directories ¶
Path | Synopsis |
---|---|
Binary buttondemo shows the functionality of a button widget.
|
Binary buttondemo shows the functionality of a button widget. |