English
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) Viewgo
func TextButton(props ButtonProps, label string) View| Field | Type | Purpose, defaults, and constraints |
|---|---|---|
Key | string | Stable unique identity within one parent; empty by default. Use business IDs in dynamic lists, not changing indices. |
Style | Style | Local layout, paint, and text styling; zero uses intrinsic sizes and theme defaults. |
Token | ComponentToken | Component theme entry; empty selects its default. |
States | StateStyles | Paint patches for actual interaction states; cannot fabricate state or change layout. |
Pointer | PointerBehavior | Defaults to PointerAuto; PointerNone excludes the entire subtree from pointer participation, unlike Disabled. |
Variant | ButtonVariant | Defaults to ButtonFilled; see appearance recipes below. |
Tone | ButtonTone | Defaults to ButtonPrimary; ButtonDefault is an alias. |
Size | ButtonSize | Size enum; defaults to ButtonNormal. |
Disabled | bool | Defaults to false; true removes focus and cancels interaction on interactive components. |
OnPress | func() | 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.