sampler: replace red x with record instruction

This commit is contained in:
🪞👃🪞 2025-05-11 01:36:14 +03:00
parent b9c101081b
commit ee2efd1c26

View file

@ -137,7 +137,6 @@ fn draw_viewer (sample: Option<&Arc<RwLock<Sample>>>) -> impl Content<TuiOut> +
ThunkRender::new(move|to: &mut TuiOut|{
let [x, y, width, height] = to.area();
let area = Rect { x, y, width, height };
let (x_bounds, y_bounds, lines): ([f64;2], [f64;2], Vec<Line>) =
if let Some(sample) = &sample {
let sample = sample.read().unwrap();
let start = sample.start as f64;
@ -156,26 +155,35 @@ fn draw_viewer (sample: Option<&Arc<RwLock<Sample>>>) -> impl Content<TuiOut> +
lines.push(Line::new(x, min_db, x, y, Color::Green));
t += step / 2.;
}
(
[sample.start as f64, sample.end as f64],
[min_db, 0.],
lines
)
} else {
(
[0.0, width as f64],
[0.0, height as f64],
vec![
Line::new(0.0, 0.0, width as f64, height as f64, Color::Red),
Line::new(width as f64, 0.0, 0.0, height as f64, Color::Red),
]
)
};
Canvas::default()
.x_bounds(x_bounds)
.y_bounds(y_bounds)
.paint(|ctx| { for line in lines.iter() { ctx.draw(line) } })
.x_bounds([sample.start as f64, sample.end as f64])
.y_bounds([min_db, 0.])
.paint(|ctx| {
for line in lines.iter() {
ctx.draw(line);
}
//FIXME: proportions
//let text = "press record to finish sampling";
//ctx.print(
//(width - text.len() as u16) as f64 / 2.0,
//height as f64 / 2.0,
//text.red()
//);
}).render(area, &mut to.buffer);
} else {
Canvas::default()
.x_bounds([0.0, width as f64])
.y_bounds([0.0, height as f64])
.paint(|ctx| {
let text = "press record to begin sampling";
ctx.print(
(width - text.len() as u16) as f64 / 2.0,
height as f64 / 2.0,
text.red()
);
})
.render(area, &mut to.buffer);
}
})
}