Crates.io | egui-material3 |
lib.rs | egui-material3 |
version | 0.0.6 |
created_at | 2025-09-01 17:15:00.409807+00 |
updated_at | 2025-09-18 12:30:38.166022+00 |
description | Material Design 3 components for egui with comprehensive theming support |
homepage | https://github.com/nikescar/egui-material3 |
repository | https://github.com/nikescar/egui-material3 |
max_upload_size | |
id | 1819933 |
size | 1,339,242 |
A Material Design component library for egui, providing Material Design 3 components with theme support.
Add this to your Cargo.toml
:
$ cargo add egui-material3
use eframe::egui;
use egui_material3::{
MaterialButton, MaterialCheckbox, MaterialSlider,
theme::{setup_google_fonts, setup_local_fonts, setup_local_theme, load_fonts, load_themes, update_window_background}
};
fn main() -> Result<(), eframe::Error> {
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default().with_inner_size([800.0, 600.0]),
..Default::default()
};
eframe::run_native(
"Material Design App",
options,
Box::new(|cc| {
// Setup Material Design fonts and themes
setup_google_fonts(Some("Roboto"));
setup_local_fonts(Some("resources/MaterialSymbolsOutlined[FILL,GRAD,opsz,wght].ttf"));
setup_local_theme(Some("resources/my-theme.json")); // or None for default
// Load fonts and themes
load_fonts(&cc.egui_ctx);
load_themes();
// Apply theme background
update_window_background(&cc.egui_ctx);
Ok(Box::<MyApp>::default())
}),
)
}
#[derive(Default)]
struct MyApp {
text: String,
checked: bool,
slider_value: f32,
}
impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
ui.heading("Material Design Components");
// Material Design components
ui.add(MaterialButton::new("Click me"));
ui.add(MaterialCheckbox::new(&mut self.checked, "Check me"));
ui.add(MaterialSlider::new(&mut self.slider_value, 0.0..=100.0).text("Slider"));
});
}
}
The library supports Material Design 3 themes with:
The MaterialImageList
component supports multiple image sources with smart caching:
use egui_material3::image_list;
// Local image files
ui.add(image_list()
.columns(3)
.item_spacing(8.0)
.items_from_paths(glob::glob("resources/*.png")?));
// Online images (requires 'ondemand' feature)
ui.add(image_list()
.columns(4)
.item_spacing(8.0)
.items_from_urls(vec![
"https://example.com/image1.jpg".to_string(),
"https://example.com/image2.png".to_string(),
]));
// Embedded images from byte arrays
ui.add(image_list()
.columns(2)
.item_spacing(8.0)
.items_from_bytes(vec![
include_bytes!("image1.png").to_vec(),
include_bytes!("image2.png").to_vec(),
]));
Enable the ondemand
feature for online image support:
[dependencies]
egui-material3 = { version = "0.0.6", features = ["ondemand"] }
Features:
Look at the examples/
folder for complete examples:
main
- Main Window for all storieswidget_gallery_example.rs
- Showcase of all Material componentsnobel_prizes_example.rs
- Real-world data table exampleondemand
- Image list with online/offline images and caching demo