use crate::ui::Ui;
use super::{TabBarFittingPolicy, TabBarFlags, TabBarOptions, TabBarToken};
#[derive(Debug)]
#[must_use]
pub struct TabBar<T> {
id: T,
options: TabBarOptions,
}
impl<T: AsRef<str>> TabBar<T> {
#[doc(alias = "BeginTabBar")]
pub fn new(id: T) -> Self {
Self {
id,
options: TabBarOptions::new(),
}
}
pub fn reorderable(mut self, value: bool) -> Self {
if value {
self.options.flags |= TabBarFlags::REORDERABLE;
} else {
self.options.flags &= !TabBarFlags::REORDERABLE;
}
self
}
pub fn flags(mut self, flags: impl Into<TabBarOptions>) -> Self {
self.options = flags.into();
self
}
pub fn fitting_policy(mut self, policy: TabBarFittingPolicy) -> Self {
self.options.fitting_policy = Some(policy);
self
}
pub fn begin(self, ui: &Ui) -> Option<TabBarToken<'_>> {
ui.tab_bar_with_flags(self.id, self.options)
}
pub fn build<R, F: FnOnce() -> R>(self, ui: &Ui, f: F) -> Option<R> {
self.begin(ui).map(|_tab| f())
}
}