delegate action registration to widget

This commit is contained in:
yggverse 2024-11-01 03:23:49 +02:00
parent 532ed65ed8
commit 157227cbfe
2 changed files with 28 additions and 18 deletions

View file

@ -3,7 +3,10 @@ mod database;
use database::Database;
use adw::ApplicationWindow;
use gtk::{prelude::GtkWindowExt, Box};
use gtk::{
gio::SimpleAction,
prelude::{ActionMapExt, GtkWindowExt, IsA},
};
use sqlite::Transaction;
// Default options
@ -17,7 +20,7 @@ pub struct Widget {
impl Widget {
// Construct
pub fn new(content: &Box) -> Self {
pub fn new(content: &impl IsA<gtk::Widget>, actions: &[SimpleAction]) -> Self {
// Init GTK
let gobject = ApplicationWindow::builder()
.content(content)
@ -26,6 +29,11 @@ impl Widget {
.maximized(MAXIMIZED)
.build();
// Register actions
for action in actions {
gobject.add_action(action);
}
// Return new struct
Self { gobject }
}