use std::ptr;
use crate::sys;
use crate::ui::Ui;
use super::{TabBarFlags, TabBarOptions, TabBarToken, TabItemOptions, TabItemToken};
impl Ui {
#[doc(alias = "BeginTabBar")]
pub fn tab_bar(&self, id: impl AsRef<str>) -> Option<TabBarToken<'_>> {
self.tab_bar_with_flags(id, TabBarFlags::NONE)
}
#[doc(alias = "BeginTabBar")]
pub fn tab_bar_with_flags(
&self,
id: impl AsRef<str>,
flags: impl Into<TabBarOptions>,
) -> Option<TabBarToken<'_>> {
let options = flags.into();
options.validate("Ui::tab_bar_with_flags()");
let id_ptr = self.scratch_txt(id);
let should_render = unsafe { sys::igBeginTabBar(id_ptr, options.raw()) };
if should_render {
Some(TabBarToken::new(self))
} else {
None
}
}
#[doc(alias = "BeginTabItem")]
pub fn tab_item(&self, label: impl AsRef<str>) -> Option<TabItemToken<'_>> {
self.tab_item_with_flags(label, None, TabItemOptions::new())
}
#[doc(alias = "BeginTabItem")]
pub fn tab_item_with_opened(
&self,
label: impl AsRef<str>,
opened: &mut bool,
) -> Option<TabItemToken<'_>> {
self.tab_item_with_flags(label, Some(opened), TabItemOptions::new())
}
#[doc(alias = "BeginTabItem")]
pub fn tab_item_with_flags(
&self,
label: impl AsRef<str>,
opened: Option<&mut bool>,
flags: impl Into<TabItemOptions>,
) -> Option<TabItemToken<'_>> {
let options = flags.into();
options.validate_for_tab_item("Ui::tab_item_with_flags()");
let label_ptr = self.scratch_txt(label);
let opened_ptr = opened.map(|x| x as *mut bool).unwrap_or(ptr::null_mut());
let should_render = unsafe { sys::igBeginTabItem(label_ptr, opened_ptr, options.raw()) };
if should_render {
Some(TabItemToken::new(self))
} else {
None
}
}
#[doc(alias = "TabItemButton")]
pub fn tab_item_button(&self, label: impl AsRef<str>) -> bool {
self.tab_item_button_with_flags(label, TabItemOptions::new())
}
#[doc(alias = "TabItemButton")]
pub fn tab_item_button_with_flags(
&self,
label: impl AsRef<str>,
flags: impl Into<TabItemOptions>,
) -> bool {
let options = flags.into();
options.validate_for_tab_button("Ui::tab_item_button_with_flags()");
unsafe { sys::igTabItemButton(self.scratch_txt(label), options.raw()) }
}
#[doc(alias = "SetTabItemClosed")]
pub fn set_tab_item_closed(&self, tab_or_docked_window_label: impl AsRef<str>) {
unsafe { sys::igSetTabItemClosed(self.scratch_txt(tab_or_docked_window_label)) }
}
}