mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
62 lines
2 KiB
Rust
62 lines
2 KiB
Rust
use crate::prelude::*;
|
|
|
|
pub struct Chain {
|
|
name: String,
|
|
devices: Vec<Box<dyn Device>>,
|
|
focused: usize,
|
|
}
|
|
|
|
impl Chain {
|
|
pub fn new (name: &str, devices: Vec<Box<dyn Device>>) -> Result<DynamicDevice<Self>, Box<dyn Error>> {
|
|
Ok(DynamicDevice::new(render, handle, process, Self {
|
|
name: name.into(),
|
|
devices,
|
|
focused: 0
|
|
}))
|
|
}
|
|
}
|
|
|
|
pub fn process (_: &mut Chain, _: &Client, _: &ProcessScope) -> Control {
|
|
Control::Continue
|
|
}
|
|
|
|
pub fn render (state: &Chain, buf: &mut Buffer, area: Rect)
|
|
-> Usually<Rect>
|
|
{
|
|
let Rect { x, y, .. } = area;
|
|
let area = Rect { x, y, width: 40, height: 30 };
|
|
let mut y = area.y;
|
|
buf.set_string(area.x, y, "│", Style::default().black());
|
|
buf.set_string(area.x + area.width - 1, y, "│", Style::default().black());
|
|
buf.set_string(area.x + 2, y, "Input...", Style::default().dim());
|
|
let mut x = 0u16;
|
|
for device in state.devices.iter() {
|
|
let result = device.render(buf, Rect {
|
|
x: area.x,
|
|
y,
|
|
width: area.width,
|
|
height: 21//area.height.saturating_sub(y)
|
|
})?;
|
|
//let result = Rect { x: 0, y: 0, width: result.width, height: 21 };
|
|
x = x.max(result.width);
|
|
y = y + result.height;
|
|
//y = y + 1;
|
|
buf.set_string(area.x, y, "│", Style::default().black());
|
|
buf.set_string(area.x + area.width - 1, y, "│", Style::default().black());
|
|
buf.set_string(area.x + 2, y, " Patch in ┐ │ └ Patch out", Style::default().dim());
|
|
y = y + 1;
|
|
//buf.set_string(area.x, y, format!("{y}---BOT---"), Style::default().red());
|
|
//buf.set_string(area.x + area.width - 1, area.y + 1, "│", Style::default().black());
|
|
//buf.set_string(area.x + 2, y, "Patch...", Style::default().dim());
|
|
}
|
|
Ok(draw_box(buf, Rect {
|
|
x: area.x,
|
|
y: area.y,
|
|
width: area.width,
|
|
height: y - area.y,
|
|
}))
|
|
}
|
|
|
|
pub fn handle (_: &mut Chain, _: &AppEvent) -> Usually<bool> {
|
|
Ok(false)
|
|
}
|