English
Text: text and Label
Build text with Text and Label. 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 (
"github.com/dxui-org/dxui"
"log"
)
func main() {
app := dxui.NewApp(dxui.AppOptions{
Title: "Text",
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.Text(dxui.TextProps{
Value: "Hello dxui",
Wrap: dxui.TextWrapWords,
MaxLines: 2,
Style: dxui.Style{
Width: dxui.Px(240),
Text: dxui.TextStyle{
Size: 20,
},
},
}),
)
}); err != nil {
log.Fatal(err)
}
}Parameters and API
go
func Text(props TextProps) Viewgo
func Label(value 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. |
Value | string | Current application-owned value; see this page for behavior and zero-value semantics. |
Wrap | TextWrap | Defaults to TextNoWrap; TextWrapWords uses simple word wrapping. |
MaxLines | int | Positive values limit visible lines; 0 is unlimited, negative values fail the build. |
Behavior and limitations
Label(value) is default Text; TextNoWrap is the zero value. TextWrapWords uses simple word splitting and collapses whitespace, not full Unicode line breaking. Positive MaxLines limits lines. Invalid UTF-8 becomes U+FFFD. Text is not a selectable editor; CJK display depends on font coverage.
All components share identity, style, and pointer rules. See full declarations for referenced enums, structs, and comments. Running examples explains build verification.