Icon
A Lucide icon or any SVG, sized and tinted like text.
Loading the live example…
import (
"github.com/egoist/mygo/ui"
"github.com/oneo-me/onevra/source/components"
"github.com/oneo-me/onevra/source/icons/lucide"
)
type iconSizes struct{}
func (iconSizes) View(c *ui.Context) {
t := c.Theme()
ui.Column(c).Gap(16).AlignItems(ui.Center).Children(func() {
ui.Row(c).Gap(16).AlignItems(ui.Center).Children(func() {
for _, size := range []float32{16, 20, 24, 32, 48} {
components.Icon(c, lucide.Rocket).Size(size, size)
}
})
ui.Row(c).Gap(16).AlignItems(ui.Center).Children(func() {
components.Icon(c, lucide.Heart).Size(24, 24).TextColor(t.Danger)
components.Icon(c, lucide.CircleCheck).Size(24, 24).TextColor(t.Success)
components.Icon(c, lucide.TriangleAlert).Size(24, 24).TextColor(t.Warning)
components.Icon(c, lucide.Sparkles).Size(24, 24).TextColor(t.Accent)
})
})
}components.Icon takes a Lucide accessor, such as lucide.Rocket, or a parsed *ui.SVG. Icons inherit the text color and keep their strokes as they scale. See icons for the Lucide package.
File icons
Loading the live example…
import (
"github.com/egoist/mygo/ui"
"github.com/oneo-me/onevra/source/components"
)
type fileIcons struct{}
func (fileIcons) View(c *ui.Context) {
ui.Grid(c).Columns(3).Gap(12).Children(func() {
for _, name := range []string{"main.go", "go.mod", "App.tsx", "index.ts", "package.json", "README.md", "logo.svg", "build.sh", ".gitignore"} {
ui.Row(c).Gap(6).AlignItems(ui.Center).Children(func() {
components.FileIcon(c, name).Size(16, 16)
components.Text(c, name).FontSize(13)
})
}
})
}components.FileIcon shows a file's type, as code editors' file trees do. It picks a Lucide icon by the whole name, such as go.mod, or else by the extension, tinted in that ecosystem's color.
API
Icon
func Icon[T *ui.SVG | func() *ui.SVG](c *ui.Context, source T) ui.ElementIcon creates an SVG icon from a parsed asset or a named accessor such as lucide.Search (without calling it). Accessors run synchronously when the element is built; the asset package owns parsing and caching. A typed nil SVG or accessor produces an empty icon.
Icons inherit text color and font size from their parent. Use Size to set explicit dimensions and Label to supply application-owned accessible text. MyGo owns rendering, aspect ratio and element semantics. No icon registry or dependency on a particular icon pack is introduced.
pkg.go.devFileIcon
func FileIcon(c *ui.Context, name string) ui.ElementFileIcon creates the type icon of a file named name, as code editors' file trees show: a Lucide icon chosen by its whole name, such as go.mod or .gitignore, or else its extension, tinted in its ecosystem's color. name may be a path; only its last element counts. Unknown types show a plain file icon in the inherited text color.
Like Icon, it inherits font size; use Size for explicit dimensions and TextColor to override the tint.
pkg.go.dev