reenable inc/dec phrase

This commit is contained in:
🪞👃🪞 2024-07-11 21:32:12 +03:00
parent c3040cef1c
commit 2c8f4857dd
11 changed files with 217 additions and 585 deletions

View file

@ -1,23 +1,23 @@
use crate::core::*;
use crate::view::*;
use crate::model::*;
use crate::view::{*, Direction};
pub struct ChainView<'a> {
pub focused: bool,
pub track: Option<&'a Track>,
pub vertical: bool,
pub track: Option<&'a Track>,
pub direction: Direction,
pub focused: bool,
}
impl<'a> ChainView<'a> {
pub fn horizontal (app: &'a App) -> Self {
Self::new(app, false)
Self::new(app, Direction::Right)
}
pub fn vertical (app: &'a App) -> Self {
Self::new(app, true)
Self::new(app, Direction::Down)
}
pub fn new (app: &'a App, vertical: bool) -> Self {
pub fn new (app: &'a App, direction: Direction) -> Self {
Self {
vertical,
direction,
focused: app.section == AppSection::Chain,
track: match app.track_cursor {
0 => None,
@ -28,220 +28,66 @@ impl<'a> ChainView<'a> {
}
impl<'a> Render for ChainView<'a> {
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
let style = Some(if self.focused {
Style::default().green().dim()
} else {
Style::default().dim()
});
let Rect { x, y, width, height } = area;
if self.track.is_none() {
let label = "No track selected";
label.blit(
buf,
x + (width - label.len() as u16) / 2,
y + height / 2,
Some(Style::default().dim().bold())
);
}
fill_bg(buf, area, if self.focused {
Color::Rgb(20, 45, 5)
} else {
Color::Reset
});
//lozenge_left(buf, x, y, height, style);
let (area, _plugins) = if self.track.is_some() {
if self.vertical {
self.draw_as_column(buf, area, style)?
} else {
self.draw_as_row(buf, area, style)?
fn render (&self, buf: &mut Buffer, mut area: Rect) -> Usually<Rect> {
if let Some(track) = self.track {
match self.direction {
Direction::Down => area.width = area.width.min(40),
Direction::Right => area.width = area.width.min(10),
}
fill_bg(buf, area, if self.focused { Color::Rgb(20, 45, 5) } else { Color::Reset });
self.direction
.split_focus(0, track.devices.as_slice(), if self.focused {
Style::default().green().dim()
} else {
Style::default().dim()
})
.render(buf, area)
} else {
(area, vec![])
};
//lozenge_right(buf, x + width - 1, y, height, style);
let Rect { x, y, width, height } = area;
let label = "No track selected";
let x = x + (width - label.len() as u16) / 2;
let y = y + height / 2;
label.blit(buf, x, y, Some(Style::default().dim().bold()))?;
Ok(area)
}
}
}
type Renderables<'a> = &'a [JackDevice];
impl<'a> Direction {
fn split_focus (&self, index: usize, items: Renderables<'a>, style: Style) -> SplitFocus<'a> {
SplitFocus(*self, index, items, style)
}
}
pub struct SplitFocus<'a>(pub Direction, pub usize, pub Renderables<'a>, pub Style);
impl<'a> Render for SplitFocus<'a> {
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
let Rect { mut x, mut y, mut width, mut height } = area;
let mut results = vec![];
for item in self.2.iter() {
if width == 0 || height == 0 {
break
}
let result = item.render(buf, Rect { x, y, width, height })?;
results.push(result);
match self.0 {
Direction::Down => {
y = y + result.height;
height = height.saturating_sub(result.height);
},
Direction::Right => {
x = x + result.width;
width = width.saturating_sub(result.width);
},
}
}
results
.get(self.1)
.map(|focused|Lozenge(self.3).draw(buf, *focused))
.transpose()?;
Ok(area)
}
}
impl<'a> ChainView<'a> {
pub fn draw_as_row (
&self, buf: &mut Buffer, area: Rect, style: Option<Style>
) -> Usually<(Rect, Vec<Rect>)> {
let Rect { mut x, y, width, height } = area;
let mut h = 3u16;
let mut frames = vec![];
let track = self.track.as_ref().unwrap();
for (i, device) in track.devices.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 frame = device.state.read().unwrap()
.render(buf, Rect { x: x + x2, y, width, height })?;
let style = if i == track.device {
Some(if self.focused {
Style::default().green().bold().not_dim()
} else {
Style::default().green().dim()
})
} else {
style
};
LozengeV(style.unwrap_or(Style::default())).draw(buf, frame);
//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;
}
let label = "[Add device…]";
label.blit(buf, x + 1, area.y + 1, Some(Style::default().dim()));
x = x + 1 + label.len() as u16 + 1;
Ok((Rect { x: area.x, y: area.y, width: x, height: h }, frames))
}
pub fn draw_as_column (
&self, buf: &mut Buffer, area: Rect, selected: Option<Style>
) -> Usually<(Rect, Vec<Rect>)> {
let Rect { x, mut y, width, height } = area;
let mut w = 0u16;
let mut frames = vec![];
let track = self.track.as_ref().unwrap();
for (_i, device) in track.devices.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()?;
let device = device.state.read().unwrap();
//let style_midi = Style::default().black().bold().on_green();
//let style_audio = Style::default().black().bold().on_red();
//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 + frame.height;
//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.name()?), 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.name()?), 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.name()?), 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.name()?), style_audio);
//y = y + 1;
//}
}
if frames.len() > 0 {
Lozenge(selected.unwrap_or(Style::default()))
.draw(buf, frames[track.device]);
}
Ok((Rect { x, y: area.y, width: w, height: y - area.y }, frames))
//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,
//}))
}
}
//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 enum ChainViewMode {
//Hidden,
//Compact,
//Row,
//Column,
//}