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

@ -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))
//}
}
}