mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 05:06:43 +01:00
54 lines
2.2 KiB
Rust
54 lines
2.2 KiB
Rust
use crate::*;
|
|
|
|
impl Widget for Plugin<Tui> {
|
|
type Engine = Tui;
|
|
fn layout (&self, to: [u16;4]) -> Perhaps<[u16;4]> {
|
|
Ok(Some(to))
|
|
}
|
|
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
|
let area = to.area();
|
|
let [x, y, _, height] = area;
|
|
let mut width = 20u16;
|
|
match &self.plugin {
|
|
Some(PluginKind::LV2(LV2Plugin { port_list, instance, .. })) => {
|
|
let start = self.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);
|
|
let style = if i == self.selected {
|
|
Some(Style::default().green())
|
|
} else {
|
|
None
|
|
} ;
|
|
to.blit(&label, x + 2, y + 1 + i as u16 - start as u16, style)?;
|
|
} else {
|
|
break
|
|
}
|
|
}
|
|
},
|
|
_ => {}
|
|
};
|
|
draw_header(self, to, x, y, width)?;
|
|
Ok(Some([x, y, width, height]))
|
|
}
|
|
}
|
|
|
|
fn draw_header <E> (state: &Plugin<E>, to: &mut Tui, x: u16, y: u16, w: u16) -> Usually<Rect> {
|
|
let style = Style::default().gray();
|
|
let label1 = format!(" {}", state.name);
|
|
to.blit(&label1, 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()))]);
|
|
to.blit(&label2, x + 2 + label1.len() as u16, y, Some(style.not_dim()))?;
|
|
}
|
|
Ok(Rect { x, y, width: w, height: 1 })
|
|
}
|