2024-03-12 22:49:20 +03:00
|
|
|
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(
|
2024-03-12 22:54:20 +03:00
|
|
|
&self,
|
2024-03-12 22:49:20 +03:00
|
|
|
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(
|
2024-03-12 22:54:20 +03:00
|
|
|
self,
|
2024-03-12 22:49:20 +03:00
|
|
|
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(
|
2024-03-12 22:54:20 +03:00
|
|
|
self,
|
2024-03-12 22:49:20 +03:00
|
|
|
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(
|
2024-03-12 22:54:20 +03:00
|
|
|
self,
|
2024-03-12 22:49:20 +03:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|