mirror of
https://gitlab.freedesktop.org/pipewire/helvum
synced 2026-03-15 19:46:10 +08:00
graphview: Draw links in front of nodes, instead of behind them.
This commit is contained in:
@@ -96,7 +96,7 @@ mod imp {
|
|||||||
|
|
||||||
let alloc = widget.allocation();
|
let alloc = widget.allocation();
|
||||||
|
|
||||||
let cr = snapshot
|
let background_cr = snapshot
|
||||||
.append_cairo(&graphene::Rect::new(
|
.append_cairo(&graphene::Rect::new(
|
||||||
0.0,
|
0.0,
|
||||||
0.0,
|
0.0,
|
||||||
@@ -107,51 +107,59 @@ mod imp {
|
|||||||
|
|
||||||
// Try to replace the background color with a darker one from the theme.
|
// Try to replace the background color with a darker one from the theme.
|
||||||
if let Some(rgba) = widget.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());
|
background_cr.set_source_rgb(rgba.red.into(), rgba.green.into(), rgba.blue.into());
|
||||||
if let Err(e) = cr.paint() {
|
if let Err(e) = background_cr.paint() {
|
||||||
warn!("Failed to paint graphview background: {}", e);
|
warn!("Failed to paint graphview background: {}", e);
|
||||||
};
|
};
|
||||||
} // TODO: else log colour not found
|
} // TODO: else log colour not found
|
||||||
|
|
||||||
// Draw a nice grid on the background.
|
// Draw a nice grid on the background.
|
||||||
cr.set_source_rgb(0.18, 0.18, 0.18);
|
background_cr.set_source_rgb(0.18, 0.18, 0.18);
|
||||||
cr.set_line_width(0.2); // TODO: Set to 1px
|
background_cr.set_line_width(0.2); // TODO: Set to 1px
|
||||||
let mut y = 0.0;
|
let mut y = 0.0;
|
||||||
while y < alloc.height.into() {
|
while y < alloc.height.into() {
|
||||||
cr.move_to(0.0, y);
|
background_cr.move_to(0.0, y);
|
||||||
cr.line_to(alloc.width.into(), y);
|
background_cr.line_to(alloc.width.into(), y);
|
||||||
y += 20.0; // TODO: Change to em;
|
y += 20.0; // TODO: Change to em;
|
||||||
}
|
}
|
||||||
let mut x = 0.0;
|
let mut x = 0.0;
|
||||||
while x < alloc.width.into() {
|
while x < alloc.width.into() {
|
||||||
cr.move_to(x, 0.0);
|
background_cr.move_to(x, 0.0);
|
||||||
cr.line_to(x, alloc.height.into());
|
background_cr.line_to(x, alloc.height.into());
|
||||||
x += 20.0; // TODO: Change to em;
|
x += 20.0; // TODO: Change to em;
|
||||||
}
|
}
|
||||||
if let Err(e) = cr.stroke() {
|
if let Err(e) = background_cr.stroke() {
|
||||||
warn!("Failed to draw graphview grid: {}", e);
|
warn!("Failed to draw graphview grid: {}", e);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Draw all links
|
|
||||||
cr.set_line_width(2.0);
|
|
||||||
cr.set_source_rgb(0.0, 0.0, 0.0);
|
|
||||||
for link in self.links.borrow().values() {
|
|
||||||
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);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw all children
|
// Draw all children
|
||||||
self.nodes
|
self.nodes
|
||||||
.borrow()
|
.borrow()
|
||||||
.values()
|
.values()
|
||||||
.for_each(|node| self.instance().snapshot_child(node, snapshot));
|
.for_each(|node| self.instance().snapshot_child(node, snapshot));
|
||||||
|
|
||||||
|
// Draw all links
|
||||||
|
let link_cr = snapshot
|
||||||
|
.append_cairo(&graphene::Rect::new(
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
alloc.width as f32,
|
||||||
|
alloc.height as f32,
|
||||||
|
))
|
||||||
|
.expect("Failed to get cairo context");
|
||||||
|
link_cr.set_line_width(2.0);
|
||||||
|
link_cr.set_source_rgb(0.0, 0.0, 0.0);
|
||||||
|
for link in self.links.borrow().values() {
|
||||||
|
if let Some((from_x, from_y, to_x, to_y)) = self.get_link_coordinates(link) {
|
||||||
|
link_cr.move_to(from_x, from_y);
|
||||||
|
link_cr.curve_to(from_x + 75.0, from_y, to_x - 75.0, to_y, to_x, to_y);
|
||||||
|
if let Err(e) = link_cr.stroke() {
|
||||||
|
warn!("Failed to draw graphview links: {}", e);
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
log::warn!("Could not get allocation of ports of link: {:?}", link);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user