egui-controls
egui-controls
is a Rust library that provides a ControlPanel
proc-macro to generate a simple control panel interface using the egui immediate mode graphical user interface library.
Motivation
You're implementing a Rust algorithm that has various tunable parameters, and would like to inspect the output by tweaking the parameters in real-time.
Usage
Example
Suppose your typical config data that contains the parameters for the algorithm looks like this:
/// Some initial values for the config that make sense.
Now, just derive egui_controls::ControlPanel for your data, and
sprinkle in some #[control]
attributes on the fields you'd like to be interactive in the UI:
+ use egui_controls::ControlPanel;
- #[derive(Debug, Clone)]
+ #[derive(Debug, Clone, ControlPanel)]
pub struct CirclePackingAlgorithmConfig {
/// The radius of the circles to pack.
+ #[control(slider(2. ..= 15.0))]
pub radius: f64,
/// If circles overlap, then how many should be allowed
/// to overlap at most.
+ #[control(slider(0 ..= 20))]
pub max_overlap_count: usize,
/// Once we find the circles, label them with the
/// given name.
+ #[control(textbox)]
pub circle_label: String,
/// Some global constant that should definitely only take on this value.
pub non_changing_global_value: i8
}
Now, use config.ui(ui)
to embed that in any UI section you're building with eframe::egui
.
use ;
// Write the usual eframe entrypoint.
Output
This generates a simple control panel interface for the CirclePackingAlgorithmConfig
and we can tune the values via the sliders.
Note: You can run the readme
example to generate the same output.