Skip to content

Button: buttons and TextButton

Build buttons with Button. This page includes a runnable example, all props, and behavior constraints.

Complete example

Complete environment setup first. Copy this complete main.go and run go run ..

go
package main

import (
	"fmt"
	"github.com/dxui-org/dxui"
	"log"
)

func main() {
	count := 0
	app := dxui.NewApp(dxui.AppOptions{
		Title:      "Button",
		Width:      640,
		Height:     480,
		Background: dxui.RGBA(248, 250, 252, 255),
	})
	if err := app.Run(func() dxui.View {
		return dxui.Box(
			dxui.BoxProps{
				Gap: 16,
				Style: dxui.Style{
					Padding: dxui.Padding(24),
				},
			},
			dxui.Box(
				dxui.BoxProps{
					Gap: 12,
				},
				dxui.Label(fmt.Sprint(count)),
				dxui.TextButton(
					dxui.ButtonProps{
						Variant: dxui.ButtonOutline,
						Tone:    dxui.ButtonSuccess,
						Size:    dxui.ButtonNormal,
						OnPress: func() {

							count++
						},
					},
					"Add",
				),
				dxui.Button(dxui.ButtonProps{
					Disabled: true,
				}, dxui.Label("Disabled")),
			),
		)
	}); err != nil {

		log.Fatal(err)
	}
}

Parameters and API

go
func Button(props ButtonProps, child View) View
go
func TextButton(props ButtonProps, label string) View
FieldTypePurpose, defaults, and constraints
KeystringStable unique identity within one parent; empty by default. Use business IDs in dynamic lists, not changing indices.
StyleStyleLocal layout, paint, and text styling; zero uses intrinsic sizes and theme defaults.
TokenComponentTokenComponent theme entry; empty selects its default.
StatesStateStylesPaint patches for actual interaction states; cannot fabricate state or change layout.
PointerPointerBehaviorDefaults to PointerAuto; PointerNone excludes the entire subtree from pointer participation, unlike Disabled.
VariantButtonVariantDefaults to ButtonFilled; see appearance recipes below.
ToneButtonToneDefaults to ButtonPrimary; ButtonDefault is an alias.
SizeButtonSizeSize enum; defaults to ButtonNormal.
DisabledboolDefaults to false; true removes focus and cancels interaction on interactive components.
OnPressfunc()Runs on the UI thread after activation; nil performs no action.

Behavior and limitations

Button accepts one arbitrary child View; TextButton centers text. Defaults: Filled / Primary / Normal. Variants: Filled, Soft, Outline, Dashed, Ghost, Link. Tones: Primary, Secondary, Success, Info, Warn, Danger. Sizes: Small, Normal, Large. Explicit Token replaces the appearance recipe; local Style still overrides it. A matching pointer or Enter/Space release activates once. Nil OnPress retains focus and interaction appearance. Link does not navigate.

All components share identity, style, and pointer rules. See full declarations for referenced enums, structs, and comments. Running examples explains build verification.