This repository has been archived on 2025-03-27. You can view files and clone it, but cannot push or open issues or pull requests.
AIT/src/view/components/tabs.rs

71 lines
1.5 KiB
Rust
Raw Normal View History

pub mod tabs_module {
use gtk4 as gtk;
use gtk::{Notebook, Label, Box};
pub type TabLabel = Label;
pub type TabContent = Box;
#[derive(Clone)]
pub struct TabsBuilder {
tabs: Vec<(TabLabel, TabContent)>
}
pub struct Tabs {
tabs_wrapper: Notebook
}
impl Tabs {
pub fn builder() -> TabsBuilder {
TabsBuilder{
tabs: Vec::new(),
}
}
pub fn get(self) -> Notebook {
self.tabs_wrapper
}
}
impl TabsBuilder {
fn append_tab_private(&mut self, label: &str, page: TabContent) {
let tab_label = Label::new(Some(label));
self.tabs.push((tab_label, page));
}
pub fn add_tab(mut self, label: &str, page: TabContent) -> Self {
self.append_tab_private(label, page);
self
}
pub fn add_tabs(mut self, labels: Vec<&str>, pages: Vec<TabContent>) -> Self {
for (label, page) in labels.iter().zip(pages) {
self.append_tab_private(label, page);
}
self
}
pub fn build(&mut self, group_name: &str) -> Tabs {
let tabs_wrapper = Notebook::builder()
.group_name(group_name)
.build();
self.tabs
.iter()
.for_each(|(label, content)| {
tabs_wrapper.append_page(content, Some(label));
});
Tabs {
tabs_wrapper
}
}
}
}