draw ports; fix process callback

This commit is contained in:
🪞👃🪞 2024-06-22 20:05:48 +03:00
parent 72ead536be
commit 9e550a73ae
8 changed files with 268 additions and 175 deletions

View file

@ -34,7 +34,7 @@ pub fn process (_: &mut Chain, _: &Client, _: &ProcessScope) -> Control {
pub fn render (state: &Chain, buf: &mut Buffer, area: Rect)
-> Usually<Rect>
{
let Rect { x, y, .. } = area;
let Rect { mut x, mut y, width, height } = area;
let selected = Some(if state.focused {
Style::default().green().not_dim()
} else {
@ -52,8 +52,57 @@ pub fn render (state: &Chain, buf: &mut Buffer, area: Rect)
draw_box_styled(buf, area, selected)
},
ChainView::Column => {
let (area, areas) = Column::draw(buf, area, &state.items, 0)?;
draw_box_styled(buf, areas[state.focus], selected);
//let (area, areas) = Column::draw(buf, area, &state.items, 0)?;
let mut w = 0u16;
let mut y = area.y;
let mut frames = vec![];
for (i, device) in state.items.iter().enumerate() {
let midi_ins = device.midi_ins()?;
let midi_outs = device.midi_outs()?;
let audio_ins = device.audio_ins()?;
let audio_outs = device.audio_outs()?;
y = y + midi_ins.len() as u16;
let frame = device.render(buf, Rect { x, y, width, height: height - y })?;
frames.push(frame);
w = w.max(frame.width);
y = y - midi_ins.len() as u16;
for port in midi_ins.iter() {
buf.set_string(x + frame.width - 10, y,
&format!(" <i> MIDI {port} "),
Style::default().black().bold().on_green());
y = y + 1;
}
y = y - audio_ins.len() as u16;
for port in audio_ins.iter() {
buf.set_string(x + frame.width - 10, y,
&format!(" <i> MIDI {port} "),
Style::default().black().bold().on_red());
y = y + 1;
}
y = y + frame.height - 1;
y = y + midi_outs.len() as u16;
for port in midi_outs.iter() {
buf.set_string(x + 2, y,
&format!(" <o> MIDI {port} "),
Style::default().black().bold().on_green());
y = y + 1;
}
y = y + audio_outs.len() as u16;
for port in audio_outs.iter() {
buf.set_string(x + 2, y,
&format!(" <o> Audio {port} "),
Style::default().black().bold().on_red());
y = y + 1;
}
}
draw_box_styled(buf, frames[state.focus], selected);
area
},
})
@ -159,3 +208,5 @@ pub fn handle (state: &mut Chain, event: &AppEvent) -> Usually<bool> {
|s: &mut Chain|s.handle_focus(&FocusEvent::Outward)]
}))
}
impl DevicePorts for Chain {}