implement separated mod for window widget, rename getters

This commit is contained in:
yggverse 2024-10-06 05:03:45 +03:00
parent 13292a977d
commit 1e00c5930c
5 changed files with 58 additions and 64 deletions

View file

@ -13,7 +13,7 @@ const MAXIMIZED: bool = false;
pub struct Widget {
database: Arc<Database>,
application_window: ApplicationWindow,
gobject: ApplicationWindow,
}
impl Widget {
@ -48,7 +48,7 @@ impl Widget {
};
// Init GTK
let application_window = ApplicationWindow::builder()
let gobject = ApplicationWindow::builder()
.titlebar(titlebar)
.child(child)
.default_height(DEFAULT_HEIGHT)
@ -57,10 +57,7 @@ impl Widget {
.build();
// Return new struct
Self {
database,
application_window,
}
Self { database, gobject }
}
// Actions
@ -86,8 +83,8 @@ impl Widget {
Ok(records) => {
for record in records {
// Restore widget
self.application_window.set_maximized(record.is_maximized);
self.application_window
self.gobject.set_maximized(record.is_maximized);
self.gobject
.set_default_size(record.default_width, record.default_height);
// Delegate restore action to childs
@ -102,9 +99,9 @@ impl Widget {
match self.database.add(
tx,
app_browser_id,
&self.application_window.default_width(),
&self.application_window.default_height(),
&self.application_window.is_maximized(),
&self.gobject.default_width(),
&self.gobject.default_height(),
&self.gobject.is_maximized(),
) {
Ok(_) => {
// Delegate save action to childs
@ -116,7 +113,7 @@ impl Widget {
}
// Getters
pub fn application_window(&self) -> &ApplicationWindow {
&self.application_window
pub fn gobject(&self) -> &ApplicationWindow {
&self.gobject
}
}

View file

@ -1,14 +1,16 @@
mod tab;
mod widget;
use tab::Tab;
use widget::Widget;
use std::sync::Arc;
use tab::Tab;
use gtk::{gio::SimpleAction, glib::GString, prelude::BoxExt, Box, Orientation};
use gtk::{gio::SimpleAction, glib::GString, Box};
pub struct Window {
tab: Arc<Tab>,
widget: Box,
widget: Arc<Widget>,
}
impl Window {
@ -32,9 +34,7 @@ impl Window {
tab.append(Some(GString::from("gemini://geminiprotocol.net/")), true); // demo tab @TODO replace with session restore feature
// GTK
let widget = Box::builder().orientation(Orientation::Vertical).build();
widget.append(tab.widget());
let widget = Arc::new(Widget::new(tab.widget()));
// Init struct
Self { tab, widget }
@ -86,7 +86,7 @@ impl Window {
self.tab.page_description()
}
pub fn widget(&self) -> &Box {
&self.widget
pub fn widget_gobject(&self) -> &Box {
&self.widget.gobject()
}
}

View file

@ -0,0 +1,20 @@
use gtk::{prelude::BoxExt, Box, Notebook, Orientation};
pub struct Widget {
gobject: Box,
}
impl Widget {
// Construct
pub fn new(tab: &Notebook) -> Self {
let gobject = Box::builder().orientation(Orientation::Vertical).build();
gobject.append(tab);
Self { gobject }
}
// Getters
pub fn gobject(&self) -> &Box {
&self.gobject
}
}