follow new construction protocol

This commit is contained in:
yggverse 2024-09-26 00:59:44 +03:00
parent c03bef9f15
commit 1db706aa5b
7 changed files with 25 additions and 30 deletions

View File

@ -5,7 +5,6 @@ use subject::Subject;
use tray::Tray;
use gtk::{glib::GString, HeaderBar};
use std::sync::Arc;
pub struct Header {
widget: HeaderBar,
@ -14,7 +13,7 @@ pub struct Header {
impl Header {
// Construct
pub fn new() -> Arc<Header> {
pub fn new() -> Header {
let tray = Tray::new();
let subject = Subject::new();
@ -22,7 +21,7 @@ impl Header {
widget.pack_start(tray.widget());
widget.set_title_widget(Some(subject.widget()));
Arc::new(Self { widget, subject })
Self { widget, subject }
}
// Actions

View File

@ -3,16 +3,15 @@ mod tab;
use tab::Tab;
use gtk::{glib::GString, prelude::BoxExt, Box, Orientation};
use std::sync::Arc;
pub struct Main {
tab: Arc<Tab>,
tab: Tab,
widget: Box,
}
impl Main {
// Construct
pub fn new() -> Arc<Main> {
pub fn new() -> Main {
// Init components
let tab = Tab::new();
@ -22,7 +21,7 @@ impl Main {
widget.append(tab.widget());
// Init struct
Arc::new(Self { tab, widget })
Self { tab, widget }
}
// Actions

View File

@ -10,8 +10,6 @@ use gtk::{
Align, Box, Orientation,
};
use std::sync::Arc;
pub struct Label {
// Components
pin: Pin,
@ -23,7 +21,7 @@ pub struct Label {
impl Label {
// Construct
pub fn new(name: GString, is_pinned: bool) -> Arc<Label> {
pub fn new(name: GString, is_pinned: bool) -> Label {
// Components
let pin = Pin::new(is_pinned);
let title = Title::new();
@ -39,7 +37,7 @@ impl Label {
widget.append(title.widget());
// Result
Arc::new(Self { pin, title, widget })
Self { pin, title, widget }
}
// Actions

View File

@ -22,20 +22,21 @@ pub struct Tab {
impl Tab {
// Construct
pub fn new() -> Arc<Tab> {
pub fn new() -> Tab {
// Init GTK component
let notebook = Arc::new(Notebook::builder().scrollable(true).build());
// Init new Tab struct
let tab = Arc::new(Self {
let tab = Self {
// Reference wanted for async events, create new smart pointer
widget: notebook.clone(),
// Init empty HashMap index as no tabs appended yet
labels: RefCell::new(HashMap::new()),
pages: RefCell::new(HashMap::new()),
});
};
// Connect events
/* @TODO move outside
notebook.connect_page_removed({
// Make new local ref
let tab = tab.clone();
@ -46,7 +47,7 @@ impl Tab {
tab.labels.borrow_mut().remove(id);
tab.pages.borrow_mut().remove(id);
}
});
});*/
tab // return Arc pointer to the new Tab constructed
}
@ -57,8 +58,8 @@ impl Tab {
let id = uuid_string_random();
// Init new tab components
let label = Label::new(id.clone(), false);
let page = Page::new(id.clone());
let label = Arc::new(Label::new(id.clone(), false));
let page = Arc::new(Page::new(id.clone()));
// Register dynamically created tab components in the HashMap index
self.labels.borrow_mut().insert(id.clone(), label.clone());

View File

@ -1,5 +1,3 @@
use std::sync::Arc;
use gtk::{Box, Orientation};
pub struct Content {
@ -8,10 +6,10 @@ pub struct Content {
impl Content {
// Construct
pub fn new() -> Arc<Content> {
Arc::new(Self {
pub fn new() -> Content {
Self {
widget: Box::builder().orientation(Orientation::Vertical).build(),
})
}
}
// Getters

View File

@ -21,7 +21,7 @@ pub struct Page {
// GTK
widget: Box,
// Components
navigation: Navigation,
navigation: Arc<Navigation>,
content: Arc<Content>,
// Extras
meta: Arc<RefCell<Meta>>,
@ -29,10 +29,10 @@ pub struct Page {
impl Page {
// Construct
pub fn new(name: GString) -> Arc<Page> {
pub fn new(name: GString) -> Page {
// Init components
let content = Content::new();
let navigation = Navigation::new();
let content = Arc::new(Content::new());
let navigation = Arc::new(Navigation::new());
// Init widget
let widget = Box::builder()
@ -47,12 +47,12 @@ impl Page {
let meta = Arc::new(RefCell::new(Meta::new()));
// Result
Arc::new(Self {
Self {
widget,
content,
navigation,
meta,
})
}
}
// Actions

View File

@ -31,8 +31,8 @@ impl Browser {
) -> Browser {
// Init components
// let db = db::Browser::new(connection);
let header = header::Header::new();
let main = main::Main::new();
let header = Arc::new(header::Header::new());
let main = Arc::new(main::Main::new());
let widget = ApplicationWindow::builder()
.application(app)