Headerbar: Remove the requirment of a window to construct it.
This commit is contained in:
parent
91aae6a9f5
commit
8b2ae6d464
@ -88,7 +88,9 @@ impl App {
|
|||||||
let content = Content::new(&sender).expect("Content Initialization failed.");
|
let content = Content::new(&sender).expect("Content Initialization failed.");
|
||||||
|
|
||||||
// Create the headerbar
|
// Create the headerbar
|
||||||
let header = Header::new(&content, &window, &sender);
|
let header = Header::new(&content, &sender);
|
||||||
|
// Add the Headerbar to the window.
|
||||||
|
window.set_titlebar(&header.container);
|
||||||
|
|
||||||
// Add the content main stack to the overlay.
|
// Add the content main stack to the overlay.
|
||||||
let overlay = gtk::Overlay::new();
|
let overlay = gtk::Overlay::new();
|
||||||
|
|||||||
@ -18,7 +18,7 @@ use std::rc::Rc;
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
// TODO: split this into smaller
|
// TODO: split this into smaller
|
||||||
pub struct Header {
|
pub struct Header {
|
||||||
container: gtk::HeaderBar,
|
pub container: gtk::HeaderBar,
|
||||||
switch: gtk::StackSwitcher,
|
switch: gtk::StackSwitcher,
|
||||||
back: gtk::Button,
|
back: gtk::Button,
|
||||||
show_title: gtk::Label,
|
show_title: gtk::Label,
|
||||||
@ -180,22 +180,13 @@ impl Default for Header {
|
|||||||
|
|
||||||
// TODO: Refactor components into smaller widgets.
|
// TODO: Refactor components into smaller widgets.
|
||||||
impl Header {
|
impl Header {
|
||||||
pub fn new(
|
pub fn new(content: &Content, sender: &Sender<Action>) -> Rc<Self> {
|
||||||
content: &Content,
|
|
||||||
window: >k::ApplicationWindow,
|
|
||||||
sender: &Sender<Action>,
|
|
||||||
) -> Rc<Self> {
|
|
||||||
let h = Rc::new(Header::default());
|
let h = Rc::new(Header::default());
|
||||||
Self::init(&h, content, window, &sender);
|
Self::init(&h, content, &sender);
|
||||||
h
|
h
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init(
|
pub fn init(s: &Rc<Self>, content: &Content, sender: &Sender<Action>) {
|
||||||
s: &Rc<Self>,
|
|
||||||
content: &Content,
|
|
||||||
window: >k::ApplicationWindow,
|
|
||||||
sender: &Sender<Action>,
|
|
||||||
) {
|
|
||||||
let weak = Rc::downgrade(s);
|
let weak = Rc::downgrade(s);
|
||||||
|
|
||||||
s.switch.set_stack(&content.get_stack());
|
s.switch.set_stack(&content.get_stack());
|
||||||
@ -212,9 +203,6 @@ impl Header {
|
|||||||
weak.upgrade().map(|h| h.add.on_add_clicked(&sender));
|
weak.upgrade().map(|h| h.add.on_add_clicked(&sender));
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Add the Headerbar to the window.
|
|
||||||
window.set_titlebar(&s.container);
|
|
||||||
|
|
||||||
let switch = &s.switch;
|
let switch = &s.switch;
|
||||||
let add_toggle = &s.add.toggle;
|
let add_toggle = &s.add.toggle;
|
||||||
let show_title = &s.show_title;
|
let show_title = &s.show_title;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user