Skip to content

Icon: vector icons

Build vector icons with Icon. 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"
	"github.com/dxui-org/dxui/icon"
	"log"
)

func main() {

	app := dxui.NewApp(dxui.AppOptions{
		Title:      "Icon",
		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.Icon(dxui.IconProps{
				Data:        icon.Search(),
				Size:        32,
				StrokeWidth: 2,
				Color:       dxui.TokenColor(dxui.Color.Semantic.Accent),
			}),
		)
	}); err != nil {

		log.Fatal(err)
	}
}

Parameters and API

go
func Icon(props IconProps) 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.
DataIconDataValid icon data from an official constructor or custom filled paths.
Sizefloat32Logical size; 0 uses the theme default.
ColorColorValueExplicit color or TokenColor; inherits theme color when unset.
StrokeWidthIconStrokeWidthFinite nonnegative view-box stroke width; 0 means 2. Ignored for filled paths.

Behavior and limitations

Size uses logical units; 0 selects the theme default of 20. StrokeWidth uses view-box units, must be finite/nonnegative, and defaults to 2 when zero; custom filled icons ignore it. Icons have no action semantics; compose with Button. Individual icon.Name() calls link on demand, while icon/catalog retains the full catalog. IconData does not parse SVG.

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