egui_inspect/lib.rs
1//! # egui_inspect
2//! This crate expose macros and traits to generate boilerplate code
3//! for structs inspection and edition.
4//!
5//! Basic usage would be
6//! ```
7//! # use egui_inspect::*;
8//! #[derive(EguiInspect)]
9//! struct MyApp {
10//! #[inspect(no_edit)]
11//! string: String,
12//! #[inspect(multiline)]
13//! code: String,
14//! #[inspect(min = 12.0, max = 53.0)]
15//! unsigned32: u32,
16//! #[inspect(hide)]
17//! skipped: bool,
18//! #[inspect(custom_func_mut = "custom_bool_inspect")]
19//! boolean: bool,
20//! #[inspect(no_edit)]
21//! raw_string: &'static str,
22//! #[inspect(slider, min = -43.0, max = 125.0)]
23//! float64: f32,
24//! }
25//!
26//! fn custom_bool_inspect(boolean: &mut bool, label: &'static str, ui: &mut egui::Ui) {
27//! ui.label("C'EST LA GIGA FONCTION CUSTOM WÉ");
28//! boolean.inspect(label, ui);
29//! }
30//!
31//! fn main() {
32//! let app = MyApp::default();
33//! app.inspect("My App", &ui); // here `ui` would be some `&mut egui::Ui`
34//! }
35//! ```
36//!
37//! You can add attributes to structures field.
38//! Currently supported attributes are defined in the struct AttributeArgs of egui_inspect_derive
39//!
40//! Here is a list of supported attributes.
41//! It might not be up to date, it's better to check directly AttributeArgs declaration
42//!
43//! - `hide` *(bool)*: If true, doesn't generate code for the given field
44//! - `no_edit` *(bool)*: If true, never call mut function for the given field (May be overridden by other params)
45//! - `slider` *(bool)*: If true, use a slider when inspecting numbers (`mut` only)
46//! - `min` *(f32)*: Min value for inspecting numbers (`mut` only)
47//! - `max` *(f32)*: Max value for inspecting numbers (`mut` only)
48//! - `multiline` *(bool)*: If true, display the text on multiple lines (`mut` only)
49//! - `custom_func` *(string)*: Use custom function for non-mut inspect (Evaluate the string as a function path)
50//! - `custom_func_mut` *(string)*: Use custom function for mut inspect (Evaluate the string as a function path)
51//!
52
53/// See also [EguiInspect]
54pub use egui_inspect_derive::*;
55
56/// Base trait to automatically inspect structs
57pub trait EguiInspect {
58 fn inspect(&self, label: &'static str, ui: &mut egui::Ui);
59 fn inspect_mut(&mut self, label: &'static str, ui: &mut egui::Ui);
60}
61
62pub trait InspectNumber {
63 fn inspect_with_slider(&mut self, label: &'static str, ui: &mut egui::Ui, min: f32, max: f32);
64 fn inspect_with_drag_value(&mut self, label: &'static str, ui: &mut egui::Ui);
65}
66
67pub trait InspectString {
68 fn inspect_mut_multiline(&mut self, label: &'static str, ui: &mut egui::Ui);
69 fn inspect_mut_singleline(&mut self, label: &'static str, ui: &mut egui::Ui);
70}
71
72pub mod base_type_inspect;