From f09a6072f8faef782e9bcda57c7eb7d4956a4743 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Sat, 28 Dec 2024 18:55:58 +0100 Subject: [PATCH] draw x for no sample --- crates/tek/src/sampler/sample_viewer.rs | 29 +++++++++++++++---------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/crates/tek/src/sampler/sample_viewer.rs b/crates/tek/src/sampler/sample_viewer.rs index 3dcedb51..00d3e35e 100644 --- a/crates/tek/src/sampler/sample_viewer.rs +++ b/crates/tek/src/sampler/sample_viewer.rs @@ -6,16 +6,23 @@ pub struct SampleViewer<'a>(pub Option<&'a Arc>>); render!(|self: SampleViewer<'a>|render(|to|{ let [x, y, width, height] = to.area(); let area = Rect { x, y, width, height }; - Canvas::default() - .x_bounds([0.0, f64::from(width)]) - .y_bounds([0.0, f64::from(height)]) - .paint(|ctx|{ - ctx.draw(&Points { - coords: &[(0., 0.), (1., 2.), (3., 4.)], - color: Color::Rgb(255,0,0) - }) - // TODO - }) - .render(area, &mut to.buffer); + let (x_bounds, y_bounds, coords): ([f64;2], [f64;2], &[(f64,f64)]) = + if let Some(sample) = self.0 { + let sample = sample.read().unwrap(); + ( + [sample.start as f64, sample.end as f64], + [0 as f64, f32::MAX as f64], + &[] + ) + } else { + ( + [0.0, f64::from(width)], + [0.0, f64::from(height)], + &[(0., 0.), (1., 1.), (2., 2.), (0., 2.), (2., 0.)] + ) + }; + Canvas::default().x_bounds(x_bounds).y_bounds(y_bounds).paint(|ctx|{ + ctx.draw(&Points { coords, color: Color::Rgb(255,0,0) }) + }).render(area, &mut to.buffer); Ok(()) }));