added pages builder, to do universal traits for builders
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
pub mod wrapper;
|
||||
pub mod switch;
|
||||
pub mod tabs;
|
||||
pub mod pages;
|
||||
pub mod switch;
|
||||
pub mod wrapper;
|
||||
|
||||
88
src/view/components/pages.rs
Normal file
88
src/view/components/pages.rs
Normal file
@@ -0,0 +1,88 @@
|
||||
use gtk4 as gtk;
|
||||
|
||||
use gtk::{Stack, StackSidebar, Box};
|
||||
use gtk4::{Orientation, StackSwitcher, StackTransitionType, Widget};
|
||||
use gtk4::prelude::{BoxExt, IsA};
|
||||
|
||||
pub struct Pages{
|
||||
all_pages: Box
|
||||
}
|
||||
|
||||
pub struct PagesBuilder{
|
||||
pages_content: Stack,
|
||||
}
|
||||
|
||||
impl Pages {
|
||||
pub fn builder() -> PagesBuilder{
|
||||
PagesBuilder {
|
||||
pages_content: Stack::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get(self) -> Box {
|
||||
self.all_pages
|
||||
}
|
||||
}
|
||||
|
||||
impl PagesBuilder {
|
||||
|
||||
fn append_page_private(
|
||||
&mut self,
|
||||
page_name: &str,
|
||||
page_title: &str,
|
||||
content: &impl IsA<Widget>
|
||||
) {
|
||||
self.pages_content.add_titled(content, Some(page_name), page_title);
|
||||
}
|
||||
|
||||
pub fn set_transition(
|
||||
mut self,
|
||||
type_transition : StackTransitionType,
|
||||
duration: u32
|
||||
) -> Self {
|
||||
self.pages_content.set_transition_type(type_transition);
|
||||
self.pages_content.set_transition_duration(duration);
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_page(
|
||||
mut self,
|
||||
page_name: &str,
|
||||
page_title: &str,
|
||||
content: &impl IsA<Widget>
|
||||
) -> Self {
|
||||
self.append_page_private(page_name, page_title, content);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_pages(
|
||||
mut self,
|
||||
pages: Vec<(&str, &str, &impl IsA<Widget>)>,
|
||||
) -> Self {
|
||||
pages.iter()
|
||||
.for_each(|(name, title, content)| {
|
||||
self.append_page_private(*name, *title, *content);
|
||||
});
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build(&self, spacing: i32) -> Pages {
|
||||
let stack_sidebar = StackSidebar::new();
|
||||
let stack_switcher = StackSwitcher::new();
|
||||
|
||||
stack_sidebar.set_stack(&self.pages_content);
|
||||
stack_switcher.set_stack(Some(&self.pages_content));
|
||||
|
||||
let wrapper = Box::new(Orientation::Horizontal, spacing);
|
||||
|
||||
wrapper.append(&stack_sidebar);
|
||||
wrapper.append(&self.pages_content);
|
||||
|
||||
Pages{
|
||||
all_pages: wrapper
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,7 +24,6 @@ impl Tabs {
|
||||
pub fn get(self) -> Notebook {
|
||||
self.tabs_wrapper
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl TabsBuilder {
|
||||
|
||||
Reference in New Issue
Block a user