Fully refactored project architecture, imports and etc.
This commit is contained in:
71
src/view/components/tabs.rs
Normal file
71
src/view/components/tabs.rs
Normal file
@@ -0,0 +1,71 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user