core/button/options.go

Functions

Functions

func A11yHint

A11yHint sets the accessibility hint text for the button.

func A11yHint(hint string) Option {
	return func(c *config) {
		c.a11yHint = hint
	}
}

func BackgroundOpt

BackgroundOpt sets a custom background color override.

func BackgroundOpt(color widget.Color) Option {
	return func(c *config) {
		c.background = &color
	}
}

func Disabled

Disabled sets the button's disabled state. A disabled button does not

respond to user input and is drawn with a dimmed appearance.

func Disabled(d bool) Option {
	return func(c *config) {
		c.disabled = d
	}
}

func DisabledFn

DisabledFn sets a dynamic function that is evaluated to determine whether

the button is disabled. When set, this takes precedence over the static value

but not over a signal set via [DisabledSignal].

func DisabledFn(fn func() bool) Option {
	return func(c *config) {
		c.disabledFn = fn
	}
}

func DisabledReadonlySignal

DisabledReadonlySignal binds the button's disabled state to a read-only signal.

This is useful for computed signals created via [state.NewComputed].

When set, this takes highest precedence over all other disabled sources.

func DisabledReadonlySignal(sig state.ReadonlySignal[bool]) Option {
	return func(c *config) {
		c.readonlyDisabledSignal = sig
	}
}

func DisabledSignal

DisabledSignal binds the button's disabled state to a reactive signal.

When set, the signal value takes precedence over both [DisabledFn] and [Disabled]

but not over [DisabledReadonlySignal].

func DisabledSignal(sig state.Signal[bool]) Option {
	return func(c *config) {
		c.disabledSignal = sig
	}
}

func OnClick

OnClick sets the callback invoked when the button is activated

(mouse click or keyboard Enter/Space).

func OnClick(fn func()) Option {
	return func(c *config) {
		c.onClick = fn
	}
}

func PainterOpt

PainterOpt sets the painter used to render the button.

Each design system provides its own painter. If not set,

[DefaultPainter] is used.

func PainterOpt(p Painter) Option {
	return func(c *config) {
		c.painter = p
	}
}

func RoundedOpt

RoundedOpt sets a custom corner radius override.

func RoundedOpt(radius float32) Option {
	return func(c *config) {
		c.rounded = &radius
	}
}

func SizeOpt

SizeOpt sets the button's size.

func SizeOpt(s Size) Option {
	return func(c *config) {
		c.size = s
	}
}

func TextFn

TextFn sets a dynamic text function that is evaluated on each draw.

When set, this takes precedence over the static text but not over

a signal set via [TextSignal].

func TextFn(fn func() string) Option {
	return func(c *config) {
		c.textFn = fn
	}
}

func TextOpt

TextOpt sets the button's static display text.

func TextOpt(s string) Option {
	return func(c *config) {
		c.text = s
	}
}

func TextReadonlySignal

TextReadonlySignal binds the button's display text to a read-only signal.

This is useful for computed signals created via [state.NewComputed].

When set, this takes highest precedence over all other text sources.

func TextReadonlySignal(sig state.ReadonlySignal[string]) Option {
	return func(c *config) {
		c.readonlyTextSignal = sig
	}
}

func TextSignal

TextSignal binds the button's display text to a reactive signal.

When set, the signal value takes precedence over both [TextFn] and [TextOpt]

but not over [TextReadonlySignal].

func TextSignal(sig state.Signal[string]) Option {
	return func(c *config) {
		c.textSignal = sig
	}
}

func VariantOpt

VariantOpt sets the button's visual variant.

func VariantOpt(v Variant) Option {
	return func(c *config) {
		c.variant = v
	}
}