mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
define browser entities as structs
This commit is contained in:
parent
3fbfe6a7e0
commit
c0ebe95eb8
4 changed files with 84 additions and 40 deletions
|
|
@ -1,14 +1,34 @@
|
||||||
mod tab;
|
mod tab;
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use gtk::prelude::BoxExt;
|
use gtk::prelude::BoxExt;
|
||||||
use gtk::Box;
|
use gtk::Box;
|
||||||
|
|
||||||
pub fn new() -> Box {
|
pub struct Main {
|
||||||
let main = Box::builder()
|
pub widget: Arc<gtk::Box>,
|
||||||
.orientation(gtk::Orientation::Vertical)
|
pub tab: Arc<tab::Tab>,
|
||||||
.build();
|
}
|
||||||
|
|
||||||
main.append(&tab::new());
|
impl Main {
|
||||||
|
pub fn tab_append(&self) {
|
||||||
main
|
self.tab.append(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new() -> Main {
|
||||||
|
// Init components
|
||||||
|
let tab = Arc::new(tab::new());
|
||||||
|
|
||||||
|
// Init widget
|
||||||
|
let widget = Arc::new(
|
||||||
|
Box::builder()
|
||||||
|
.orientation(gtk::Orientation::Vertical)
|
||||||
|
.build(),
|
||||||
|
);
|
||||||
|
|
||||||
|
widget.append(tab.widget.as_ref());
|
||||||
|
|
||||||
|
// Init struct
|
||||||
|
Main { widget, tab }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,27 +1,31 @@
|
||||||
mod label;
|
mod label;
|
||||||
mod page;
|
mod page;
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use gtk::Notebook;
|
use gtk::Notebook;
|
||||||
|
pub struct Tab {
|
||||||
pub fn new() -> Notebook {
|
pub widget: Arc<gtk::Notebook>,
|
||||||
let tab = Notebook::builder().scrollable(true).build();
|
|
||||||
|
|
||||||
// Add test tab @TODO restore from session
|
|
||||||
append(&tab, true);
|
|
||||||
|
|
||||||
tab
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn append(tab: &Notebook, current: bool) -> u32 {
|
impl Tab {
|
||||||
let page = page::new();
|
pub fn append(&self, current: bool) -> u32 {
|
||||||
|
let page = page::new();
|
||||||
|
|
||||||
let page_number = tab.append_page(&page, Some(&label::new()));
|
let page_number = self.widget.append_page(&page, Some(&label::new()));
|
||||||
|
|
||||||
tab.set_tab_reorderable(&page, true);
|
self.widget.set_tab_reorderable(&page, true);
|
||||||
|
|
||||||
if current {
|
if current {
|
||||||
tab.set_current_page(Some(page_number));
|
self.widget.set_current_page(Some(page_number));
|
||||||
|
}
|
||||||
|
|
||||||
|
page_number
|
||||||
}
|
}
|
||||||
|
}
|
||||||
page_number
|
|
||||||
|
pub fn new() -> Tab {
|
||||||
|
let widget = Arc::new(Notebook::builder().scrollable(true).build());
|
||||||
|
|
||||||
|
Tab { widget }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
mod header;
|
mod header;
|
||||||
mod main;
|
mod main;
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gio::ActionEntry,
|
gio::ActionEntry,
|
||||||
prelude::{ActionMapExtManual, GtkWindowExt},
|
prelude::{ActionMapExtManual, GtkWindowExt},
|
||||||
|
|
@ -8,32 +10,50 @@ use gtk::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use sqlite::Connection;
|
use sqlite::Connection;
|
||||||
|
pub struct Browser {
|
||||||
|
pub widget: Arc<ApplicationWindow>,
|
||||||
|
pub main: Arc<main::Main>,
|
||||||
|
}
|
||||||
|
|
||||||
pub fn new(app: &Application, db: &Connection, width: i32, height: i32) -> ApplicationWindow {
|
pub fn new(app: &Application, db: &Connection, width: i32, height: i32) -> Browser {
|
||||||
// Init browser window
|
// Init components
|
||||||
let browser = ApplicationWindow::builder()
|
let main = Arc::new(main::new());
|
||||||
.default_width(width)
|
|
||||||
.default_height(height)
|
// Init widget
|
||||||
.application(app)
|
let widget = Arc::new(
|
||||||
.titlebar(&header::new())
|
ApplicationWindow::builder()
|
||||||
.child(&main::new())
|
.default_width(width)
|
||||||
.build();
|
.default_height(height)
|
||||||
|
.application(app)
|
||||||
|
.titlebar(&header::new())
|
||||||
|
.child(main.widget.as_ref())
|
||||||
|
.build(),
|
||||||
|
);
|
||||||
|
|
||||||
// Init actions
|
// Init actions
|
||||||
|
let action_tab_append = ActionEntry::builder("tab_append")
|
||||||
|
.activate({
|
||||||
|
let main = main.clone();
|
||||||
|
move |_, _, _| {
|
||||||
|
main.tab_append();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.build();
|
||||||
|
|
||||||
let action_debug = ActionEntry::builder("debug")
|
let action_debug = ActionEntry::builder("debug")
|
||||||
.activate(|browser: &ApplicationWindow, _, _| {
|
.activate(|this: &ApplicationWindow, _, _| {
|
||||||
browser.emit_enable_debugging(true);
|
this.emit_enable_debugging(true);
|
||||||
})
|
})
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let action_quit = ActionEntry::builder("quit")
|
let action_quit = ActionEntry::builder("quit")
|
||||||
.activate(|browser: &ApplicationWindow, _, _| {
|
.activate(|this: &ApplicationWindow, _, _| {
|
||||||
browser.close();
|
this.close();
|
||||||
})
|
})
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
browser.add_action_entries([action_debug, action_quit]);
|
widget.add_action_entries([action_tab_append, action_debug, action_quit]);
|
||||||
|
|
||||||
// Done
|
// Done
|
||||||
browser
|
Browser { widget, main }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ fn main() -> glib::ExitCode {
|
||||||
};
|
};
|
||||||
|
|
||||||
move |this| {
|
move |this| {
|
||||||
browser::new(&this, &db, 640, 480).present();
|
browser::new(&this, &db, 640, 480).widget.present();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue