egui-elements
Themes, widgets, and components for egui.
The goal of this crate is to make it easy to create nice looking apps with egui.
egui-elements is far from perfect and there may be breaking changes to the color palettes as egui evolves.
This crate is not a drop-in replacement for stock egui widgets. It ships:
- A widget set (
Button,Label,ComboBox,SecureTextEdit,Modal,MultiLabel,Window) that reads visuals from an installed theme, and cornerBadgesfor buttons - Seven built-in palettes (
ThemeKind) plus a liveThemeEditor(WIP) - Feature-gated composites: credentials form, QR image, Linux QR scanner
There are no crate-root re-exports. Import from the modules:
use ;
use ;
use theme_switcher;
use ThemeEditor;
Button, ComboBox, and Window have the same names as the egui types. Import this crate's widgets after use eframe::egui::*, or alias one of them.
Installation
[]
= "0.1"
Enable only the features you need (see Features). For the showcase demo:
= { = "0.1", = ["full"] }
Quick start
use ;
use ;
use Button;
Theme::install writes the egui::Style and the per-widget visuals onto ctx. Custom widgets then pick them up automatically. You can still override a single widget with .visuals(...).
Always call Theme::install if you switch themes so egui sees the new look:
use ThemeEditor;
use ;
use theme_switcher;
Usage
Widgets
use ;
use ;
Give each ComboBox / SecureTextEdit a unique id_salt if you repeat the same gallery on several surfaces (bg, frame, window). Otherwise their persistent state collides.
Badges
Attach a notification Badge to a corner of a Button to signal unseen content
behind it - e.g. the number changes:
use ;
let changes = 3;
ui.add;
Badge::new(text) shows that text in the top-right corner, filled with the theme
error color; Badge::dot() is a plain coloured dot. .corner(BadgeCorner::TopLeft) /
TopRight / BottomLeft / BottomRight picks the corner, .color(...) and
.text_color(...) override the fill and glyph colors (text defaults to
theme.colors.bg so it stays readable on chromatic fills).
The badge is an overlay: it is painted on top of the button and never changes its size or layout.
Credentials form (secure-types)
Show/hide (and the QR-scan button) use Lucide SVG icons
via egui-lucide, colored with
theme.colors.text. Register egui's SVG loader once at startup:
install_image_loaders;
egui_extras needs the svg feature. The lucide feature is enabled
automatically by secure-types and qr-scanner.
use CredentialsForm;
let mut form = new
.with_open
.with_confirm_password;
form.show;
let username = form.username;
let password = form.password;
form.erase; // wipe the SecureString fields
QR image (qr-image)
Use a unique bytes://… URI per image so egui's loader cache does not reuse the wrong PNG.
use QrImage;
let qr = new;
if !qr.has_error
// When the image leaves the screen, forget it so the bytes can be wiped:
qr.clear;
QR scanner (qr-scanner, Linux and Windows)
use QRScanner;
let mut scanner = new;
scanner.open;
scanner.show;
if let Some = scanner.get_result
The scanner captures the monitor under the cursor via xcap and decodes with rqrr-zeroize (a fork of rqrr that wipes the prepared image buffer on drop). Exported on Linux and Windows, not macOS.
Where the pixels go:
- Linux X11 — in-memory (XCB). Prefer this for sensitive codes.
- Linux Wayland —
xcapasks GNOME Shell or the XDG desktop portal, which writes a PNG under the temp dir and then deletes it. That file exists for a brief moment. - Windows — in-memory GDI (
BitBlt/GetDIBits). No screenshot temp file. (This crate does not enable xcap’s optionalwgcfeature; that path is also in-memory.)
Features
| Feature | Default | What it enables |
|---|---|---|
serde |
Serialize / Deserialize on theme types, plus egui/serde |
|
lucide |
egui-lucide SVG icons (Eye / EyeOff / ScanQrCode). Also enabled by secure-types and qr-scanner. Host apps must call egui_extras::install_image_loaders with the svg feature. |
|
secure-types |
secure-types (SecureString) buffers; SecureInputField, CredentialsForm, VirtualKeyboard. Enables lucide. |
|
qr-image |
Encode a string as a PNG QR egui::Image (qrcodegen-no-heap + image) |
|
qr-scanner |
Linux/Windows screen-capture QR scanner (xcap + enigo + rqrr-zeroize). Also enables secure-types (the dependency) and lucide. The QRScanner type is exported on Linux and Windows. |
|
elegance |
Convert the current theme into egui-elegance so elegance widgets match the theme |
|
full |
All of the above |
Widgets, themes, the editor, and the overlay work with no features enabled.
QR scanner system dependencies
QR scanner uses the xcap crate. You may have to install the following dependencies:
Debian/Ubuntu:
Alpine:
Arch Linux:
If it still doesn't compile, try installing the following packages:
Demo
Capability gallery (palette, widgets, components):
Product-framed placeholder (mail client UI):
Built-in themes
ThemeKind |
Notes |
|---|---|
TokyoNight |
Dark. tokyo-night-vscode-theme |
TokyoNightLight |
Light variant of the same |
McLaren650Gts |
2015 McLaren 650S GT3 livery |
Reverie |
Reverie Obsidian theme |
ShadeSanctuary |
Shade Sanctuary |
Wasp |
Dark Wasp Obsidian theme |
WaspLight |
Light variant of the same |
Palette slot roles (bg vs widget_bg, hover vs highlight, …) are documented in docs/theme.md.
License
MIT. Icons from the lucide feature are Lucide (ISC).