button

package
v1.0.31-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 10 Imported by: 1 module, 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 button provides a stateful clickable button component built on the stateless elements.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Button

type Button struct {
	// Contextual gives it a context menu (Context).
	elements.Contextual
	// contains filtered or unexported fields
}

Button is a stateful clickable button. Create it once with New and lay it out every frame; label, styles and handler may change at any time.

func New

func New(label string, st ...styles.Styles) *Button

New returns a Button with the given label. The styles argument is optional.

func (*Button) CacheSafe

func (b *Button) CacheSafe() bool

CacheSafe reports whether the button can cache its output: its icons, if any, must be CacheSafe too.

func (*Button) Click

func (b *Button) Click()

Click simulates a click programmatically. It does nothing while the button is disabled or loading.

func (*Button) Disabled

func (b *Button) Disabled(v bool) *Button

Disabled dims the button and ignores input: no clicks, no hover, default cursor. It returns b for chaining.

func (*Button) Focus

func (b *Button) Focus()

Focus gives the button keyboard focus on the next frame.

func (*Button) Focused

func (b *Button) Focused() bool

Focused reports whether the button had keyboard focus last frame.

func (*Button) Icon

func (b *Button) Icon(el elements.Element) *Button

Icon sets an element shown before the label, typically an icon. Icons that set no Color of their own follow the label color. It returns b for chaining; Icon(nil) removes it.

func (*Button) IsDisabled

func (b *Button) IsDisabled() bool

IsDisabled reports whether the button is disabled.

func (*Button) IsLoading

func (b *Button) IsLoading() bool

IsLoading reports whether the button shows its loading state.

func (*Button) Label

func (b *Button) Label(label string) *Button

Label replaces the button label. It returns b for chaining.

func (*Button) Layout

func (b *Button) Layout(gtx layout.Context) layout.Dimensions

Layout lays out and updates the button. It replays the output recorded last time until its label, styles, state, hover or press, constraints or direction change.

func (*Button) Loading

func (b *Button) Loading(v bool) *Button

Loading shows a spinner in place of the icon and ignores clicks while v is true - for actions in progress. It returns b for chaining.

func (*Button) OnClick

func (b *Button) OnClick(fn func()) *Button

OnClick sets the handler invoked on every click. It returns b for chaining.

func (*Button) Styles

func (b *Button) Styles(st styles.Styles) *Button

Styles replaces the button styles. It returns b for chaining.

func (*Button) TrailingIcon

func (b *Button) TrailingIcon(el elements.Element) *Button

TrailingIcon sets an element shown after the label - a chevron, an external-link mark. It follows the label color like Icon. It returns b for chaining.

func (*Button) Variant

func (b *Button) Variant(v Variant) *Button

Variant sets the button's visual style (VariantContained, the default, VariantOutlined or VariantGhost). It returns b for chaining.

type Variant

type Variant string

Variant selects the button's visual style.

const (
	// VariantContained fills the button with Background (or black if
	// unset) at all times - the default, and today's only look before
	// Variant existed.
	VariantContained Variant = "contained"
	// VariantOutlined is transparent with a visible border, filling
	// faintly with the border color on hover/press.
	VariantOutlined Variant = "outlined"
	// VariantGhost is fully transparent at rest - only the label is
	// visible - filling faintly with Background on hover/press.
	VariantGhost Variant = "ghost"
)

Jump to

Keyboard shortcuts

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