diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index d0141ba..d76c896 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -6,6 +6,7 @@ - Support for progress bar - Support for push/pop item width +- Support for ID stack manipulation (integer values) - `ImVec4::zero()` - `Into` array and tuple conversions for ImVec2 and ImVec4 diff --git a/src/lib.rs b/src/lib.rs index 2389b43..af41e8c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -409,7 +409,7 @@ impl<'ui> Ui<'ui> { /// The current process is aborted if the item width stack is empty. pub fn pop_item_width(&self) { unsafe { imgui_sys::igPopItemWidth() } } - /// Runs a function with a value temporarily pushed to the item width stack. + /// Runs a function after temporarily pushing a value to the item width stack. pub fn with_item_width(&self, width: f32, f: F) where F: FnOnce() { self.push_item_width(width); f(); @@ -446,6 +446,29 @@ impl<'ui> Ui<'ui> { pub fn get_columns_count(&self) -> i32 { unsafe { imgui_sys::igGetColumnsCount() } } } +// ID scopes +impl<'ui> Ui<'ui> { + /// Pushes an identifier to the ID stack. + pub fn push_id(&self, id: i32) { + unsafe { imgui_sys::igPushIdInt(id) }; + } + + /// Pops an identifier from the ID stack. + /// + /// # Aborts + /// The current process is aborted if the ID stack is empty. + pub fn pop_id(&self) { + unsafe { imgui_sys::igPopId() }; + } + + /// Runs a function after temporarily pushing a value to the ID stack. + pub fn with_id(&self, id: i32, f: F) where F: FnOnce() { + self.push_id(id); + f(); + self.pop_id(); + } +} + // Widgets impl<'ui> Ui<'ui> { pub fn text<'p>(&self, text: ImStr<'p>) {