diff --git a/crates/tek/src/sampler/sample_viewer.rs b/crates/tek/src/sampler/sample_viewer.rs index cb54d0db..3ad94263 100644 --- a/crates/tek/src/sampler/sample_viewer.rs +++ b/crates/tek/src/sampler/sample_viewer.rs @@ -2,23 +2,41 @@ use crate::*; use std::ops::Deref; use ratatui::{prelude::Rect, widgets::{Widget, canvas::{Canvas, Points}}}; +const EMPTY: &[(f64, f64)] = &[(0., 0.), (1., 1.), (2., 2.), (0., 2.), (2., 0.)]; + pub struct SampleViewer(pub Option>>); render!(|self: SampleViewer|render(|to|{ let [x, y, width, height] = to.area(); let area = Rect { x, y, width, height }; + let mut points = vec![]; let (x_bounds, y_bounds, coords): ([f64;2], [f64;2], &[(f64,f64)]) = if let Some(sample) = &self.0 { let sample = sample.read().unwrap(); + let start = sample.start as f64; + let end = sample.end as f64; + let length = end - start; + let step = length / width as f64; + let mut t = start; + while t < end { + points.push((t as f64, 0.)); + points.push((t as f64, 1.)); + points.push((t as f64, 0.5)); + points.push((t as f64, 0.25)); + points.push((t as f64, 0.125)); + points.push((t as f64, 0.0625)); + points.push((t as f64, 0.03125)); + t += step; + } ( [sample.start as f64, sample.end as f64], - [0 as f64, f32::MAX as f64], - &[] + [0., 1.], + points.as_slice() ) } else { ( [0.0, f64::from(width)], [0.0, f64::from(height)], - &[(0., 0.), (1., 1.), (2., 2.), (0., 2.), (2., 0.)] + EMPTY ) }; Canvas::default().x_bounds(x_bounds).y_bounds(y_bounds).paint(|ctx|{