Update dependencies

This commit is contained in:
Tom A. Wagner
2021-05-08 18:42:49 +02:00
parent 1c69dc85fb
commit a5d8c871ee
6 changed files with 106 additions and 139 deletions

View File

@@ -72,8 +72,8 @@ mod imp {
.child(&scrollwindow)
.build();
window
.get_settings()
.set_property_gtk_application_prefer_dark_theme(true);
.settings()
.set_gtk_application_prefer_dark_theme(true);
window.show();
}
@@ -84,7 +84,7 @@ mod imp {
let provider = gtk::CssProvider::new();
provider.load_from_data(STYLE.as_bytes());
gtk::StyleContext::add_provider_for_display(
&gtk::gdk::Display::get_default().expect("Error initializing gtk css provider."),
&gtk::gdk::Display::default().expect("Error initializing gtk css provider."),
&provider,
gtk::STYLE_PROVIDER_PRIORITY_APPLICATION,
);
@@ -197,8 +197,8 @@ impl Application {
false,
clone!(@weak self as app => @default-return None, move |args| {
// Args always look like this: &[widget, id_port_from, id_port_to]
let port_from = args[1].get_some::<u32>().unwrap();
let port_to = args[2].get_some::<u32>().unwrap();
let port_from = args[1].get::<u32>().unwrap();
let port_to = args[2].get::<u32>().unwrap();
app.toggle_link(port_from, port_to);

View File

@@ -62,7 +62,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let app = application::Application::new(gtk_receiver, pw_sender.clone());
app.run(&std::env::args().collect::<Vec<_>>());
app.run();
pw_sender
.send(GtkMessage::Terminate)

View File

@@ -1,16 +1,16 @@
use super::Node;
use gtk::{glib, graphene, gsk, prelude::*, subclass::prelude::*, WidgetExt};
use gtk::{gdk, glib, graphene, gsk, prelude::*, subclass::prelude::*};
use std::collections::HashMap;
mod imp {
use super::*;
use gtk::{gdk, WidgetExt};
use std::{cell::RefCell, rc::Rc};
use log::warn;
#[derive(Default)]
pub struct GraphView {
pub(super) nodes: RefCell<HashMap<u32, Node>>,
@@ -38,7 +38,7 @@ mod imp {
let motion_controller = gtk::EventControllerMotion::new();
motion_controller.connect_motion(|controller, x, y| {
let instance = controller
.get_widget()
.widget()
.unwrap()
.dynamic_cast::<Self::Type>()
.unwrap();
@@ -46,9 +46,9 @@ mod imp {
if let Some(ref widget) = *this.dragged.borrow() {
if controller
.get_current_event()
.current_event()
.unwrap()
.get_modifier_state()
.modifier_state()
.contains(gdk::ModifierType::BUTTON1_MASK)
{
instance.move_node(&widget, x as f32, y as f32);
@@ -71,7 +71,7 @@ mod imp {
/* FIXME: A lot of hardcoded values in here.
Try to use relative units (em) and colours from the theme as much as possible. */
let alloc = widget.get_allocation();
let alloc = widget.allocation();
let cr = snapshot
.append_cairo(&graphene::Rect::new(
@@ -83,9 +83,11 @@ mod imp {
.expect("Failed to get cairo context");
// Try to replace the background color with a darker one from the theme.
if let Some(rgba) = widget.get_style_context().lookup_color("text_view_bg") {
if let Some(rgba) = widget.style_context().lookup_color("text_view_bg") {
cr.set_source_rgb(rgba.red.into(), rgba.green.into(), rgba.blue.into());
cr.paint();
if let Err(e) = cr.paint() {
warn!("Failed to paint graphview background: {}", e);
};
} // TODO: else log colour not found
// Draw a nice grid on the background.
@@ -103,7 +105,9 @@ mod imp {
cr.line_to(x, alloc.height as f64);
x += 20.0; // TODO: Change to em;
}
cr.stroke();
if let Err(e) = cr.stroke() {
warn!("Failed to draw graphview grid: {}", e);
};
// Draw all links
cr.set_line_width(2.0);
@@ -112,7 +116,9 @@ mod imp {
if let Some((from_x, from_y, to_x, to_y)) = self.get_link_coordinates(link) {
cr.move_to(from_x, from_y);
cr.curve_to(from_x + 75.0, from_y, to_x - 75.0, to_y, to_x, to_y);
cr.stroke();
if let Err(e) = cr.stroke() {
warn!("Failed to draw graphview links: {}", e);
};
} else {
log::warn!("Could not get allocation of ports of link: {:?}", link);
}
@@ -122,7 +128,7 @@ mod imp {
self.nodes
.borrow()
.values()
.for_each(|node| self.get_instance().snapshot_child(node, snapshot));
.for_each(|node| self.instance().snapshot_child(node, snapshot));
}
}
@@ -143,11 +149,11 @@ mod imp {
y: mut fy,
width: fw,
height: fh,
} = from_port.get_allocation();
} = from_port.allocation();
let from_node = from_port
.get_ancestor(Node::static_type())
.ancestor(Node::static_type())
.expect("Port is not a child of a node");
let gtk::Allocation { x: fnx, y: fny, .. } = from_node.get_allocation();
let gtk::Allocation { x: fnx, y: fny, .. } = from_node.allocation();
fx += fnx + fw;
fy += fny + (fh / 2);
@@ -157,11 +163,11 @@ mod imp {
y: mut ty,
height: th,
..
} = to_port.get_allocation();
} = to_port.allocation();
let to_node = to_port
.get_ancestor(Node::static_type())
.ancestor(Node::static_type())
.expect("Port is not a child of a node");
let gtk::Allocation { x: tnx, y: tny, .. } = to_node.get_allocation();
let gtk::Allocation { x: tnx, y: tny, .. } = to_node.allocation();
tx += tnx;
ty += tny + (th / 2);
@@ -249,7 +255,7 @@ impl GraphView {
pub(super) fn move_node(&self, node: &gtk::Widget, x: f32, y: f32) {
let layout_manager = self
.get_layout_manager()
.layout_manager()
.expect("Failed to get layout manager")
.dynamic_cast::<gtk::FixedLayout>()
.expect("Failed to cast to FixedLayout");
@@ -260,7 +266,7 @@ impl GraphView {
.unwrap();
layout_manager
.get_layout_child(node)
.layout_child(node)
.expect("Could not get layout child")
.dynamic_cast::<gtk::FixedLayoutChild>()
.expect("Could not cast to FixedLayoutChild")

View File

@@ -1,6 +1,6 @@
use super::graph_view::GraphView;
use gtk::{glib, prelude::*, subclass::prelude::*, WidgetExt};
use gtk::{glib, prelude::*, subclass::prelude::*};
use pipewire::spa::Direction;
use std::{collections::HashMap, rc::Rc};
@@ -38,12 +38,12 @@ mod imp {
motion_controller.connect_enter(|controller, _, _| {
// Tell the graphview that the Node is the target of a drag when the mouse enters its label
let widget = controller
.get_widget()
.widget()
.expect("Controller with enter event has no widget")
.get_ancestor(super::Node::static_type())
.ancestor(super::Node::static_type())
.expect("Node label does not have a node ancestor widget");
widget
.get_ancestor(GraphView::static_type())
.ancestor(GraphView::static_type())
.expect("Node with enter event is not on graph")
.dynamic_cast::<GraphView>()
.unwrap()
@@ -53,9 +53,9 @@ mod imp {
// Tell the graphview that the Node is no longer the target of a drag when the mouse leaves.
// FIXME: Check that we are the current target before setting none.
controller
.get_widget()
.widget()
.expect("Controller with leave event has no widget")
.get_ancestor(GraphView::static_type())
.ancestor(GraphView::static_type())
.expect("Node with leave event is not on graph")
.dynamic_cast::<GraphView>()
.unwrap()

View File

@@ -80,11 +80,10 @@ impl Port {
let drop_target = gtk::DropTarget::new(u32::static_type(), gdk::DragAction::COPY);
let this = res.clone();
drop_target.connect_drop(move |drop_target, val, _, _| {
if let Some(source_id) = val.downcast_ref::<u32>() {
if let Ok(source_id) = val.get::<u32>() {
// Get the callback registered in the widget and call it
let source_id = source_id.get_some();
drop_target
.get_widget()
.widget()
.expect("Drop target has no widget")
.emit_by_name("port-toggled", &[&source_id, &this.id()])
.expect("Failed to send signal");
@@ -99,7 +98,7 @@ impl Port {
Direction::Output => {
// The port will simply provide its pipewire id to the drag target.
let drag_src = gtk::DragSourceBuilder::new()
.content(&gdk::ContentProvider::new_for_value(&(id.to_value())))
.content(&gdk::ContentProvider::for_value(&(id.to_value())))
.build();
res.add_controller(&drag_src);
}