Check that a widget is being dragged before checking the event in graphview.

A bug in gtk4-rs makes the library print errors when accessing an event, this change reduces the amount of errors, as they are only printed when the mouse is over a node now.
This commit is contained in:
Tom A. Wagner
2021-01-08 09:57:25 +01:00
parent 323e1a2a8f
commit 4744a1a647

View File

@@ -44,24 +44,26 @@ mod imp {
fn constructed(&self, obj: &Self::Type) {
self.parent_constructed(obj);
// Move the Node that is currently being dragged to the cursor position as long as Mouse Button 1 is held.
let motion_controller = gtk::EventControllerMotion::new();
motion_controller.connect_motion(|controller, x, y| {
if controller
.get_current_event()
.unwrap()
.get_modifier_state()
.contains(gdk::ModifierType::BUTTON1_MASK)
{
let instance = controller
.get_widget()
.unwrap()
.dynamic_cast::<Self::Type>()
.unwrap();
let this = imp::GraphView::from_instance(&instance);
if let Some(ref widget) = *this.dragged.borrow() {
this.move_node(&widget, x as f32, y as f32);
};
if controller
.get_current_event()
.unwrap()
.get_modifier_state()
.contains(gdk::ModifierType::BUTTON1_MASK)
{
instance.move_node(&widget, x as f32, y as f32);
}
};
});
obj.add_controller(&motion_controller);
}