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 = unsafe { sys::igBeginTabBar(id_ptr, options.raw()) };
30
31 if should_render {
32 Some(TabBarToken::new(self))
33 } else {
34 None
35 }
36 }
37
38 #[doc(alias = "BeginTabItem")]
46 pub fn tab_item(&self, label: impl AsRef<str>) -> Option<TabItemToken<'_>> {
47 self.tab_item_with_flags(label, None, TabItemOptions::new())
48 }
49
50 #[doc(alias = "BeginTabItem")]
54 pub fn tab_item_with_opened(
55 &self,
56 label: impl AsRef<str>,
57 opened: &mut bool,
58 ) -> Option<TabItemToken<'_>> {
59 self.tab_item_with_flags(label, Some(opened), TabItemOptions::new())
60 }
61
62 #[doc(alias = "BeginTabItem")]
64 pub fn tab_item_with_flags(
65 &self,
66 label: impl AsRef<str>,
67 opened: Option<&mut bool>,
68 flags: impl Into<TabItemOptions>,
69 ) -> Option<TabItemToken<'_>> {
70 let options = flags.into();
71 options.validate_for_tab_item("Ui::tab_item_with_flags()");
72 let label_ptr = self.scratch_txt(label);
73 let opened_ptr = opened.map(|x| x as *mut bool).unwrap_or(ptr::null_mut());
74
75 let should_render = unsafe { sys::igBeginTabItem(label_ptr, opened_ptr, options.raw()) };
76
77 if should_render {
78 Some(TabItemToken::new(self))
79 } else {
80 None
81 }
82 }
83
84 #[doc(alias = "TabItemButton")]
86 pub fn tab_item_button(&self, label: impl AsRef<str>) -> bool {
87 self.tab_item_button_with_flags(label, TabItemOptions::new())
88 }
89
90 #[doc(alias = "TabItemButton")]
92 pub fn tab_item_button_with_flags(
93 &self,
94 label: impl AsRef<str>,
95 flags: impl Into<TabItemOptions>,
96 ) -> bool {
97 let options = flags.into();
98 options.validate_for_tab_button("Ui::tab_item_button_with_flags()");
99 unsafe { sys::igTabItemButton(self.scratch_txt(label), options.raw()) }
100 }
101
102 #[doc(alias = "SetTabItemClosed")]
104 pub fn set_tab_item_closed(&self, tab_or_docked_window_label: impl AsRef<str>) {
105 unsafe { sys::igSetTabItemClosed(self.scratch_txt(tab_or_docked_window_label)) }
106 }
107}