view: Refactor view to have a manager View struct.

The view struct creates, manages and runs the view, and handles all communication with components outside of the view.
This commit is contained in:
Tom A. Wagner
2021-03-30 19:57:05 +02:00
parent 48821be18d
commit 2cb155c5ee
4 changed files with 172 additions and 108 deletions

View File

@@ -202,7 +202,7 @@ impl GraphView {
}
}
pub fn add_port_to_node(&self, node_id: u32, port_id: u32, port: crate::view::port::Port) {
pub fn add_port(&self, node_id: u32, port_id: u32, port: crate::view::port::Port) {
let private = imp::GraphView::from_instance(self);
if let Some(node) = private.nodes.borrow_mut().get_mut(&node_id) {
@@ -217,6 +217,14 @@ impl GraphView {
}
}
pub fn remove_port(&self, id: u32, node_id: u32) {
let private = imp::GraphView::from_instance(self);
let nodes = private.nodes.borrow();
if let Some(node) = nodes.get(&node_id) {
node.remove_port(id);
}
}
/// Add a link to the graph.
///
/// `add_link` takes three arguments: `link_id` is the id of the link as assigned by the pipewire server,
@@ -235,11 +243,11 @@ impl GraphView {
self.queue_draw();
}
pub fn set_dragged(&self, widget: Option<gtk::Widget>) {
pub(super) fn set_dragged(&self, widget: Option<gtk::Widget>) {
*imp::GraphView::from_instance(self).dragged.borrow_mut() = widget;
}
pub fn move_node(&self, node: &gtk::Widget, x: f32, y: f32) {
pub(super) fn move_node(&self, node: &gtk::Widget, x: f32, y: f32) {
let layout_manager = self
.get_layout_manager()
.expect("Failed to get layout manager")