{"id":16752804,"url":"https://github.com/aalekhpatel07/egui-controls","last_synced_at":"2025-04-10T15:53:04.194Z","repository":{"id":183645659,"uuid":"657889198","full_name":"aalekhpatel07/egui-controls","owner":"aalekhpatel07","description":"Derive a simple control panel interface for your data using eframe::egui","archived":false,"fork":false,"pushed_at":"2023-06-26T13:06:05.000Z","size":44,"stargazers_count":8,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-06T18:54:00.702Z","etag":null,"topics":["control-panel","eframe","egui","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aalekhpatel07.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-24T05:54:07.000Z","updated_at":"2025-03-03T01:41:01.000Z","dependencies_parsed_at":null,"dependency_job_id":"e8134865-b4bb-4390-9abd-f55ee012fa73","html_url":"https://github.com/aalekhpatel07/egui-controls","commit_stats":null,"previous_names":["aalekhpatel07/egui-controls"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aalekhpatel07%2Fegui-controls","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aalekhpatel07%2Fegui-controls/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aalekhpatel07%2Fegui-controls/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aalekhpatel07%2Fegui-controls/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aalekhpatel07","download_url":"https://codeload.github.com/aalekhpatel07/egui-controls/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248245649,"owners_count":21071533,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["control-panel","eframe","egui","rust"],"created_at":"2024-10-13T02:48:10.197Z","updated_at":"2025-04-10T15:53:04.172Z","avatar_url":"https://github.com/aalekhpatel07.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# egui-controls\n\n`egui-controls` is a Rust library that provides a `ControlPanel` proc-macro to generate a simple control panel interface using the [egui](https://github.com/emilk/egui) immediate mode graphical user interface library.\n\n## Motivation\nYou're implementing a Rust algorithm that has various tunable parameters, and would like to inspect the output by\ntweaking the parameters in real-time.\n\n## Usage\n\n```sh\ncargo add egui-controls\n```\n\n## Example\n\nSuppose your typical config data that contains the parameters for the algorithm looks like this:\n\n```rust\n#[derive(Debug, Clone)]\npub struct CirclePackingAlgorithmConfig {\n    /// The radius of the circles to pack.\n    pub radius: f64,\n    /// If circles overlap, then how many should be allowed \n    /// to overlap at most.\n    pub max_overlap_count: usize,\n    /// Once we find the circles, label them with the\n    /// given name.\n    pub circle_label: String,\n    /// Some global constant that should definitely only take on this value.\n    pub non_changing_global_value: i8\n}\n\n/// Some initial values for the config that make sense.\nimpl Default for CirclePackingAlgorithmConfig {\n    fn default() -\u003e Self {\n        Self {\n            radius: 12.0,\n            max_overlap_count: 10,\n            circle_label: \"Some text\".to_string(),\n            non_changing_global_value: 42\n        }\n    }\n}\n```\n\nNow, just derive [egui_controls::ControlPanel](https://github.com/aalekhpatel07/egui-controls/blob/main/src/lib.rs) for your data, and\nsprinkle in some `#[control]` attributes on the fields you'd like to be interactive in the UI:\n```diff\n+ use egui_controls::ControlPanel;\n\n- #[derive(Debug, Clone)]\n+ #[derive(Debug, Clone, ControlPanel)]\npub struct CirclePackingAlgorithmConfig {\n    /// The radius of the circles to pack.\n+   #[control(slider(2. ..= 15.0))]\n    pub radius: f64,\n    /// If circles overlap, then how many should be allowed \n    /// to overlap at most.\n+   #[control(slider(0 ..= 20))]\n    pub max_overlap_count: usize,\n    /// Once we find the circles, label them with the\n    /// given name.\n+   #[control(textbox)]\n    pub circle_label: String,\n    /// Some global constant that should definitely only take on this value.\n    pub non_changing_global_value: i8\n}\n```\nNow, use `config.ui(ui)` to embed that in any UI section you're building with `eframe::egui`.\n```rust\nuse eframe::{egui, Frame};\n\n#[derive(Debug, Clone, Default)]\npub struct MyApp {\n    settings: CirclePackingAlgorithmConfig\n}\n\nimpl eframe::App for MyApp {\n    fn update(\u0026mut self, ctx: \u0026egui::Context, _frame: \u0026mut Frame) {\n        egui::CentralPanel::default().show(ctx, |ui: \u0026mut egui::Ui| {\n            // Embed the settings panel\n            // directly into your ui.\n            self.settings.ui(ui);\n            // Add this the struct's debug repr if you want\n            // to see the values getting updated as you tweak\n            // the settings via the ui.\n            ui.vertical(|ui| {\n                ui.code(format!(\"{:#?}\", \u0026self.settings));\n            });\n        });\n    }\n}\n\n// Write the usual eframe entrypoint.\npub fn main() {\n    let options = ::eframe::NativeOptions {\n        resizable: true,\n        initial_window_size: Some(::eframe::egui::vec2(2000.0, 500.0)),\n        ..Default::default()\n    };\n    let app = MyApp::default();\n    ::eframe::run_native(\"readme\", options, Box::new(|_| Box::new(app))).unwrap();\n}\n```\n## Output\n\nThis generates a simple control panel interface for the `CirclePackingAlgorithmConfig`\nand we can tune the values via the sliders.\n\nNote: You can run the `readme` example to generate the same output.\n\n\u003cimg src=\"docs/example_screenshot.png\" title=\"Control Panel interface generated for CirclePackingAlgorithmConfig\" width=\"745\" alt=\"The Control Panel interface generated for CirclePackingAlgorithmConfig.\"/\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faalekhpatel07%2Fegui-controls","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faalekhpatel07%2Fegui-controls","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faalekhpatel07%2Fegui-controls/lists"}