This commit is contained in:
Joonas Javanainen 2015-08-26 11:46:12 +01:00
parent e8d7db3d9d
commit b14999b5a2
2 changed files with 64 additions and 0 deletions

View File

@ -32,11 +32,13 @@ pub use imgui_sys::{
};
pub use menus::{Menu, MenuItem};
pub use sliders::{SliderFloat, SliderInt};
pub use trees::{TreeNode};
pub use widgets::{CollapsingHeader};
pub use window::{Window};
mod menus;
mod sliders;
mod trees;
mod widgets;
mod window;
@ -305,6 +307,13 @@ impl<'ui> Ui<'ui> {
}
}
// Widgets: Trees
impl<'ui> Ui<'ui> {
pub fn tree_node<'p>(&self, id: ImStr<'p>) -> TreeNode<'ui, 'p> {
TreeNode::new(id)
}
}
// Widgets: Menus
impl<'ui> Ui<'ui> {
pub fn main_menu_bar<F>(&self, f: F) where F: FnOnce() {

55
src/trees.rs Normal file
View File

@ -0,0 +1,55 @@
use imgui_sys;
use std::marker::PhantomData;
use super::{Ui, ImGuiSetCond, ImStr};
pub struct TreeNode<'ui, 'p> {
id: ImStr<'p>,
label: Option<ImStr<'p>>,
opened: bool,
opened_cond: ImGuiSetCond,
_phantom: PhantomData<&'ui Ui<'ui>>
}
impl<'ui, 'p> TreeNode<'ui, 'p> {
pub fn new(id: ImStr<'p>) -> Self {
TreeNode {
id: id,
label: None,
opened: false,
opened_cond: ImGuiSetCond::empty(),
_phantom: PhantomData
}
}
#[inline]
pub fn label(self, label: ImStr<'p>) -> Self {
TreeNode {
label: Some(label),
.. self
}
}
#[inline]
pub fn opened(self, opened: bool, cond: ImGuiSetCond) -> Self {
TreeNode {
opened: opened,
opened_cond: cond,
.. self
}
}
pub fn build<F: FnOnce()>(self, f: F) {
let render = unsafe {
if !self.opened_cond.is_empty() {
imgui_sys::igSetNextTreeNodeOpened(self.opened, self.opened_cond);
}
imgui_sys::igTreeNodeStr(
self.id.as_ptr(),
super::fmt_ptr(),
self.label.unwrap_or(self.id).as_ptr()
)
};
if render {
f();
unsafe { imgui_sys::igTreePop() };
}
}
}