wip: component playground; Align primitive

This commit is contained in:
🪞👃🪞 2024-09-07 20:54:49 +03:00
parent 4cca03352a
commit 5fc7da3aca
12 changed files with 181 additions and 42 deletions

View file

@ -211,3 +211,9 @@ pub const KEYMAP_PLUGIN: &'static [KeyBinding<Plugin>] = keymap!(Plugin {
Ok(true)
}],
});
impl Layout<Tui> for Plugin {
fn layout (&self, area: [u16;4]) -> Perhaps<[u16;4]> {
todo!()
}
}

View file

@ -28,27 +28,27 @@ impl Render<Tui> for AddSampleModal {
to.make_dim();
let area = center_box(
area,
64.max(area.width.saturating_sub(8)),
20.max(area.width.saturating_sub(8)),
64.max(area.w().saturating_sub(8)),
20.max(area.w().saturating_sub(8)),
);
to.fill_fg(area, Color::Reset);
to.fill_bg(area, Nord::bg_lo(true, true));
to.fill_char(area, ' ');
to.blit(&format!("{}", &self.dir.to_string_lossy()), area.x+2, area.y+1, Some(Style::default().bold()))?;
to.blit(&"Select sample:", area.x+2, area.y+2, Some(Style::default().bold()))?;
to.blit(&format!("{}", &self.dir.to_string_lossy()), area.x()+2, area.y()+1, Some(Style::default().bold()))?;
to.blit(&"Select sample:", area.x()+2, area.y()+2, Some(Style::default().bold()))?;
for (i, (is_dir, name)) in self.subdirs.iter()
.map(|path|(true, path))
.chain(self.files.iter().map(|path|(false, path)))
.enumerate()
.skip(self.offset)
{
if i >= area.height as usize - 4 {
if i >= area.h() as usize - 4 {
break
}
let t = if is_dir { "" } else { "" };
let line = format!("{t} {}", name.to_string_lossy());
let line = &line[..line.len().min(area.width as usize - 4)];
to.blit(&line, area.x + 2, area.y + 3 + i as u16, Some(if i == self.cursor {
let line = &line[..line.len().min(area.w() as usize - 4)];
to.blit(&line, area.x() + 2, area.y() + 3 + i as u16, Some(if i == self.cursor {
Style::default().green()
} else {
Style::default().white()

View file

@ -143,3 +143,9 @@ impl Sampler {
}
}
}
impl Layout<Tui> for Sampler {
fn layout (&self, area: [u16;4]) -> Perhaps<[u16;4]> {
todo!()
}
}

View file

@ -1,6 +1,11 @@
use crate::*;
use tek_core::Direction;
impl Layout<Tui> for Track<Tui> {
fn layout (&self, area: [u16;4]) -> Perhaps<[u16;4]> {
todo!()
}
}
impl Render<Tui> for Track<Tui> {
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
TrackView {
@ -32,30 +37,31 @@ pub struct TrackView<'a, E: Engine> {
}
impl<'a> Render<Tui> for TrackView<'a, Tui> {
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
let mut area = to.area();
if let Some(chain) = self.chain {
match self.direction {
Direction::Down => area.width = area.width.min(40),
Direction::Right => area.width = area.width.min(10),
_ => { unimplemented!() },
}
to.fill_bg(to.area(), Nord::bg_lo(self.focused, self.entered));
let mut split = Split::new(self.direction);
for device in chain.devices.as_slice().iter() {
split = split.add_ref(device);
}
let (area, areas) = split.render_areas(to)?;
if self.focused && self.entered && areas.len() > 0 {
Corners(Style::default().green().not_dim()).draw(to.with_rect(areas[0]))?;
}
Ok(Some(area))
} else {
let [x, y, width, height] = area;
let label = "No chain selected";
let x = x + (width - label.len() as u16) / 2;
let y = y + height / 2;
to.blit(&label, x, y, Some(Style::default().dim().bold()))?;
Ok(Some(area))
}
todo!();
//let mut area = to.area();
//if let Some(chain) = self.chain {
//match self.direction {
//Direction::Down => area.width = area.width.min(40),
//Direction::Right => area.width = area.width.min(10),
//_ => { unimplemented!() },
//}
//to.fill_bg(to.area(), Nord::bg_lo(self.focused, self.entered));
//let mut split = Split::new(self.direction);
//for device in chain.devices.as_slice().iter() {
//split = split.add_ref(device);
//}
//let (area, areas) = split.render_areas(to)?;
//if self.focused && self.entered && areas.len() > 0 {
//Corners(Style::default().green().not_dim()).draw(to.with_rect(areas[0]))?;
//}
//Ok(Some(area))
//} else {
//let [x, y, width, height] = area;
//let label = "No chain selected";
//let x = x + (width - label.len() as u16) / 2;
//let y = y + height / 2;
//to.blit(&label, x, y, Some(Style::default().dim().bold()))?;
//Ok(Some(area))
//}
}
}