Skip to main content

dear_imgui_rs/widget/tree/
entry.rs

1use crate::Id;
2use crate::sys;
3use crate::ui::Ui;
4
5use super::{TreeNode, TreeNodeFlags, TreeNodeId, TreeNodeToken};
6
7/// # Tree Node Widgets
8impl Ui {
9    /// Constructs a new tree node with just a name, and pushes it.
10    ///
11    /// Use [tree_node_config] to access a builder to put additional
12    /// configurations on the tree node.
13    ///
14    /// [tree_node_config]: Self::tree_node_config
15    pub fn tree_node<I, T>(&self, id: I) -> Option<TreeNodeToken<'_>>
16    where
17        I: Into<TreeNodeId<T>>,
18        T: AsRef<str>,
19    {
20        self.tree_node_config(id).push()
21    }
22
23    /// Constructs a new tree node builder.
24    ///
25    /// Use [tree_node] to build a simple node with just a name.
26    ///
27    /// [tree_node]: Self::tree_node
28    pub fn tree_node_config<I, T>(&self, id: I) -> TreeNode<'_, T>
29    where
30        I: Into<TreeNodeId<T>>,
31        T: AsRef<str>,
32    {
33        TreeNode::new(id.into(), self)
34    }
35
36    /// Creates a collapsing header widget
37    #[doc(alias = "CollapsingHeader")]
38    pub fn collapsing_header(&self, label: impl AsRef<str>, flags: TreeNodeFlags) -> bool {
39        let label_ptr = self.scratch_txt(label);
40        unsafe { sys::igCollapsingHeader_TreeNodeFlags(label_ptr, flags.bits()) }
41    }
42
43    /// Creates a collapsing header widget with a visibility tracking variable.
44    ///
45    /// Passing `visible` enables a close button on the header. When clicked, ImGui will set
46    /// `*visible = false`. As with other immediate-mode widgets, you should stop submitting the
47    /// header when `*visible == false`.
48    #[doc(alias = "CollapsingHeader")]
49    pub fn collapsing_header_with_visible(
50        &self,
51        label: impl AsRef<str>,
52        visible: &mut bool,
53        flags: TreeNodeFlags,
54    ) -> bool {
55        let label_ptr = self.scratch_txt(label);
56        unsafe { sys::igCollapsingHeader_BoolPtr(label_ptr, visible as *mut bool, flags.bits()) }
57    }
58
59    /// Returns the distance from the start of a tree node to the label text.
60    #[doc(alias = "GetTreeNodeToLabelSpacing")]
61    pub fn tree_node_to_label_spacing(&self) -> f32 {
62        unsafe { sys::igGetTreeNodeToLabelSpacing() }
63    }
64
65    /// Returns whether the tree node identified by `storage_id` is open in storage.
66    #[doc(alias = "TreeNodeGetOpen")]
67    pub fn tree_node_get_open(&self, storage_id: Id) -> bool {
68        unsafe { sys::igTreeNodeGetOpen(storage_id.raw()) }
69    }
70}