Skip to content

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) View
go
func Label(value 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.
ValuestringCurrent application-owned value; see this page for behavior and zero-value semantics.
WrapTextWrapDefaults to TextNoWrap; TextWrapWords uses simple word wrapping.
MaxLinesintPositive 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.