Icon β
The Icon widget displays a single character or short string (like an emoji) that can optionally respond to clicks.
Basic Usage β
Use the Icon() extension method to display icons inline with other content.
csharp
using Hex1b;
using Hex1b.Widgets;
await using var terminal = Hex1bTerminal.CreateBuilder()
.WithHex1bApp((app, options) => ctx => ctx.HStack(h => [
h.Icon("π "),
h.Text(" Home"),
h.Text(" | "),
h.Icon("βοΈ"),
h.Text(" Settings"),
h.Text(" | "),
h.Icon("β"),
h.Text(" Help")
]))
.Build();
await terminal.RunAsync();dotnet runKey features:
- Display emoji, Unicode symbols, or short text
- Automatically measures to single-character width (or emoji width)
- Lightweight widget for decorative or indicator purposes
Clickable Icons β
Attach an OnClick() handler to make icons interactive.
csharp
using Hex1b;
using Hex1b.Widgets;
await using var terminal = Hex1bTerminal.CreateBuilder()
.WithHex1bApp((app, options) => ctx => ctx.VStack(v => [
v.Text("Click an icon:"),
v.Text(""),
v.HStack(h => [
h.Icon("βΆοΈ").OnClick(_ => Console.WriteLine("Play!")),
h.Text(" "),
h.Icon("βΈοΈ").OnClick(_ => Console.WriteLine("Pause!")),
h.Text(" "),
h.Icon("βΉοΈ").OnClick(_ => Console.WriteLine("Stop!"))
])
]))
.Build();
await terminal.RunAsync();dotnet runWhen a click handler is attached, the icon:
- Responds to mouse clicks
- Becomes focusable for keyboard navigation
- Can be activated with Enter/Space when focused
API Reference β
| Method | Description |
|---|---|
Icon(string) | Create an icon with the specified character/emoji |
OnClick(handler) | Handle click events (sync or async) |
Common Patterns β
Status Indicators β
csharp
ctx.HStack(h => [
h.Icon(status.IsOnline ? "π’" : "π΄"),
h.Text($" {status.Name}")
])1
2
3
4
2
3
4
Action Buttons β
csharp
ctx.HStack(h => [
h.Icon("βοΈ").OnClick(_ => Edit()),
h.Text(" "),
h.Icon("ποΈ").OnClick(_ => Delete())
])1
2
3
4
5
2
3
4
5
With Tree Items β
Icons are commonly used with Tree items to indicate file types:
csharp
t.Item("Documents").Icon("π")
t.Item("README.md").Icon("π")1
2
2