Crate egui_field_editor

Source
Expand description

This crate expose macros and traits to generate boilerplate code for structs inspection and edition.

Basic usage would be:

use egui_field_editor::{EguiInspect, EguiInspector};
use eframe::egui;
 
#[derive(EguiInspect, Default)]
struct MyApp {
    #[inspect(read_only)]
    string: String,
    #[inspect(multiline)]
    code: String,
    #[inspect(range(min = 12.0, max = 53.0))]
    unsigned32: u32,
    #[inspect(hidden)]
    #[allow(dead_code)]
    skipped: bool,
    #[inspect(tooltip = "A boolean")]
    boolean: bool,
    raw_string: &'static str,
    #[inspect(slider(min = "-43.0", max = 125.0))]
    float64: f32,
    #[inspect(name = "A proper field name")]
    ugly_internal_field_name: u16,
}
 
impl eframe::App for MyApp {
    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
        egui::CentralPanel::default().show(ctx, |ui| {
            ui.add(EguiInspector::new(self));
        });
    }
}
 
fn main() {
    let options = eframe::NativeOptions::default();
    let _ = eframe::run_native("EGui Inspector Very Simple Example", options, 
        Box::new(|_cc|
            Ok(Box::new(MyApp {
                raw_string:"A raw string which is not editable, even is read_only=false",
                string: "A read only string".to_string(),
                ..Default::default()
            }))
        )
    );
}

You can add attributes to structures field.

Currently supported attributes are defined in the struct AttributeArgs of egui_field_editor_derive

Here is a list of supported attributes:

  • name (String): Use custom label for the given field instead of the internal field name

  • hidden (bool): If true, doesn’t generate code for the given field

  • read_only (bool): If true, the field is not editable (and color is grayed)

  • slider (min=f32, max=f32): If present, use a slider when inspecting numbers

  • range (min=f32, max=f32): Min/Max value for inspecting numbers

  • multiline (optional u8): If set, display the text on multiple lines. If affected to a u8, it defines the number of rows to display

  • tooltip (String): Tooltip to display when cursor is hover

  • color (bool): Display the field has a color (field type needs to implement From<Color32Wrapper>/Into<Color32Wrapper> - see Color32Wrapper)

  • custom_fn (String): Use a custom function instead of calling EguiInspect::inspect_with_custom_id

  • from_string: (bool): Force edition from string conversion (needs type to implement FromStr and Display)

    Compatible with multiline.`

  • date (DatePickerParams): Parameters to customize the Date Picker widget:

    • combo_boxes: (optional bool) Show combo boxes in date picker popup. (Default: true).

    • arrows: (optional bool) Show arrows in date picker popup. (Default: true).

    • calendar: (optional bool) Show calendar in date picker popup. (Default: true).

    • calendar_week: (optional bool) Show calendar week in date picker popup. (Default: true).

    • show_icon: (optional bool) Show the calendar icon on the button. (Default: true).

    • format: String Change the format shown on the button. (Default: "%Y-%m-%d").

      See chrono::format::strftime for valid formats.

    • highlight_weekends: (optional bool). Highlight weekend days. (Default: true)

    • start_end_years: (min = String|i32, max = String|i32):

      Set the start and end years for the date picker. (Default: today’s year - 100 to today’s year + 10)

      This will limit the years you can choose from in the dropdown to the specified range.

      For example, if you want to provide the range of years from 2000 to 2035, you can use: start_end_years(min=2000, max=2035).

§Feature Flags

This crate provides optional features to extend functionality with external libraries. You can enable them selectively to reduce compile time and dependency footprint.

  • nalgebra_glm: Enables support for inspecting nalgebra-glm types like Vec3, Vec4, etc.

    This adds a dependency to nalgebra-glm.

  • datepicker: Enables date picker UI using chrono and egui_extras.

    This adds a dependency to egui_extras datepicker feature and to chrono.

  • all: A shortcut to activate all features.

§Default Features

No features are activated by default.

default = []

Structs§

Color32Wrapper
An utility wrapper around egui::Color32.
EguiInspector
A wrapper widget that renders an object implementing EguiInspect inside an egui UI.

Traits§

EguiInspect
A trait for rendering custom UI inspectors using egui.

Functions§

add_bool
Adds a boolean checkbox.
add_button
Add a egui::Button
add_color
Adds a color picker for custom color types convertible to/from Color32Wrapper.
add_color32
Adds a color picker for egui::Color32.
add_combobox
Adds a egui::ComboBox to modify the index of chosed in the choices array.
add_custom_ui
Adds a custom field with layout and tooltip support.
add_date
Adds a date picker for date types.
add_dquat
Adds an editor for DQuat using egui::DragValue for each field.
add_dvec2
Adds an editor for DVec2 using egui::DragValue for each field.
add_dvec3
Adds an editor for DVec3 using egui::DragValue for each field.
add_dvec4
Adds an editor for DVec4 using egui::DragValue for each field.
add_mat2x2
Adds an editor for Mat2x2 using egui::DragValue for each field.
add_mat2x3
Adds an editor for Mat2x3 using egui::DragValue for each field.
add_mat2x4
Adds an editor for Mat2x4 using egui::DragValue for each field.
add_mat3x2
Adds an editor for Mat3x2 using egui::DragValue for each field.
add_mat3x3
Adds an editor for Mat3x3 using egui::DragValue for each field.
add_mat3x4
Adds an editor for Mat3x4 using egui::DragValue for each field.
add_mat4x2
Adds an editor for Mat4x2 using egui::DragValue for each field.
add_mat4x3
Adds an editor for Mat4x3 using egui::DragValue for each field.
add_mat4x4
Adds an editor for Mat4x4 using egui::DragValue for each field.
add_number
Adds a numeric drag field to the UI.
add_number_slider
Adds a numeric slider to the given egui UI.
add_path
Add a path (a singleline string editor) with a button next to it to open a file picker if the feature “filepicker” is active
add_quat
Adds an editor for Quat using egui::DragValue for each field.
add_string_convertible
Add a single line text field which use string conversions to edit.
add_string_convertible_multiline
Add a multiline line text field which use string conversions to edit.
add_string_multiline
Adds a multi-line text field with a specified number of visible lines.
add_string_singleline
Adds a single-line text field.
add_vec2
Adds an editor for Vec2 using egui::DragValue for each field.
add_vec3
Adds an editor for Vec3 using egui::DragValue for each field.
add_vec4
Adds an editor for Vec4 using egui::DragValue for each field.
add_vec2i8
Adds an editor for I8Vec2 using egui::DragValue for each field.
add_vec2i16
Adds an editor for I16Vec2 using egui::DragValue for each field.
add_vec2i32
Adds an editor for I32Vec2 using egui::DragValue for each field.
add_vec2i64
Adds an editor for I64Vec2 using egui::DragValue for each field.
add_vec2u8
Adds an editor for U8Vec2 using egui::DragValue for each field.
add_vec2u16
Adds an editor for U16Vec2 using egui::DragValue for each field.
add_vec2u32
Adds an editor for U32Vec2 using egui::DragValue for each field.
add_vec2u64
Adds an editor for U64Vec2 using egui::DragValue for each field.
add_vec3i8
Adds an editor for I8Vec3 using egui::DragValue for each field.
add_vec3i16
Adds an editor for I16Vec3 using egui::DragValue for each field.
add_vec3i32
Adds an editor for I32Vec3 using egui::DragValue for each field.
add_vec3i64
Adds an editor for I64Vec3 using egui::DragValue for each field.
add_vec3u8
Adds an editor for U8Vec3 using egui::DragValue for each field.
add_vec3u16
Adds an editor for U16Vec3 using egui::DragValue for each field.
add_vec3u32
Adds an editor for U32Vec3 using egui::DragValue for each field.
add_vec3u64
Adds an editor for U64Vec3 using egui::DragValue for each field.
add_vec4i8
Adds an editor for I8Vec4 using egui::DragValue for each field.
add_vec4i16
Adds an editor for I16Vec4 using egui::DragValue for each field.
add_vec4i32
Adds an editor for I32Vec4 using egui::DragValue for each field.
add_vec4i64
Adds an editor for I64Vec4 using egui::DragValue for each field.
add_vec4u8
Adds an editor for U8Vec4 using egui::DragValue for each field.
add_vec4u16
Adds an editor for U16Vec4 using egui::DragValue for each field.
add_vec4u32
Adds an editor for U32Vec4 using egui::DragValue for each field.
add_vec4u64
Adds an editor for U64Vec4 using egui::DragValue for each field.
add_widget
Adds a labeled widget to the UI with layout and tooltip support.

Derive Macros§

EguiInspect
See also EguiInspect