Skip to main content

egui_elements/
lib.rs

1//! Widgets, themes, and optional components for [egui](https://github.com/emilk/egui).
2//!
3//! This crate is **not** a drop-in replacement for stock egui widgets. It
4//! ships a themed widget set, a palette of built-in looks, a live theme
5//! editor, and a few higher-level components (credentials form, QR image,
6//! Linux/Windows QR scanner).
7//!
8//! # Quick start
9//!
10//! ```no_run
11//! use egui::{Context, Ui};
12//! use egui_elements::{Theme, ThemeKind};
13//! use egui_elements::Button;
14//!
15//! fn ui(ctx: &Context, ui: &mut Ui) {
16//!     let mut theme = Theme::new(ThemeKind::TokyoNight);
17//!     theme.install(ctx);
18//!
19//!     if ui.add(Button::new("Save")).clicked() {
20//!         // …
21//!     }
22//! }
23//! ```
24//!
25//! Custom widgets pick up [`visuals`] from the installed
26//! [`Theme`](crate::theme::Theme). You can still override a single widget
27//! with `.visuals(...)`.
28//!
29//! # Modules
30//!
31//! - [`theme`] / [`themes`] — palettes, [`ThemeKind`](crate::theme::ThemeKind), install
32//! - [`widgets`] — [`Button`](crate::widgets::Button) (with
33//!   [`HoldSettings`](crate::widgets::HoldSettings) for configurable hold-to-confirm
34//!   fills and completion bursts), [`Label`](crate::widgets::Label)
35//!   (including [`Label::sections`](crate::widgets::Label::sections) for mixed styles),
36//!   [`ComboBox`](crate::widgets::ComboBox), [`Modal`](crate::widgets::Modal),
37//!   [`SecureTextEdit`](crate::widgets::SecureTextEdit), [`MultiLabel`](crate::widgets::MultiLabel),
38//!   [`Window`](crate::widgets::Window)
39//! - [`widgets::particles`] — [`Snow`](crate::widgets::particles::Snow),
40//!   [`Light`](crate::widgets::particles::Light) and
41//!   [`Lightning`](crate::widgets::particles::Lightning) with themed
42//!   [`SnowSettings`](crate::widgets::particles::SnowSettings) /
43//!   [`LightSettings`](crate::widgets::particles::LightSettings) /
44//!   [`LightningSettings`](crate::widgets::particles::LightningSettings) windows
45//! - [`components`] — feature-gated composites (`secure-types`, `qr-image`, `qr-scanner`)
46//! - [`editor`] — live [`ThemeEditor`](crate::editor::ThemeEditor)
47//! - [`utils`] — [`theme_switcher`](crate::utils::theme_switcher), HSLA helpers
48//! - [`overlay`] — dimming overlay for stacked windows
49//! - [`visuals`] — per-widget chrome (`ButtonVisuals`, `TextEditVisuals`, …)
50//!
51//! # Features
52//!
53//! | Feature | What it enables |
54//! |---------|-----------------|
55//! | `serde` | `Serialize` / `Deserialize` on theme types; `egui/serde` |
56//! | `lucide` | [`egui-lucide`](https://docs.rs/egui-lucide) SVG icons. Also enabled by `secure-types` and `qr-scanner`. |
57//! | `secure-types` | [`SecureString`](https://docs.rs/secure-types) buffers, credentials form, virtual keyboard |
58//! | `qr-image` | Encode a string as a QR [`Image`](egui::Image) |
59//! | `qr-scanner` | Linux/Windows screen-capture QR scanner (`xcap` + `rqrr-zeroize`) |
60//! | `elegance` | Push the current palette into [`egui-elegance`](https://docs.rs/egui-elegance) |
61//! | `full` | All of the above |
62//!
63//! Run the showcase with:
64//!
65//! ```text
66//! cargo run --example demo --features full
67//! ```
68//!
69//! See the crate README for system packages required by `qr-scanner`.
70//!
71//! [`ComboBox`](crate::widgets::ComboBox) and [`Window`](crate::widgets::Window) have
72//! the same names as [`egui::ComboBox`] and [`egui::Window`]. Import this crate's
73//! widgets after `use egui::*`, or alias one of them.
74
75mod glow;
76
77pub mod components;
78pub mod editor;
79pub mod theme;
80pub mod themes;
81pub mod utils;
82pub mod visuals;
83pub mod widgets;
84
85pub use theme::{Theme, ThemeKind};
86pub use widgets::{
87   Badge, BadgeCorner, Button, ComboBox, Frame, HoldBurst, HoldSettings, Label, Light, LightMotion,
88   LightSettings, Lightning, LightningSettings, Modal, MultiLabel, ParticleLayer, Snow,
89   SnowSettings, Window,
90};
91
92#[cfg(feature = "secure-types")]
93pub use widgets::SecureTextEdit;
94
95#[cfg(any(feature = "secure-types", feature = "lucide"))]
96pub use egui_lucide;
97
98#[cfg(all(
99   feature = "qr-scanner",
100   any(target_os = "linux", target_os = "windows")
101))]
102pub use components::QRScanner;
103
104#[cfg(feature = "secure-types")]
105pub use components::{CredentialsForm, InputField, SecureInputField, VirtualKeyboard};
106
107#[cfg(feature = "qr-image")]
108pub use components::QrImage;