use crate::ui::Ui;
use super::{TabItemOptions, TabItemPlacement, TabItemToken};
#[derive(Debug)]
#[must_use]
pub struct TabItem<'a, T> {
label: T,
opened: Option<&'a mut bool>,
options: TabItemOptions,
}
impl<'a, T: AsRef<str>> TabItem<'a, T> {
#[doc(alias = "BeginTabItem")]
pub fn new(label: T) -> Self {
Self {
label,
opened: None,
options: TabItemOptions::new(),
}
}
pub fn opened(mut self, opened: &'a mut bool) -> Self {
self.opened = Some(opened);
self
}
pub fn flags(mut self, flags: impl Into<TabItemOptions>) -> Self {
self.options = flags.into();
self
}
pub fn placement(mut self, placement: TabItemPlacement) -> Self {
self.options.placement = Some(placement);
self
}
pub fn begin(self, ui: &Ui) -> Option<TabItemToken<'_>> {
ui.tab_item_with_flags(self.label, self.opened, self.options)
}
pub fn build<R, F: FnOnce() -> R>(self, ui: &Ui, f: F) -> Option<R> {
self.begin(ui).map(|_tab| f())
}
}