Browse Source

delegate event implementation to label, fix target for label click controller

master
yggverse 2 months ago
parent
commit
94d56fec4a
  1. 18
      src/app/browser/window/tab/item.rs
  2. 48
      src/app/browser/window/tab/item/label.rs

18
src/app/browser/window/tab/item.rs

@ -11,8 +11,7 @@ use sqlite::Transaction;
use gtk::{ use gtk::{
gio::SimpleAction, gio::SimpleAction,
glib::{uuid_string_random, GString}, glib::{uuid_string_random, GString},
prelude::WidgetExt, Box,
Box, GestureClick,
}; };
use std::sync::Arc; use std::sync::Arc;
@ -56,21 +55,6 @@ impl Item {
action_update.clone(), action_update.clone(),
)); ));
// Init additional label actions @TODO move to Label?
let controller = GestureClick::new();
controller.connect_pressed({
let label = label.clone();
move |_, count, _, _| {
// double click
if count == 2 {
label.pin(!label.is_pinned()); // toggle
}
}
});
label.gobject().add_controller(controller);
// Return struct // Return struct
Self { Self {
id, id,

48
src/app/browser/window/tab/item/label.rs

@ -9,7 +9,7 @@ use sqlite::Transaction;
use title::Title; use title::Title;
use widget::Widget; use widget::Widget;
use gtk::{glib::GString, Box}; use gtk::{glib::GString, prelude::WidgetExt, Box, GestureClick};
use std::sync::Arc; use std::sync::Arc;
pub struct Label { pub struct Label {
@ -23,13 +23,55 @@ pub struct Label {
impl Label { impl Label {
// Construct // Construct
pub fn new(name: GString, is_pinned: bool) -> Label { pub fn new(name: GString, is_pinned: bool) -> Label {
// Components // Init components
let pin = Arc::new(Pin::new(is_pinned)); let pin = Arc::new(Pin::new(is_pinned));
let title = Arc::new(Title::new()); let title = Arc::new(Title::new());
// GTK // Init GTK
let widget = Arc::new(Widget::new(name, pin.gobject(), title.gobject())); let widget = Arc::new(Widget::new(name, pin.gobject(), title.gobject()));
// Init events:
// Await for widget realize to continue this feature
widget.gobject().connect_realize({
let pin = pin.clone();
let title = title.clone();
let widget = widget.clone();
move |_| {
// Init GestureClick listener
let controller = GestureClick::new();
// Listen for double click
controller.connect_pressed({
let pin = pin.clone();
let title = title.clone();
move |_, count, _, _| {
if count == 2 {
// Toggle pin @TODO use action?
let is_pinned = !pin.is_pinned();
pin.pin(is_pinned);
title.pin(is_pinned);
}
}
});
// Label's parent contain native GTK paddings, that makes click event ignored
// try assign the controller to parent as the solution
match widget.gobject().parent() {
// @TODO check for GtkGizmo type?
Some(parent) => {
parent.add_controller(controller);
}
// Assign controller to the current widget, drop notice
None => {
widget.gobject().add_controller(controller);
println!("Could not assign action to destination, please report");
// @TODO
}
}
}
});
// Result // Result
Self { pin, title, widget } Self { pin, title, widget }
} }

Loading…
Cancel
Save