egui_material3/
lib.rs

1//! # egui-material3
2//! 
3//! A comprehensive Material Design 3 component library for [egui](https://github.com/emilk/egui), 
4//! providing a complete set of Material Design components with advanced theming support.
5//!
6//! ## Features
7//!
8//! - **Complete Material Design 3 Components**: Buttons, checkboxes, sliders, dialogs, data tables, and more
9//! - **Advanced Theming System**: Support for light/dark modes, contrast levels, and custom Material Design themes
10//! - **Build-time Theme Inclusion**: Automatically include theme JSON files at compile time for optimal performance
11//! - **Runtime Theme Loading**: Load and switch themes dynamically at runtime
12//! - **Material Design Icons**: Full support for Material Symbols with built-in icon font loading
13//! - **Responsive Design**: Components adapt to different screen sizes and orientations
14//!
15//! ## Quick Start
16//!
17//! Add this to your `Cargo.toml`:
18//! ```bash
19//! $ cargo add egui-material3
20//! ```
21//!
22//! ### Basic Usage
23//! 
24//! ```rust,no_run
25//! use eframe::egui;
26//! use egui_material3::{
27//!     MaterialButton, MaterialCheckbox, MaterialSlider,
28//!     theme::{setup_google_fonts, setup_local_fonts, setup_local_theme, 
29//!            load_fonts, load_themes, update_window_background}
30//! };
31//!
32//! fn main() -> Result<(), eframe::Error> {
33//!     let options = eframe::NativeOptions {
34//!         viewport: egui::ViewportBuilder::default().with_inner_size([800.0, 600.0]),
35//!         ..Default::default()
36//!     };
37//!     
38//!     eframe::run_native(
39//!         "Material Design App",
40//!         options,
41//!         Box::new(|cc| {
42//!             // Setup Material Design fonts and themes
43//!             setup_google_fonts(Some("Roboto"));
44//!             setup_local_fonts(Some("resources/MaterialSymbolsOutlined.ttf"));
45//!             setup_local_theme(None); // Use default theme
46//!             
47//!             // Load fonts and themes
48//!             load_fonts(&cc.egui_ctx);
49//!             load_themes();
50//!             
51//!             // Apply theme background
52//!             update_window_background(&cc.egui_ctx);
53//!             
54//!             Ok(Box::<MyApp>::default())
55//!         }),
56//!     )
57//! }
58//!
59//! #[derive(Default)]
60//! struct MyApp {
61//!     checked: bool,
62//!     slider_value: f32,
63//! }
64//!
65//! impl eframe::App for MyApp {
66//!     fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
67//!         egui::CentralPanel::default().show(ctx, |ui| {
68//!             ui.heading("Material Design Components");
69//!             
70//!             // Use Material Design components
71//!             ui.add(MaterialButton::new("Click me"));
72//!             ui.add(MaterialCheckbox::new(&mut self.checked, "Check me"));
73//!             ui.add(MaterialSlider::new(&mut self.slider_value, 0.0..=100.0));
74//!         });
75//!     }
76//! }
77//! ```
78//!
79//! ## Theme System
80//!
81//! The theme system supports Material Design 3 with comprehensive theming capabilities:
82//!
83//! ### Build-time Theme Inclusion
84//! 
85//! Themes can be automatically included at build time from JSON files:
86//! 
87//! ```rust,no_run
88//! use egui_material3::theme::{setup_local_theme, load_themes};
89//! 
90//! // Uses themes from resources/ and examples/ directories automatically
91//! setup_local_theme(None); 
92//! load_themes();
93//! ```
94//!
95//! ### Runtime Theme Loading
96//!
97//! Load custom themes dynamically:
98//!
99//! ```rust,no_run
100//! use egui_material3::theme::{setup_local_theme, load_themes};
101//!
102//! // Load specific theme file
103//! setup_local_theme(Some("path/to/my-theme.json"));
104//! load_themes();
105//! ```
106//!
107//! ### Theme Modes and Contrast
108//!
109//! Support for multiple theme modes and contrast levels:
110//!
111//! ```rust,no_run
112//! use egui_material3::theme::{get_global_theme, update_window_background, ThemeMode, ContrastLevel};
113//!
114//! // Change theme mode at runtime
115//! if let Ok(mut theme) = get_global_theme().lock() {
116//!     theme.theme_mode = ThemeMode::Dark;
117//!     theme.contrast_level = ContrastLevel::High;
118//! }
119//! // Apply changes
120//! update_window_background(ctx);
121//! ```
122//!
123//! ## Available Components
124//!
125//! ### Basic Components
126//! - [`MaterialButton`] - Material Design buttons with multiple variants
127//! - [`MaterialCheckbox`] - Checkboxes following Material Design guidelines  
128//! - [`MaterialSlider`] - Sliders with Material Design styling
129//! - [`MaterialSwitch`] - Toggle switches
130//! - [`MaterialRadio`] - Radio button groups
131//! - [`MaterialSelect`] - Dropdown selection components
132//!
133//! ### Advanced Components
134//! - [`MaterialChip`] - Filter and action chips
135//! - [`MaterialCard2`] - Material Design cards
136//! - [`MaterialDialog`] - Modal dialogs and alerts
137//! - [`MaterialFab`] - Floating Action Buttons
138//! - [`MaterialProgress`] - Progress indicators and loading states
139//! - [`MaterialDataTable`] - Data tables with sorting and selection
140//!
141//! ### Navigation Components  
142//! - [`MaterialTabs`] - Tab navigation
143//! - [`MaterialDrawer`] - Navigation drawers
144//! - [`MaterialTopAppBar`] - App bars and toolbars
145//!
146//! ### Icons and Visual Elements
147//! - [`MaterialIcon`] - Material Design icons with font support
148//! - [`MaterialList`] - Lists following Material Design patterns
149//! - [`MaterialImageList`] - Image lists with online/offline support and smart caching
150//!
151//! ## Image Lists and OnDemand Feature
152//!
153//! The [`MaterialImageList`] component provides comprehensive image display capabilities:
154//!
155//! ```rust,no_run
156//! use egui_material3::image_list;
157//!
158//! // Local image files
159//! ui.add(image_list()
160//!     .columns(3)
161//!     .item_spacing(8.0)
162//!     .items_from_paths(glob::glob("resources/*.png")?));
163//!
164//! // Online images (requires 'ondemand' feature)
165//! ui.add(image_list()
166//!     .columns(4)
167//!     .item_spacing(8.0)
168//!     .items_from_urls(vec![
169//!         "https://example.com/image1.jpg".to_string(),
170//!         "https://example.com/image2.png".to_string(),
171//!     ]));
172//!
173//! // Embedded images from byte arrays
174//! ui.add(image_list()
175//!     .columns(2)
176//!     .item_spacing(8.0)
177//!     .items_from_bytes(vec![
178//!         include_bytes!("image1.png").to_vec(),
179//!         include_bytes!("image2.png").to_vec(),
180//!     ]));
181//! ```
182//!
183//! ### OnDemand Feature
184//!
185//! Enable the `ondemand` feature for online image support:
186//!
187//! ```toml
188//! [dependencies]
189//! egui-material3 = { version = "0.0.6", features = ["ondemand"] }
190//! ```
191//!
192//! Key capabilities:
193//! - **Smart caching**: Downloaded images are cached locally with correct file extensions
194//! - **Format detection**: Automatically detects PNG, JPEG, GIF, and WebP formats
195//! - **Efficient loading**: Images are downloaded once and reused from cache
196//! - **Performance optimized**: UI repaints only when new images are available
197//! - **Error handling**: Graceful fallback with visual indicators for failed loads
198//!
199//! ## Examples
200//!
201//! The crate includes comprehensive examples:
202//!
203//! - `widget_gallery_example` - Showcase of all Material components with theme switching
204//! - `nobel_prizes_example` - Real-world data table implementation
205//! - `stories` - Individual component showcase windows for detailed exploration
206//! - `package` - Standalone example with bundled resources and themes
207//! - `ondemand` - Image list demonstration with online/offline images and smart caching
208//!
209//! Run examples with:
210//! ```bash
211//! cargo run --example widget_gallery_example
212//! cargo run --example nobel_prizes_example
213//! cargo run --example stories
214//!
215//! # OnDemand example with online image support
216//! cd examples/ondemand && cargo run
217//!
218//! # Package example runs independently with its own Cargo.toml
219//! cd examples/package && cargo run
220//! ```
221//!
222//! ## Material Design Resources
223//!
224//! - [Material Design 3](https://m3.material.io/)
225//! - [Material Theme Builder](https://m3.material.io/theme-builder)
226//! - [Material Design Icons](https://fonts.google.com/icons)
227//!
228//! This crate follows the Material Design 3 specifications and guidelines for consistent,
229//! accessible, and beautiful user interfaces.
230
231pub mod icons;
232pub mod image_utils;
233pub mod button;
234pub mod checkbox;
235pub mod chips;
236pub mod dialog;
237pub mod fab;
238pub mod icon;
239pub mod iconbutton;
240pub mod list;
241pub mod menu;
242pub mod progress;
243pub mod radio;
244pub mod select;
245pub mod slider;
246pub mod switch;
247pub mod tabs;
248pub mod datatable;
249pub mod drawer;
250pub mod imagelist;
251pub mod layoutgrid;
252pub mod snackbar;
253pub mod topappbar;
254pub mod card2;
255pub mod theme;
256
257pub use {
258    button::{MaterialButton, MaterialButtonVariant},
259    checkbox::{MaterialCheckbox, checkbox},
260    chips::{MaterialChip, ChipVariant, assist_chip, filter_chip, input_chip, suggestion_chip},
261    dialog::{MaterialDialog, dialog},
262    fab::{MaterialFab, FabVariant, FabSize, SvgIcon, SvgPath, fab_surface, fab_primary, fab_secondary, fab_tertiary, fab_branded, google_branded_icon},
263    icon::{MaterialIcon, icon},
264    iconbutton::{MaterialIconButton, IconButtonVariant, icon_button_standard, icon_button_filled, icon_button_filled_tonal, icon_button_outlined, icon_button_toggle},
265    list::{MaterialList, ListItem, list, list_item},
266    menu::{MaterialMenu, MenuItem, Corner, FocusState, Positioning, menu, menu_item},
267    progress::{MaterialProgress, ProgressVariant, linear_progress, circular_progress},
268    radio::{MaterialRadio, MaterialRadioGroup, radio, radio_group},
269    select::{MaterialSelect, select},
270    slider::{MaterialSlider, slider},
271    switch::{MaterialSwitch, switch},
272    tabs::{MaterialTabs, TabVariant, tabs_primary, tabs_secondary},
273    datatable::{MaterialDataTable, DataTableColumn, DataTableRow, SortDirection, data_table},
274    drawer::{MaterialDrawer, DrawerVariant, DrawerItem, permanent_drawer, modal_drawer, dismissible_drawer, standard_drawer},
275    imagelist::{MaterialImageList, ImageListVariant, ImageListItem, image_list, masonry_image_list, woven_image_list},
276    layoutgrid::{MaterialLayoutGrid, layout_grid, debug_layout_grid},
277    snackbar::{MaterialSnackbar, SnackbarPosition, snackbar, snackbar_with_action},
278    topappbar::{MaterialTopAppBar, TopAppBarVariant, top_app_bar, center_aligned_top_app_bar, medium_top_app_bar, large_top_app_bar},
279    card2::{MaterialCard2, Card2Variant, elevated_card2, filled_card2, outlined_card2},
280    theme::{get_global_color, get_global_theme, update_global_theme, MaterialThemeContext, ThemeMode, ContrastLevel, MaterialThemeFile},
281    egui::TextEdit, // Re-export egui's TextEdit
282};