egui_styled
A styling layer for egui with per-widget hover/focus/active styling, semantic design tokens, and composable style functions.
Tailwind-style utility styling for egui with Flutter-like
builder widget APIs. Style widgets in terms of 'how it looks' instead of
repeatedly cloning and mutating ui.visuals_mut().
docs.rs · crates.io · examples
Quick start
Install your geometry theme and palette once during app startup, then read them anywhere in your UI.
use Color32;
use *;
Why this exists
egui styling lives on ui.visuals_mut(), which is global to the current Ui.
Applying a custom hover color to a button means cloning visuals, mutating
multiple WidgetVisuals states, and wrapping the widget in ui.scope. The
pattern works, but scales badly.
egui_styled wraps common egui widgets in builder APIs that handle that
boilerplate for you. Per-widget hover/focus/active states just work, and
styles become values you can compose instead of side-effecting helper
functions that must immediately render into a Ui.
Before / After
A card with a text input and two buttons:
With egui_styled
use Color32;
use *;
let = ui.ctx.;
frame
.bg
.corner_radius
.padding
.border
.show;
ui.scope;
Fair comparison: you can factor the raw-egui version into helper functions, which closes most of the line gap. The bigger win is what kind of helper you can write. In raw egui, a style helper typically takes
&mut Uiand renders immediately. Inegui_styled, a style helper can returnimpl Fn(W) -> W: a pure value you can store, compose, and tweak at the call site (.apply(primary_button(&t, &p)).corner_radius(0.0)).
Installation
[]
= "0.7"
= "0.35"
Version compatibility
| egui_styled | egui | Rust (MSRV) |
|---|---|---|
| 0.7 | 0.35 | 1.92 |
| 0.6 | 0.34 | 1.92 |
| 0.5.x | 0.34 | 1.92 |
Tested with eframe on Linux, macOS, and Windows.
Web (wasm) is supported - a live demo runs at david-spray.me.
No feature flags currently.
App setup
Install the theme and palette once during app startup, then read them anywhere in your frame.
design::<T>() returns (StyledTheme, T). If you only need the palette, use
design_data::<T>().
Core concepts
Styled widgets
egui_styled provides styled wrappers for common egui widgets. Each one is a
builder that resolves its stored style into WidgetVisuals at .show() time,
inside its own ui.scope, so it does not pollute sibling widgets.
button
.bg
.hover_bg
.active_bg
.text_color
.corner_radius
.show;
text_edit
.hint
.full_width
.bg
.border
.focus_border
.show;
label
.font_size
.text_color
.bold
.show;
Available today: StyledButton, StyledLabel, StyledTextEdit,
StyledCheckbox, StyledSlider (partial), StyledComboBox (partial).
Design tokens
egui_styled separates geometry/typography tokens from colors.
StyledTheme holds reusable geometry and type-scale values - spacing,
radii, font sizes, font families, and text-effect scales:
StyledTheme
WebPalette is an optional starter palette for web/dashboard-style UIs:
WebPalette
If your app has its own design language, define your own palette type instead:
ctx.set_design_data;
let colors = ctx.;
Theme and palette data live on egui::Context in typed slots. If you need two
slots of the same underlying type, use newtypes.
Composable styles
The Apply trait lets you define a style vocabulary in app code without
coupling helpers to a specific Ui:
+ 'static
button.apply.show;
// Tweak at the call site without a new helper:
button.apply.bg.show;
The crate intentionally does not ship helpers like primary_button - what
counts as "primary" is a product decision, so you define that in
app code.
Containers and layout
StyledRow / StyledColumn are flow containers with gap, alignment,
and all box styling (bg, border, padding, corner radius, shadow):
row.gap.show;
StyledFrame is the core styled box container. It supports padding,
border, corner radius, width/height constraints, vertical justify, and
background images.
StyledArea is a top-level positioned container for modals, toasts, and
backdrops. It works on &egui::Context rather than &mut Ui.
StyledStack is the overlay container: multiple layers share one origin
and paint on top of each other. Use it for layered backgrounds, badges,
centered text over images, or visual effects such as chromatic aberration:
stack
.layer_offset
.layer_offset
.layer
.show;
Note on interactivity in stacks:
StyledStacktranslates its shapes after layout, so interactive widgets inside translated layers are hit-tested at the pre-translation position. Fine for labels and visual effects; avoid burying a button deep inside a centered stack.
.extend()onStyledLabelusesTextWrapMode::Extend: natural width, no wrapping, no truncation. Especially useful inside stacks and tight rows.
Layout primitives
egui_styled adds CSS-inspired layout utilities on top of egui's flow system.
Spacer - pushes following siblings to the far edge:
row.full_width.show;
Percentage sizing - width_pct / height_pct on any styled type.
Resolves at render time, supersedes full_width/full_height, composes with
min_*/max_* as clamps:
frame.width_pct.show;
frame.width_pct.max_width.show;
Aspect ratio - derives height from width (width ÷ height, CSS
convention). Requires a definite width (width_pct or full_width); no-op
without one. Overridden by an explicit height_pct or full_height:
// 16:9 placeholder that scales with its column
frame
.width_pct
.aspect_ratio
.bg
.show;
Distribution - three CSS style justify-content modes on StyledRow. Each
measures item widths with an invisible first pass, then distributes slack:
// ends pinned, equal gaps between
row.full_width.bg.padding.space_between
.item
.item
.item
.show;
// space_around: equal margin each side of each item
// space_evenly: equal space everywhere (before, between, after)
Wrapping rows - children flow onto new lines as the container narrows.
Uses a cross-frame measurement pass so styled widgets (which egui's native
with_main_wrap can't wrap) participate correctly:
let mut tags = row.full_width.gap.wrap;
for tag in
tags.show;
Text effects
StyledLabel exposes glyph-level effects by stamping the laid-out text at
offsets and colors, so the effect follows the letterforms rather than a
bounding box.
Animation stays consumer-side: compute intensity, scale, or offset in your own state and pass the current value each frame.
// Drop shadow
label
.text_shadow
.text_color
.show;
// Chromatic aberration - two opposite shadows, one label
label
.text_shadow
.text_shadow
.text_color
.extend
.show;
// Faux stroke outline (8 compass-direction stamps)
label
.outline
.text_color
.show;
// Soft glow - intensity from 0.0 to 1.0
label
.glow
.text_color
.show;
Effects compose: a single label can carry glow, outline, multiple shadows, and scale simultaneously.
Glow is the most expensive text primitive - egui has no blur pass, so it's
approximated by stamping the text many times on a Vogel disk. The
default quality suits typical UI usage; tune with .glow_quality(n) if needed.
Gradients & glow
Box-level gradient fills, inner glows, and gradient borders are available on
every styled type, each with hover_ / active_ / focus_ state variants.
Gradients paint over the solid bg (like CSS background-image over
background-color) and respect corner_radius.
// Background gradients - 2-stop, 4-corner, or N-stop
frame.bg_gradient_v.show; // vertical
frame.bg_gradient_h.show; // horizontal
frame.bg_gradient.show; // 4 corners
frame
.bg_gradient_stops_h // N-stop / rainbow
.show;
// Inner glow - bright at the edge, fading inward (follows the corner radius)
button
.bg
.inner_glow
.hover_inner_glow
.border_gradient // vertically-interpolated border
.show;
// Per-side glow - top/bottom/left/right, or x / y / sides
frame.inner_glow_y.show; // top + bottom only
frame.inner_glow_left.show;
Background gradients bake into a small cached GPU texture (a 2×2 for corner
blends, a 256-texel ramp for N-stop), so keep gradient colors from a fixed
palette rather than animating them per frame. See examples/gradients.rs.
Images
egui_styled never loads or uploads textures itself. The app owns that part:
use ctx.load_texture, install URI loaders with
egui_extras::install_image_loaders, or use egui::include_image! for
compile-time bytes.
// Inline widget - icons, portraits, thumbnails
image
.size
.corner_radius
.border
.hover_tint
.shadow_filled
.show;
// Background texture behind children - same rounded-corner clipping as `bg`
area
.fill_screen
.background_image
.background_image_fit
.show;
Rounded-corner clipping uses the same textured shape path as egui's own
Frame, so background images and inline images respect corner_radius
correctly.
Widget support
| Widget | Status |
|---|---|
StyledButton |
✅ Full pseudo-state, shadow, padding, border |
StyledLabel |
✅ Font, color, effects, min-height, visibility |
StyledTextEdit |
✅ Hint, multiline, password, focus styling, padding, border |
StyledCheckbox |
✅ Full pseudo-state |
StyledSlider |
🚧 Partial - track/handle styling is shallow |
StyledComboBox |
🚧 Partial - trigger styled, popup items inherit |
StyledFrame |
✅ Full box model, background image, vertical justify, aspect ratio |
StyledRow / StyledColumn |
✅ Gap, alignment, box styling, distribution, wrapping |
StyledStack |
✅ Overlay layers, offsets, alignment, fixed-size layers |
StyledArea |
✅ Top-level positioned container, fill_screen, anchor |
StyledImage |
✅ Inline images, tint, hover tint, corner radius, border, shadow |
StyledSpacer |
✅ Flex spacer |
background_image |
✅ On box containers: stretch or cover fit, fade-in, tint |
Limitations
Things that are intentionally out of scope or not yet solved:
- Immediate-mode constraints still apply. Features that need multi-pass measurement - distribution, wrapping, vertical justify - use an invisible measurement frame and settle on the next repaint.
- Pseudo-state tracking has a 1-frame lag. State is written to
egui::Memoryat the end of each frame and read at the start of the next. In practice this matches egui's frame-based interaction model and is not noticeable. - Interactive widgets inside translated stacks are not reliable.
StyledStackpaints visually in the right place, but hit-testing still uses the untranslated rect. StyledSliderandStyledComboBoxare not deeply styleable yet. Trigger-level styling works; deeper internals are still limited.- Not a CSS or flexbox engine. Percentage sizing, wrapping, and distribution are implemented as egui-friendly utilities, not a constraint solver.
- Not a retained widget system.
- Not an accessibility framework. It can style focus states, but it does not add semantic roles or screen-reader support.
Performance
egui_styled adds a small per-widget overhead on top of raw egui:
- 1
ui.scope- - 2
egui::Memorylookups for pseudo-state load/store - 1
SharedStyle::resolve - A
Visualsclone, a childUiallocation, occasional short-lived strings for font override paths
For ordinary tool UIs this is usually fine. Profile if you render very large numbers of styled widgets per frame.
Text glow is the most expensive primitive - it stamps the glyph run many
times. Lower .glow_quality(n) if you render lots of glowing labels
simultaneously.
Distribution and wrapping rows add a measurement frame on first render, then settle. After that their steady-state overhead is similar to other styled containers.
Testing
Visual regression tests use egui_kittest.
Baselines live in tests/snapshots/.
Examples
Status
Pre-1.0. The API is functional and covered by examples and tests, but not yet tested in large production apps. Expect breaking changes between minor versions until 1.0.
Feedback and bug reports are welcome - open an issue.
License
MIT or Apache-2.0, at your option.