Basic i32 ID stack manipulation

This commit is contained in:
Joonas Javanainen 2017-03-17 21:09:00 +02:00
parent ef6cb15c61
commit b807b8755e
No known key found for this signature in database
GPG Key ID: D39CCA5CB19B9179
2 changed files with 25 additions and 1 deletions

View File

@ -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

View File

@ -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<F>(&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<F>(&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>) {