mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 04:36:45 +01:00
48 lines
1.9 KiB
Rust
48 lines
1.9 KiB
Rust
use crate::{core::*, model::*};
|
|
|
|
pub fn render (state: &Plugin, buf: &mut Buffer, area: Rect)
|
|
-> Usually<Rect>
|
|
{
|
|
let Rect { x, y, height, .. } = area;
|
|
let mut width = 20u16;
|
|
match &state.plugin {
|
|
Some(PluginKind::LV2(LV2Plugin { port_list, instance, .. })) => {
|
|
let start = state.selected.saturating_sub((height as usize / 2).saturating_sub(1));
|
|
let end = start + height as usize - 2;
|
|
//draw_box(buf, Rect { x, y, width, height });
|
|
for i in start..end {
|
|
if let Some(port) = port_list.get(i) {
|
|
let value = if let Some(value) = instance.control_input(port.index) {
|
|
value
|
|
} else {
|
|
port.default_value
|
|
};
|
|
//let label = &format!("C·· M·· {:25} = {value:.03}", port.name);
|
|
let label = &format!("{:25} = {value:.03}", port.name);
|
|
width = width.max(label.len() as u16 + 4);
|
|
label.blit(buf, x + 2, y + 1 + i as u16 - start as u16, if i == state.selected {
|
|
Some(Style::default().green())
|
|
} else {
|
|
None
|
|
})?;
|
|
} else {
|
|
break
|
|
}
|
|
}
|
|
},
|
|
_ => {}
|
|
};
|
|
draw_header(state, buf, area.x, area.y, width)?;
|
|
Ok(Rect { width, ..area })
|
|
}
|
|
|
|
fn draw_header (state: &Plugin, buf: &mut Buffer, x: u16, y: u16, w: u16) -> Usually<Rect> {
|
|
let style = Style::default().gray();
|
|
let label1 = format!(" {}", state.name);
|
|
label1.blit(buf, x + 1, y, Some(style.white().bold()))?;
|
|
if let Some(ref path) = state.path {
|
|
let label2 = format!("{}…", &path[..((w as usize - 10).min(path.len()))]);
|
|
label2.blit(buf, x + 2 + label1.len() as u16, y, Some(style.not_dim()))?;
|
|
}
|
|
Ok(Rect { x, y, width: w, height: 1 })
|
|
}
|