egui-cha
A TEA (The Elm Architecture) framework for egui with a built-in Design System.
Why egui-cha?
Building admin panels, debug tools, or internal utilities with egui is great, but:
- Time consuming - Writing everything from scratch takes time you don't have
- Prototypes grow fast - "Quick hack" becomes 5000 lines of spaghetti
- Separation gets blurry - UI code and application logic become tangled
The Problem with Raw egui
// Typical egui code - logic scattered everywhere
if ui.button.clicked
The TEA Solution
// View: purely presentational
primary.on_click;
// Update: all logic in one place
Result: Logic stays in update(), views stay simple, and your "quick tool" won't fall apart as it grows.
Features
- TEA Architecture: Model-View-Update pattern with
Cmdfor side effects - Router: Built-in navigation with history (back/forward)
- Design System: Themed components following Atomic Design principles
- Icon Support: Phosphor Icons integration (embedded font)
- Error Handling: Structured error handling with
Cmd::try_task,ErrorConsole, andon_framework_error - Testing Utilities:
TestRunnerfor unit testing your app logic
Installation
Or add to your Cargo.toml:
[]
= "0.1"
= "0.1"
Quick Start
use *;
use *;
;
Architecture
┌────────────────────────────────────────┐
│ egui-cha-ds (Design System) │
│ Button, Input, Card, Icon, Theme... │
├────────────────────────────────────────┤
│ egui-cha (TEA Core) │
│ App, Cmd, ViewCtx, Router, Component │
└────────────────────────────────────────┘
↓
egui
Components
Core (egui-cha)
| Component | Description |
|---|---|
App |
Main application trait with init, update, view |
Cmd |
Side effects: task, delay, try_task, from_result, retry |
Severity |
Error levels: Debug, Info, Warn, Error, Critical |
FrameworkError |
Framework internal errors with on_framework_error hook |
ViewCtx |
UI context with emit, horizontal, vertical, group |
Router |
Page navigation with history stack |
Component |
Reusable component trait |
ScrollArea |
Scrollable container with builder pattern |
Design System (egui-cha-ds)
Theme
// Apply theme to egui context
let theme = dark; // or Theme::light(), Theme::pastel(), Theme::pastel_dark()
theme.apply;
Theme includes:
- Colors: Primary, Secondary, UI State (state_success/warning/danger/info), Log Severity (log_debug/info/warn/error/critical), Background, Text, Border
- Spacing: xs (4px), sm (8px), md (16px), lg (24px), xl (32px)
- Border Radius: sm, md, lg
- Typography: font_size_xs (10px) through font_size_3xl (30px)
Atoms (13 components)
| Component | Description |
|---|---|
Button |
Primary, Secondary, Outline, Ghost, Danger, Warning, Success, Info |
Badge |
Default, Success, Warning, Error, Info |
Text |
Typography: h1, h2, h3, body, small, caption with modifiers |
Input |
Text input with TEA-style callbacks |
ValidatedInput |
Input with validation state |
Checkbox |
Boolean toggle with label |
Toggle |
Switch-style boolean toggle |
Slider |
Numeric range input |
Select |
Dropdown selection |
Icon |
Phosphor Icons (house, gear, info, etc.) |
Link |
Hyperlink component |
Code |
Code block display |
Tooltip |
Themed tooltips via ResponseExt trait |
ContextMenu |
Right-click menu via ContextMenuExt trait |
Molecules (9 components)
| Component | Description |
|---|---|
Card |
Container with optional title |
Tabs |
Tabbed navigation with TabPanel |
Modal |
Dialog overlay |
Table |
Data table component |
Navbar |
Horizontal navigation bar |
ErrorConsole |
5-level severity message display (Debug/Info/Warning/Error/Critical) |
Toast |
Temporary notifications with auto-dismiss |
Form |
Structured form with validation |
SearchBar |
Search input with submit |
Semantics (Pre-defined buttons)
// Consistent labels & icons across your app
save.on_click;
delete.on_click;
Available: save, edit, delete, close, add, remove, search, refresh, play, pause, stop, settings, back, forward, confirm, cancel, copy
Layout DSL (cha! macro)
Declarative layout syntax for composing views:
use cha;
cha!;
Supported Nodes
| Node | Description |
|---|---|
Col |
Vertical layout (ctx.vertical) |
Row |
Horizontal layout (ctx.horizontal) |
Group |
Grouped layout (ctx.group) |
Scroll |
Vertical scroll area |
ScrollH |
Horizontal scroll area |
ScrollBoth |
Both directions scroll |
Card("title") |
Card container |
@icon |
Icon shorthand (e.g., @house, @gear(20.0)) |
Properties
- Layout:
spacing,padding - Scroll:
max_height,max_width,min_height,min_width,id - Card:
padding
Commands (Side Effects)
// Async task
task
// Delayed message
delay
// Fallible async with error handling
try_task
// Batch multiple commands
batch
Router
// In your Model
// Navigate
Router
Router
Router
// In view
navbar;
Icons (Phosphor)
use ;
// Using convenience constructors
house.size.show;
gear.color.show;
// Using icon constants directly
new.show;
Available icons: HOUSE, GEAR, HASH, INFO, USER, CHECK, WARNING, PLUS, MINUS, X, ARROW_LEFT, ARROW_RIGHT, FIRE, BUG, WRENCH, X_CIRCLE
Testing
use *;
License
MIT
Credits
- egui - Immediate mode GUI library
- Phosphor Icons - Icon font