From 49e18b26478bc4297242b26bd8269dd1c5e9d521 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Thu, 10 Jun 2021 00:05:49 +0100 Subject: [PATCH] dev: Render labels last (so they are always the top layer) --- src/dev/graph/layout.rs | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/dev/graph/layout.rs b/src/dev/graph/layout.rs index 507ab743..1dac93e1 100644 --- a/src/dev/graph/layout.rs +++ b/src/dev/graph/layout.rs @@ -70,8 +70,6 @@ impl CircuitLayout { use plotters::coord::types::RangedCoordusize; use plotters::prelude::*; - let show_labels = !self.hide_labels; - // Collect the layout details. let mut cs = ConstraintSystem::default(); let config = ConcreteCircuit::configure(&mut cs); @@ -122,18 +120,12 @@ impl CircuitLayout { &BLACK, ))?; - let draw_region = |root: &DrawingArea<_, _>, top_left, bottom_right, label| { + let draw_region = |root: &DrawingArea<_, _>, top_left, bottom_right| { root.draw(&Rectangle::new( [top_left, bottom_right], ShapeStyle::from(&GREEN.mix(0.2)).filled(), ))?; root.draw(&Rectangle::new([top_left, bottom_right], &BLACK))?; - if show_labels { - root.draw( - &(EmptyElement::at(top_left) - + Text::new(label, (10, 10), ("sans-serif", 15.0).into_font())), - )?; - } Ok(()) }; @@ -145,6 +137,7 @@ impl CircuitLayout { }; // Render the regions! + let mut labels = if self.hide_labels { None } else { Some(vec![]) }; for region in layout.regions { if let Some(offset) = region.offset { // Sort the region's columns according to the defined ordering. @@ -158,12 +151,10 @@ impl CircuitLayout { match width { Some((start, end)) if end == column => width = Some((start, end + 1)), Some((start, end)) => { - draw_region( - &root, - (start, offset), - (end, offset + region.rows), - region.name.clone(), - )?; + draw_region(&root, (start, offset), (end, offset + region.rows))?; + if let Some(labels) = &mut labels { + labels.push((region.name.clone(), (start, offset))); + } width = Some((column, column + 1)); } None => width = Some((column, column + 1)), @@ -172,12 +163,10 @@ impl CircuitLayout { // Render the last part of the region. if let Some((start, end)) = width { - draw_region( - &root, - (start, offset), - (end, offset + region.rows), - region.name.clone(), - )?; + draw_region(&root, (start, offset), (end, offset + region.rows))?; + if let Some(labels) = &mut labels { + labels.push((region.name.clone(), (start, offset))); + } } // Darken the cells of the region that have been assigned to. @@ -192,6 +181,15 @@ impl CircuitLayout { draw_cell(&root, column_index(&column), row)?; } + // Render labels last, on top of everything else. + if let Some(labels) = labels { + for (label, top_left) in labels { + root.draw( + &(EmptyElement::at(top_left) + + Text::new(label, (10, 10), ("sans-serif", 15.0).into_font())), + )?; + } + } Ok(()) } }