MCPcopy Index your code
hub / github.com/PingPongun/egui_struct

github.com/PingPongun/egui_struct @v0.4.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.4.2 ↗ · + Follow
53 symbols 84 edges 5 files 4 documented · 8% updated 20mo ago★ 332 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

EguiStruct

crates.io Documentation MIT

EguiStruct is a rust derive macro that creates egui UI's from arbitrary structs and enums. This is useful for generating data bindings that can be modified and displayed in an egui ui.

Crate idea is similar to crates egui-probe, enum2egui, egui_inspect and egui-controls, but there are some important differences:

EguiStruct vs similar crates

EguiStruct egui-probe enum2egui egui_inspect egui-controls
egui version 0.26 (0.21-0.28) **** 0.27/0.28 0.23/0.24.1/0.26 0.20 N/A
Layout* Grid Grid Group/nested Nested Grid
i18n support ✅ (rust-i18n**)
Field description ✅ on hover hint (from attribute) ✅ third column (from doc comment)
Rename field/variant ✅/❌ (enum only)
Mass name case conversion
Callback on-change
Reset button
Skip field
Numerics & strings support
Vec support ✅/❌ (does not support adding/removing elements) ✅ std, smallvec1/2
Other support ✅ bool, Option, [T;N] ✅ bool, Option, [T;N], some of egui types ✅ bool, Option ✅ bool, [T;N]
HashMap/Set support ✅ std, indexmap ✅ std, hashbrown ✅ std, hashbrown
Map field/override impl
Struct derive
Enum derive
Custom types in derive
Configuration numerics ✅ Slider(min,max), Slider(min,max,step), DragValue(min,max), DragValue, List ✅ DragValue(min,max), DragValue ✅ Slider(min,max), DragValue
Configuration string ✅ multi/singleline, List ✅ multi/singleline ✅ multi/singleline
Configuration user types
Configuration others ✅ Color32, bool, Enum(combobox or inline buttons), sets/vecs/maps
List/Combobox wrapper ✅ ***

* Everything is put inside scroll&grid layout (with collapsable rows)

  • Gui is less chaotic,
  • all values are aligned,
  • Gui is comact in width

** integrated/with i18n in mind (with rust-i18n crate (or if using extractor modified rust-i18n))

*** Wrap T: Clone + ToString + PartialEq type into Combobox<T> and pass through config attribute iterator with all possible values → field will be shown as combobox

**** See section Usage >> egui version (EguiStruct supports all versions of egui through features; other crates support only "newest" one, support for other is by using legacy version)

Usage

Basic description

Add egui_struct to your Cargo.toml:

egui_struct = "0.4"

Add derive macro EguiStruct to struct you want to show (and all nested types):

#[derive(EguiStruct)]
pub struct TupleStruct(u8, u32, String, SubData);

then to show data, you only need to call show_top(..) on top level struct:

egui::CentralPanel::default().show(ctx, |ui| {
  data.show_top(ui, RichText::new("Data").heading(), None);
});

Detailed description

See docs.

Example

See ./demo

obraz

egui version

egui_struct 0.4 by default depends on egui 0.26. To use other versions of egui use correct feature in Cargo.toml, eg. to make it work with egui 0.28:

egui_struct = { version = "0.4", default-features = false, features = [ "egui28" ] }

OR use [patch] section.

Default egui version feature will be updated to newest egui on semver minor release(0.5).

TODO

  • elegant error/invalid input handling & helpful messages (macro)
  • add bounds
  • tests
  • code cleanup & simplify
  • support adding/removing elements for Vec&Hashmap's
  • (requires specialization) EguiStructEq/EguiStructClone default impl

Extension points exported contracts — how you extend this code

EguiStructImut (Interface)
Trait, that allows generating immutable view of data (takes `&data`) [5 implementers]
src/lib.rs
EguiStruct (Interface)
Trait, that allows generating mutable view of data (takes `&mut data`) For end user (if you implement trait with macro [4 …
src/lib.rs
EguiStructClone (Interface)
Similar to std [`Clone`] trait, but they respect `#[eguis(skip)]`. Necessary to implement [`EguiStruct`]. Used to provi [2 …
src/lib.rs
EguiStructEq (Interface)
Similar to std [`PartialEq`] trait, but they respect `#[eguis(skip)]`. Necessary to implement [`EguiStruct`]. Used to p [2 …
src/lib.rs

Core symbols most depended-on inside this repo

clone
called by 41
src/lib.rs
get_config
called by 6
macros/src/lib.rs
handle_fields
called by 3
macros/src/lib.rs
mask
called by 2
macros/src/lib.rs
egui_struct_inner
called by 2
macros/src/lib.rs
debug_print_generated
called by 2
macros/src/lib.rs
show_combobox
called by 2
src/lib.rs
handle_enum
called by 1
macros/src/lib.rs

Shape

Method 22
Function 12
Class 9
Enum 6
Interface 4

Languages

Rust100%

Modules by API surface

src/lib.rs27 symbols
macros/src/lib.rs14 symbols
demo/src/app.rs10 symbols
demo/src/main.rs1 symbols
demo/build.rs1 symbols

For agents

$ claude mcp add egui_struct \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page