mirror of
https://gitlab.freedesktop.org/pipewire/helvum
synced 2026-03-15 11:36:11 +08:00
Switch to gtk4
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
use gdk::prelude::*;
|
||||
use gtk::prelude::*;
|
||||
use std::collections::HashMap;
|
||||
use super::graph_view::GraphView;
|
||||
|
||||
use pipewire::port::Direction;
|
||||
use gtk::prelude::*;
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub struct Node {
|
||||
pub(super) widget: gtk::Grid,
|
||||
label: gtk::Label,
|
||||
label_box: gtk::EventBox,
|
||||
ports: HashMap<u32, super::port::Port>,
|
||||
num_ports_in: u32,
|
||||
num_ports_out: u32,
|
||||
@@ -18,51 +18,41 @@ impl Node {
|
||||
let result = Self {
|
||||
widget: gtk::Grid::new(),
|
||||
label: gtk::Label::new(Some(name)),
|
||||
label_box: gtk::EventBox::new(),
|
||||
ports: HashMap::new(),
|
||||
num_ports_in: 0,
|
||||
num_ports_out: 0,
|
||||
};
|
||||
|
||||
result.label_box.add(&result.label);
|
||||
result.widget.attach(&result.label_box, 0, 0, 2, 1);
|
||||
let motion_controller = gtk::EventControllerMotion::new();
|
||||
// Tell the graphview that the Node is the target of a drag when the mouse enters its label
|
||||
motion_controller.connect_enter(|controller, _, _| {
|
||||
let widget = controller
|
||||
.get_widget()
|
||||
.expect("Controller with enter event has no widget")
|
||||
.get_ancestor(gtk::Grid::static_type())
|
||||
.unwrap();
|
||||
widget
|
||||
.get_ancestor(GraphView::static_type())
|
||||
.unwrap()
|
||||
.dynamic_cast::<GraphView>()
|
||||
.unwrap()
|
||||
.set_dragged(Some(widget));
|
||||
});
|
||||
// Tell the graphview that the Node is no longer the target of a drag when the mouse leaves.
|
||||
motion_controller.connect_leave(|controller| {
|
||||
// FIXME: Check that we are the current target before setting none.
|
||||
controller
|
||||
.get_widget()
|
||||
.expect("Controller with leave event has no widget")
|
||||
.get_ancestor(GraphView::static_type())
|
||||
.unwrap()
|
||||
.dynamic_cast::<GraphView>()
|
||||
.unwrap()
|
||||
.set_dragged(None);
|
||||
});
|
||||
result.label.add_controller(&motion_controller);
|
||||
|
||||
// Setup needed events for dragging a node.
|
||||
result
|
||||
.label_box
|
||||
.add_events(gdk::EventMask::BUTTON1_MOTION_MASK);
|
||||
|
||||
// Setup callback for dragging the node.
|
||||
result
|
||||
.label_box
|
||||
.connect_motion_notify_event(|label, event| {
|
||||
let node_frame = label
|
||||
.get_ancestor(gtk::Grid::static_type())
|
||||
.unwrap()
|
||||
.dynamic_cast::<gtk::Grid>()
|
||||
.unwrap();
|
||||
let graphview = node_frame
|
||||
.get_ancestor(gtk::Layout::static_type())
|
||||
.unwrap()
|
||||
.dynamic_cast::<gtk::Layout>()
|
||||
.unwrap();
|
||||
|
||||
// Use root coordinates to prevent jumping around
|
||||
// as moving the widget also influences the relative coordinates.
|
||||
let (x, y) = event.get_root();
|
||||
let (offset_x, offset_y) = graphview.get_window().unwrap().get_root_origin();
|
||||
|
||||
// TODO: Calculate proper values to center the mouse on the label
|
||||
// instead of using hardcoded offsets.
|
||||
graphview.set_child_x(&node_frame, x as i32 - offset_x - 100);
|
||||
graphview.set_child_y(&node_frame, y as i32 - offset_y - 50);
|
||||
|
||||
// FIXME: If links become proper widgets,
|
||||
// we don't need to redraw the full graph everytime.
|
||||
graphview.queue_draw();
|
||||
|
||||
Inhibit(true)
|
||||
});
|
||||
result.widget.attach(&result.label, 0, 0, 2, 1);
|
||||
|
||||
result
|
||||
}
|
||||
@@ -81,7 +71,6 @@ impl Node {
|
||||
}
|
||||
}
|
||||
|
||||
port.widget.show_all();
|
||||
self.ports.insert(id, port);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user