mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
render computed points
This commit is contained in:
parent
240c498a50
commit
080c4131b7
1 changed files with 21 additions and 3 deletions
|
|
@ -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<Arc<RwLock<Sample>>>);
|
||||
render!(<Tui>|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|{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue