enum2egui/lib.rs
1//! # enum2egui
2//!
3//! [<img alt="github" src="https://img.shields.io/badge/github-matthewjberger/enum2egui-8da0cb?style=for-the-badge&labelColor=555555&logo=github" height="20">](https://github.com/matthewjberger/enum2egui)
4//! [<img alt="crates.io" src="https://img.shields.io/crates/v/enum2egui.svg?style=for-the-badge&color=fc8d62&logo=rust" height="20">](https://crates.io/crates/enum2egui)
5//! [<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-enum2egui-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs" height="20">](https://docs.rs/enum2egui)
6//!
7//! `enum2egui` is a rust derive macro that creates egui UI's from arbitrary structs and enums.
8//! This is useful for generating data bindings that can be modified and displayed in an [egui](https://github.com/emilk/egui) ui.
9//!
10//! `Default` and `Display` are required. [enum2str](https://github.com/matthewjberger/enum2str) is recommended for deriving `Display` on enums.
11//!
12//! ## Usage
13//!
14//! Add this to your `Cargo.toml`:
15//!
16//! ```toml
17//! enum2egui = "0.3.8" # supports egui 0.29.1
18//! ```
19//!
20//! ### Example
21//!
22//! Declare your data:
23//!
24//! ```rust
25//! use enum2egui::{Gui, GuiInspect};
26//!
27//! #[derive(Gui, EnumStr, Debug, Clone, Default, serde::Deserialize, serde::Serialize, PartialEq)]
28//! pub enum Color {
29//! #[default]
30//! Red,
31//! Green,
32//!
33//! #[enum2str("Custom")]
34//! Custom(u8, u8, u8),
35//!
36//! NamedCustom {
37//! red: u8,
38//! blue: u8,
39//! green: u8,
40//! metadata: Metadata,
41//! },
42//!
43//! #[enum2egui(skip)]
44//! SkippedGreen,
45//!
46//! #[enum2egui(skip)]
47//! #[enum2str("Skipped Custom")]
48//! SkippedCustom(u8, u8, u8),
49//!
50//! }
51//!
52//! #[derive(Gui, Clone, serde::Deserialize, serde::Serialize, Default)]
53//! pub struct Data {
54//! string: String,
55//! i8: i8,
56//! i16: i16,
57//! i32: i32,
58//! i64: i64,
59//! bool: bool,
60//! u8: u8,
61//! u16: u16,
62//! u32: u32,
63//! f32: f32,
64//! f64: f64,
65//! nested_struct: SubData,
66//! unnamed_struct: TupleStruct,
67//! primary_color: Color,
68//! secondary_color: Color,
69//! optional: Option<SubData>,
70//! }
71//!
72//! #[derive(Gui, Clone, serde::Deserialize, serde::Serialize, PartialEq)]
73//! pub struct TupleStruct(u8, u32, String, SubData);
74//!
75//! impl Default for TupleStruct {
76//! fn default() -> Self {
77//! Self(3, 24, "Hello!".to_string(), SubData::default())
78//! }
79//! }
80//!
81//! #[derive(Gui, Clone, Default, serde::Deserialize, serde::Serialize, PartialEq, Debug)]
82//! pub struct Metadata {
83//! message: String,
84//! }
85//!
86//! #[derive(Gui, Clone, Default, serde::Deserialize, serde::Serialize, PartialEq)]
87//! pub struct SubData {
88//! value: String,
89//! number: u32,
90//! }
91//! ```
92//!
93//! Then render it with `GuiInspect::ui(..)` or `GuiInspect::ui_mut()`. For example, with `eframe`:
94//!
95//! ```rust
96//! impl eframe::App for DemoApp {
97//! fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
98//! let Self { data } = self;
99//!
100//! egui::CentralPanel::default().show(ctx, |ui| {
101//! // Read-Only UI
102//! data.ui(ui):
103//!
104//! // Mutable UI
105//! data.ui_mut(ui);
106//! });
107//! }
108//! }
109//! ```
110//!
111//! 
112mod gui;
113
114pub use self::gui::*;
115pub use egui;
116pub use enum2egui_derive::Gui;