dev: Enable CircuitLayout labels to be hidden

This commit is contained in:
Jack Grigg 2021-06-08 12:16:02 +01:00
parent 52be437509
commit d4984ebf53
1 changed files with 18 additions and 4 deletions

View File

@ -35,11 +35,20 @@ use crate::plonk::{
/// ```
#[derive(Debug, Default)]
pub struct CircuitLayout {
hide_labels: bool,
view_width: Option<Range<usize>>,
view_height: Option<Range<usize>>,
}
impl CircuitLayout {
/// Sets the visibility of region labels.
///
/// The default is to show labels.
pub fn show_labels(mut self, show: bool) -> Self {
self.hide_labels = !show;
self
}
/// Sets the view width for this layout, as a number of columns.
pub fn view_width(mut self, width: Range<usize>) -> Self {
self.view_width = Some(width);
@ -61,6 +70,8 @@ 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);
@ -117,10 +128,13 @@ impl CircuitLayout {
ShapeStyle::from(&GREEN.mix(0.2)).filled(),
))?;
root.draw(&Rectangle::new([top_left, bottom_right], &BLACK))?;
root.draw(
&(EmptyElement::at(top_left)
+ Text::new(label, (10, 10), ("sans-serif", 15.0).into_font())),
)
if show_labels {
root.draw(
&(EmptyElement::at(top_left)
+ Text::new(label, (10, 10), ("sans-serif", 15.0).into_font())),
)?;
}
Ok(())
};
let draw_cell = |root: &DrawingArea<_, _>, column, row| {