mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-17 16:38:28 +00:00
Trees
This commit is contained in:
parent
e8d7db3d9d
commit
b14999b5a2
@ -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
55
src/trees.rs
Normal 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() };
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user