dear_imgui_rs/widget/tab/
ui.rs1use std::ptr;
2
3use crate::sys;
4use crate::ui::Ui;
5
6use super::{TabBarFlags, TabBarOptions, TabBarToken, TabItemOptions, TabItemToken};
7
8impl Ui {
10 #[doc(alias = "BeginTabBar")]
14 pub fn tab_bar(&self, id: impl AsRef<str>) -> Option<TabBarToken<'_>> {
15 self.tab_bar_with_flags(id, TabBarFlags::NONE)
16 }
17
18 #[doc(alias = "BeginTabBar")]
21 pub fn tab_bar_with_flags(
22 &self,
23 id: impl AsRef<str>,
24 flags: impl Into<TabBarOptions>,
25 ) -> Option<TabBarToken<'_>> {
26 let options = flags.into();
27 options.validate("Ui::tab_bar_with_flags()");
28 let id_ptr = self.scratch_txt(id);
29 let should_render =
30 self.run_with_bound_context(|| unsafe { sys::igBeginTabBar(id_ptr, options.raw()) });
31
32 if should_render {
33 Some(TabBarToken::new(self))
34 } else {
35 None
36 }
37 }
38
39 #[doc(alias = "BeginTabItem")]
47 pub fn tab_item(&self, label: impl AsRef<str>) -> Option<TabItemToken<'_>> {
48 self.tab_item_with_flags(label, None, TabItemOptions::new())
49 }
50
51 #[doc(alias = "BeginTabItem")]
55 pub fn tab_item_with_opened(
56 &self,
57 label: impl AsRef<str>,
58 opened: &mut bool,
59 ) -> Option<TabItemToken<'_>> {
60 self.tab_item_with_flags(label, Some(opened), TabItemOptions::new())
61 }
62
63 #[doc(alias = "BeginTabItem")]
65 pub fn tab_item_with_flags(
66 &self,
67 label: impl AsRef<str>,
68 opened: Option<&mut bool>,
69 flags: impl Into<TabItemOptions>,
70 ) -> Option<TabItemToken<'_>> {
71 let options = flags.into();
72 options.validate_for_tab_item("Ui::tab_item_with_flags()");
73 let label_ptr = self.scratch_txt(label);
74 let opened_ptr = opened.map(|x| x as *mut bool).unwrap_or(ptr::null_mut());
75
76 let should_render = self.run_with_bound_context(|| unsafe {
77 sys::igBeginTabItem(label_ptr, opened_ptr, options.raw())
78 });
79
80 if should_render {
81 Some(TabItemToken::new(self))
82 } else {
83 None
84 }
85 }
86
87 #[doc(alias = "TabItemButton")]
89 pub fn tab_item_button(&self, label: impl AsRef<str>) -> bool {
90 self.tab_item_button_with_flags(label, TabItemOptions::new())
91 }
92
93 #[doc(alias = "TabItemButton")]
95 pub fn tab_item_button_with_flags(
96 &self,
97 label: impl AsRef<str>,
98 flags: impl Into<TabItemOptions>,
99 ) -> bool {
100 let options = flags.into();
101 options.validate_for_tab_button("Ui::tab_item_button_with_flags()");
102 let label_ptr = self.scratch_txt(label);
103 self.run_with_bound_context(|| unsafe { sys::igTabItemButton(label_ptr, options.raw()) })
104 }
105
106 #[doc(alias = "SetTabItemClosed")]
108 pub fn set_tab_item_closed(&self, tab_or_docked_window_label: impl AsRef<str>) {
109 let label_ptr = self.scratch_txt(tab_or_docked_window_label);
110 self.run_with_bound_context(|| unsafe { sys::igSetTabItemClosed(label_ptr) });
111 }
112}