mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 04:36:45 +01:00
big ass refactor (rip client)
This commit is contained in:
parent
94c1f83ef2
commit
8c3cf53c67
56 changed files with 2232 additions and 1891 deletions
194
src/view/chain.rs
Normal file
194
src/view/chain.rs
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
use crate::core::*;
|
||||
use crate::view::*;
|
||||
use crate::model::*;
|
||||
|
||||
pub enum ChainViewMode {
|
||||
Hidden,
|
||||
Compact,
|
||||
Row,
|
||||
Column,
|
||||
}
|
||||
|
||||
pub struct ChainView<'a> {
|
||||
pub focused: bool,
|
||||
pub chain: Option<&'a Chain>,
|
||||
}
|
||||
|
||||
impl<'a> Render for ChainView<'a> {
|
||||
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
|
||||
let style = Some(Style::default().green().dim());
|
||||
if self.focused {
|
||||
let Rect { x, y, width, height} = area;
|
||||
lozenge_left(buf, x, y, height, style);
|
||||
lozenge_right(buf, x + width - 1, y, height, style);
|
||||
};
|
||||
let (area, _plugins) = if let Some(ref chain) = self.chain {
|
||||
draw_as_row(&*chain, buf, area, style)?
|
||||
} else {
|
||||
(area, vec![])
|
||||
};
|
||||
Ok(area)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render (state: &Chain, buf: &mut Buffer, area: Rect)
|
||||
-> Usually<Rect>
|
||||
{
|
||||
let Rect { x, y, .. } = area;
|
||||
let selected = Some(if state.focused {
|
||||
Style::default().green().not_dim()
|
||||
} else {
|
||||
Style::default().green().dim()
|
||||
});
|
||||
let result = match state.view {
|
||||
ChainViewMode::Hidden => Rect { x, y, width: 0, height: 0 },
|
||||
ChainViewMode::Compact => {
|
||||
let area = Rect { x, y, width: (state.name.len() + 4) as u16, height: 3 };
|
||||
buf.set_string(area.x + 2, area.y + 1, &state.name, Style::default());
|
||||
draw_box_styled(buf, area, selected)
|
||||
},
|
||||
ChainViewMode::Row => {
|
||||
draw_box_styled(buf, area, selected);
|
||||
let (area, _) = Row::draw(buf, area, &state.items, 0)?;
|
||||
area
|
||||
},
|
||||
ChainViewMode::Column => {
|
||||
draw_as_column(state, buf, area, selected)?
|
||||
},
|
||||
};
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
pub fn draw_as_row (
|
||||
state: &Chain, buf: &mut Buffer, area: Rect, _: Option<Style>
|
||||
) -> Usually<(Rect, Vec<Rect>)> {
|
||||
let Rect { mut x, y, width, height } = area;
|
||||
let mut h = 0u16;
|
||||
let mut frames = vec![];
|
||||
for (i, device) in state.items.iter().enumerate() {
|
||||
let x2 = 0u16;
|
||||
let _y2 = 1u16;
|
||||
//for port in device.midi_ins()?.iter() {
|
||||
//port.blit(buf, x, y + y2, Some(Style::default()));
|
||||
//x2 = x2.max(port.len() as u16);
|
||||
//y2 = y2 + 1;
|
||||
//}
|
||||
//for port in device.audio_ins()?.iter() {
|
||||
//port.blit(buf, x, y + y2, Some(Style::default()));
|
||||
//x2 = x2.max(port.len() as u16);
|
||||
//y2 = y2 + 1;
|
||||
//}
|
||||
let width = width.saturating_sub(x).saturating_sub(x2);
|
||||
let style = Some(if i == state.focus {
|
||||
if state.focused {
|
||||
Style::default().green().not_dim()
|
||||
} else {
|
||||
Style::default().green().dim()
|
||||
}
|
||||
} else {
|
||||
Style::default().dim()
|
||||
});
|
||||
lozenge_left(buf, x + x2, y, height, style);
|
||||
let frame = device.render(buf, Rect { x: x + x2, y, width, height })?;
|
||||
lozenge_right(buf, x + x2 + frame.width - 1, y, height, style);
|
||||
//let mut y2 = 1u16;
|
||||
//for port in device.midi_outs()?.iter() {
|
||||
//port.blit(buf, x + x2 + frame.width, y + y2, Some(Style::default()));
|
||||
//x2 = x2.max(port.len() as u16);
|
||||
//y2 = y2 + 1;
|
||||
//}
|
||||
//for port in device.audio_outs()?.iter() {
|
||||
//port.blit(buf, x + x2 + frame.width, y + y2, Some(Style::default()));
|
||||
//x2 = x2.max(port.len() as u16);
|
||||
//y2 = y2 + 1;
|
||||
//}
|
||||
frames.push(frame);
|
||||
h = h.max(frame.height);
|
||||
x = x + frame.width;
|
||||
}
|
||||
Ok((Rect { x: area.x, y: area.y, width, height: h }, frames))
|
||||
}
|
||||
|
||||
pub fn draw_as_column (
|
||||
state: &Chain, buf: &mut Buffer, area: Rect, selected: Option<Style>
|
||||
) -> Usually<Rect> {
|
||||
//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 (i, device) in state.items.iter().enumerate() {
|
||||
//let result = device.render(buf, Rect {
|
||||
//x: area.x,
|
||||
//y,
|
||||
//width: area.width,
|
||||
//height: 21//area.height.saturating_sub(y)
|
||||
//})?;
|
||||
//if i == state.focus {
|
||||
//if state.focused {
|
||||
//draw_box_styled(buf, result, Some(Style::default().green().not_dim()))
|
||||
//} else {
|
||||
//draw_box_styled_dotted(buf, result, Some(Style::default().green().dim()))
|
||||
//};
|
||||
//};
|
||||
////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,
|
||||
//}))
|
||||
let Rect { x, mut y, width, height } = area;
|
||||
//let (area, areas) = Column::draw(buf, area, &state.items, 0)?;
|
||||
let mut w = 0u16;
|
||||
let mut frames = vec![];
|
||||
for device in state.items.iter() {
|
||||
let style_midi = Style::default().black().bold().on_green();
|
||||
let style_audio = Style::default().black().bold().on_red();
|
||||
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.saturating_sub(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_midi);
|
||||
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_audio);
|
||||
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_midi);
|
||||
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_audio);
|
||||
y = y + 1;
|
||||
}
|
||||
}
|
||||
draw_box_styled(buf, frames[state.focus], selected);
|
||||
Ok(area)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue