{"id":20989911,"url":"https://github.com/iddm/imgui_presentable","last_synced_at":"2025-07-02T07:32:43.548Z","repository":{"id":208237849,"uuid":"721171058","full_name":"iddm/imgui_presentable","owner":"iddm","description":"An easy way for Rust types to be presented in Imgui","archived":false,"fork":false,"pushed_at":"2024-02-14T22:14:09.000Z","size":127,"stargazers_count":1,"open_issues_count":9,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-13T11:46:06.591Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iddm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"iddm"}},"created_at":"2023-11-20T13:58:09.000Z","updated_at":"2023-11-22T10:38:56.000Z","dependencies_parsed_at":"2024-11-19T06:41:34.622Z","dependency_job_id":null,"html_url":"https://github.com/iddm/imgui_presentable","commit_stats":null,"previous_names":["vityafx/imgui_presentable","iddm/imgui_presentable"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/iddm/imgui_presentable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iddm%2Fimgui_presentable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iddm%2Fimgui_presentable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iddm%2Fimgui_presentable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iddm%2Fimgui_presentable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iddm","download_url":"https://codeload.github.com/iddm/imgui_presentable/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iddm%2Fimgui_presentable/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263093814,"owners_count":23412881,"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":[],"created_at":"2024-11-19T06:26:41.679Z","updated_at":"2025-07-02T07:32:43.504Z","avatar_url":"https://github.com/iddm.png","language":"Rust","funding_links":["https://github.com/sponsors/iddm"],"categories":[],"sub_categories":[],"readme":"# Immediate Gui Presentable\n\n[![CI](https://github.com/iddm/imgui_presentable/actions/workflows/ci.yml/badge.svg)](https://github.com/iddm/imgui_presentable/actions/workflows/ci.yml)\n[![Crates](https://img.shields.io/crates/v/imgui_presentable.svg)](https://crates.io/crates/imgui_presentable)\n[![Docs](https://docs.rs/imgui_presentable/badge.svg)](https://docs.rs/imgui_presentable)\n[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)\n\nA derive-macro for easily showing your structs as a GUI component using\n[egui](https://github.com/emilk/egui) or [imgui-rs](https://github.com/imgui-rs/imgui-rs).\n\nThe name of this crate (imgui_presentable) may seem confusing and being\nonly limited to ImGui. Here, one may think of the name in the broad\nsense instead - \"Immediate Gui\", so that it is not limited to ImGui and\nnever should be. The goal of this crate is to implement all the backends\npossible, and preferrably hide all the implementation detail behind the\nderive-macro.\n\n## Example (using ImGui)\n\n```rust\n/// Describes a game scene.\n#[derive(Builder, Debug, Clone, serde::Serialize, serde::Deserialize, ImguiPresentation)]\n#[imgui_presentation(button(\"Reload from file\": \"reload\"))]\n#[imgui_presentation(button(\"Render\": \"reload_imgui\"))]\npub struct Scene {\n    #[builder(default)]\n    #[imgui_presentation(skip)]\n    magic_header: MagicHeader,\n    #[imgui_presentation(skip)]\n    id: uuid::Uuid,\n    /// Scene path.\n    #[imgui_presentation(skip)]\n    path: std::path::PathBuf,\n    /// Objects within this scene.\n    data: Data,\n    #[builder(default)]\n    physics_components: IndexedComponentsStorage\u003cPhysicsComponent\u003e,\n    #[builder(default)]\n    mesh_components: IndexedComponentsStorage\u003cMeshComponent\u003e,\n    #[builder(default)]\n    entities: HashSet\u003cEntity\u003e,\n    #[serde(skip)]\n    #[builder(default)]\n    entity_change_set: EntityChangeSet,\n    #[builder(default)]\n    farthest_object_distance: f32,\n}\n```\nDeriving the `ImguiPresentation` implements the following trait, namely overrides the `render_component` and `render_component_mut` where possible:\n\n```rust\n/// Allows the implementing object to be rendered as an ImGUI component.\npub trait ImguiPresentable {\n    /// Renders the implementor as a stand-alone window not allowing to\n    /// change the values.\n    fn render_window(\u0026self, ui: \u0026imgui::Ui, extent: Extent) {\n        ui.window(std::any::type_name::\u003cSelf\u003e())\n            .resizable(true)\n            .collapsible(true)\n            .position([0.0, 0.0], imgui::Condition::FirstUseEver)\n            .build(|| self.render_component(ui, extent));\n    }\n\n    /// Renders the implementor as a sub-component not allowing to\n    /// change the values.\n    fn render_component(\u0026self, ui: \u0026imgui::Ui, extent: Extent);\n\n    /// Renders the implementor as a stand-alone window allowing to\n    /// change the values.\n    fn render_window_mut(\u0026mut self, ui: \u0026imgui::Ui, extent: Extent) {\n        ui.window(std::any::type_name::\u003cSelf\u003e())\n            .resizable(true)\n            .collapsible(true)\n            .position([0.0, 0.0], imgui::Condition::FirstUseEver)\n            .build(|| self.render_component_mut(ui, extent));\n    }\n\n    /// Renders the implementor as a sub-component allowing to change\n    /// the values.\n    ///\n    /// # Note\n    ///\n    /// If not re-implemented, the default implementation shows the\n    /// immutable UI.\n    fn render_component_mut(\u0026mut self, ui: \u0026imgui::Ui, extent: Extent) {\n        // ui.text(\"This struct doesn't provide a mutable ui.\");\n        self.render_component(ui, extent);\n    }\n}\n```\n\nNow, whenever it is needed to render the struct using ImGui, in the\nrender loop, when a context to ImGui is obtained and a new frame drawing\nhas begun, simply:\n\n```rust\n// Before the loop we create the object we want to render:\nlet mut scene = Scene::new();\n// And initialise imgui:\nlet imgui = _; // obtain the imgui object\n// And store the extent of the window:\nlet extent = imgui_presentable::Extent {\n    width: window.width,\n    height: window.height,\n};\n\n// Now, in the render loop:\nlet context = imgui.get_context();\nlet ui = context.new_frame();\n\n// Render the component in a separate window:\nscene.render_window_mut(ui, extent);\n\n// Then finish the ImGui frame:\nlet draw_data = imgui.render();\n// And render it using what you can.\n```\n\nThis leads to this:\n\n![Image](screenshot.png \"The Scene struct is shown in ImGui\")\n\n## Backends\n\nThe supported backends:\n\n- egui\n- ImGui\n\nThe backend is selectable via the crate features.\n\nFor each of the backends, a similar but separate trait exists. Though,\nthe same trait could have just been changed, it is much more practical\nand agile to allow both features to co-exist and this cannot be done\nusing a single trait, unfortunately.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiddm%2Fimgui_presentable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiddm%2Fimgui_presentable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiddm%2Fimgui_presentable/lists"}