mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 17:20:08 +00:00
delegate event implementation to label, fix target for label click controller
This commit is contained in:
parent
22d8d147e3
commit
94d56fec4a
@ -11,8 +11,7 @@ use sqlite::Transaction;
|
||||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
glib::{uuid_string_random, GString},
|
||||
prelude::WidgetExt,
|
||||
Box, GestureClick,
|
||||
Box,
|
||||
};
|
||||
|
||||
use std::sync::Arc;
|
||||
@ -56,21 +55,6 @@ impl Item {
|
||||
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
|
||||
Self {
|
||||
id,
|
||||
|
@ -9,7 +9,7 @@ use sqlite::Transaction;
|
||||
use title::Title;
|
||||
use widget::Widget;
|
||||
|
||||
use gtk::{glib::GString, Box};
|
||||
use gtk::{glib::GString, prelude::WidgetExt, Box, GestureClick};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct Label {
|
||||
@ -23,13 +23,55 @@ pub struct Label {
|
||||
impl Label {
|
||||
// Construct
|
||||
pub fn new(name: GString, is_pinned: bool) -> Label {
|
||||
// Components
|
||||
// Init components
|
||||
let pin = Arc::new(Pin::new(is_pinned));
|
||||
let title = Arc::new(Title::new());
|
||||
|
||||
// GTK
|
||||
// Init GTK
|
||||
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
|
||||
Self { pin, title, widget }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user