connect back/forward navigation buttons

This commit is contained in:
yggverse 2025-03-04 08:15:33 +02:00
parent 0940c81b01
commit 67bcf90390
2 changed files with 21 additions and 7 deletions

View file

@ -36,7 +36,7 @@ impl Browser {
// Init widget // Init widget
let widget = Rc::new(Widget::new( let widget = Rc::new(Widget::new(
&window.g_box, &window,
&[ &[
// action groups // action groups
( (

View file

@ -1,12 +1,14 @@
mod database; mod database;
use super::Window;
use adw::ApplicationWindow; use adw::ApplicationWindow;
use gtk::{ use gtk::{
gio::SimpleActionGroup, gio::SimpleActionGroup,
glib::GString, glib::GString,
prelude::{GtkWindowExt, IsA, WidgetExt}, prelude::{GtkWindowExt, WidgetExt},
}; };
use sqlite::Transaction; use sqlite::Transaction;
use std::rc::Rc;
// Default options // Default options
const DEFAULT_HEIGHT: i32 = 480; const DEFAULT_HEIGHT: i32 = 480;
@ -19,13 +21,10 @@ pub struct Widget {
impl Widget { impl Widget {
// Construct // Construct
pub fn new( pub fn new(window: &Rc<Window>, action_groups: &[(&GString, SimpleActionGroup)]) -> Self {
content: &impl IsA<gtk::Widget>,
action_groups: &[(&GString, SimpleActionGroup)],
) -> Self {
// Init GTK // Init GTK
let application_window = ApplicationWindow::builder() let application_window = ApplicationWindow::builder()
.content(content) .content(&window.g_box)
.default_height(DEFAULT_HEIGHT) .default_height(DEFAULT_HEIGHT)
.default_width(DEFAULT_WIDTH) .default_width(DEFAULT_WIDTH)
.maximized(MAXIMIZED) .maximized(MAXIMIZED)
@ -36,6 +35,21 @@ impl Widget {
application_window.insert_action_group(name, Some(group)); application_window.insert_action_group(name, Some(group));
} }
// Connect back/forward navigation buttons @TODO use constant
application_window.add_controller({
use gtk::prelude::GestureSingleExt;
let button_controller = gtk::GestureClick::builder().button(0).build();
button_controller.connect_pressed({
let window = window.clone();
move |this, _, _, _| match this.current_button() {
8 => window.tab.history_back(None),
9 => window.tab.history_forward(None),
_ => {}
}
});
button_controller
});
// Return new struct // Return new struct
Self { application_window } Self { application_window }
} }