#![allow(deprecated, dead_code)]
use egui::style::Margin;
use egui::{Ui, WidgetText};
#[deprecated]
pub type TabContent = Box<dyn FnMut(&mut Ui) + 'static>;
#[deprecated]
pub type OnClose = Box<dyn FnMut() -> bool + 'static>;
#[deprecated]
pub type ForceClose = Box<dyn FnMut() -> bool + 'static>;
#[deprecated]
pub struct TabBuilder {
title: Option<WidgetText>,
inner_margin: Margin,
add_content: Option<TabContent>,
on_close: Option<OnClose>,
force_close: Option<ForceClose>,
clear_background: Option<bool>,
}
#[deprecated]
pub trait Tab {
fn ui(&mut self, ui: &mut Ui);
fn context_menu(&mut self, _ui: &mut Ui) {}
fn title(&mut self) -> WidgetText;
fn on_close(&mut self) -> bool {
true
}
fn force_close(&mut self) -> bool {
false
}
fn inner_margin(&self) -> Margin {
Margin::same(4.0)
}
fn clear_background(&self) -> bool {
true
}
}
#[deprecated]
pub struct BuiltTab {
pub title: WidgetText,
pub inner_margin: Margin,
pub add_content: TabContent,
on_close: Option<OnClose>,
force_close: Option<ForceClose>,
clear_background: bool,
}
impl Tab for BuiltTab {
fn ui(&mut self, ui: &mut Ui) {
(self.add_content)(ui);
}
fn context_menu(&mut self, ui: &mut Ui) {
(self.add_content)(ui);
}
fn title(&mut self) -> WidgetText {
self.title.clone()
}
fn on_close(&mut self) -> bool {
match &mut self.on_close {
Some(on_close) => on_close(),
None => true,
}
}
fn force_close(&mut self) -> bool {
match &mut self.force_close {
Some(force_close) => force_close(),
None => false,
}
}
fn inner_margin(&self) -> Margin {
self.inner_margin
}
fn clear_background(&self) -> bool {
self.clear_background
}
}
impl Default for TabBuilder {
fn default() -> Self {
Self {
title: None,
inner_margin: Margin::same(4.0),
add_content: None,
on_close: None,
force_close: None,
clear_background: None,
}
}
}
impl TabBuilder {
pub fn build(self) -> Box<dyn Tab> {
Box::new(BuiltTab {
title: self.title.expect("Missing tab title"),
inner_margin: self.inner_margin,
add_content: self.add_content.expect("Missing tab content"),
on_close: self.on_close,
force_close: self.force_close,
clear_background: self.clear_background.unwrap_or(true),
})
}
pub fn title(mut self, title: impl Into<WidgetText>) -> Self {
self.title = Some(title.into());
self
}
pub fn inner_margin(mut self, margin: Margin) -> Self {
self.inner_margin = margin;
self
}
pub fn content(mut self, add_content: impl FnMut(&mut Ui) + 'static) -> Self {
self.add_content = Some(Box::new(add_content));
self
}
pub fn on_close(mut self, on_close: impl FnMut() -> bool + 'static) -> Self {
self.on_close = Some(Box::new(on_close));
self
}
pub fn force_close(mut self, force_close: impl FnMut() -> bool + 'static) -> Self {
self.force_close = Some(Box::new(force_close));
self
}
pub fn clear_background(mut self, clear_background: bool) -> Self {
self.clear_background = Some(clear_background);
self
}
}
#[deprecated]
pub type DynamicTree = crate::Tree<Box<dyn Tab>>;
#[derive(Default)]
#[deprecated]
pub struct DynamicTabViewer {}
impl crate::TabViewer for DynamicTabViewer {
type Tab = Box<dyn Tab>;
fn ui(&mut self, ui: &mut Ui, tab: &mut Self::Tab) {
tab.ui(ui)
}
fn context_menu(&mut self, _ui: &mut Ui, _tab: &mut Self::Tab) {}
fn title(&mut self, tab: &mut Self::Tab) -> WidgetText {
tab.title()
}
fn on_close(&mut self, tab: &mut Self::Tab) -> bool {
tab.on_close()
}
fn force_close(&mut self, tab: &mut Self::Tab) -> bool {
tab.force_close()
}
fn clear_background(&self, tab: &Self::Tab) -> bool {
tab.clear_background()
}
}