From 07d90228d3484173efb8b38e6875d96ca71e0c6d Mon Sep 17 00:00:00 2001 From: unspeaker Date: Fri, 10 Jan 2025 18:29:59 +0100 Subject: [PATCH] layout lib is borked, testing with edn examples yields such wonders --- tek/examples/edn.rs | 9 ++-- tek/examples/edn03.edn | 1 + tek/examples/edn04.edn | 1 + tek/src/arranger/arranger_tui.rs | 76 ++++++++++++++++---------------- 4 files changed, 46 insertions(+), 41 deletions(-) create mode 100644 tek/examples/edn04.edn diff --git a/tek/examples/edn.rs b/tek/examples/edn.rs index f6188dcf..f285a9a0 100644 --- a/tek/examples/edn.rs +++ b/tek/examples/edn.rs @@ -6,6 +6,8 @@ use crossterm::event::{*, KeyCode::*}; const EDN: &'static [&'static str] = &[ include_str!("edn01.edn"), include_str!("edn02.edn"), + include_str!("edn03.edn"), + include_str!("edn04.edn"), ]; fn main () -> Usually<()> { @@ -29,9 +31,10 @@ impl EdnViewData for &Example { impl Content for Example { fn content (&self) -> impl Render { - Bsp::a( - Push::xy(1, 1, Align::n(format!("Example {}/{}:", self.0 + 1, EDN.len()))), - EdnView::from_source(self, EDN[self.0]) + Bsp::a(Push::y(1, Align::n(format!("Example {}/{}:", self.0 + 1, EDN.len()))), + Bsp::a(Push::y(2, Align::n(format!("{}", EDN[self.0]))), + Tui::bg(Color::Rgb(10,20,30), EdnView::from_source(self, EDN[self.0])) + ) ) } } diff --git a/tek/examples/edn03.edn b/tek/examples/edn03.edn index e69de29b..16222753 100644 --- a/tek/examples/edn03.edn +++ b/tek/examples/edn03.edn @@ -0,0 +1 @@ +(fill/xy :hello-world) diff --git a/tek/examples/edn04.edn b/tek/examples/edn04.edn new file mode 100644 index 00000000..0a2b02b1 --- /dev/null +++ b/tek/examples/edn04.edn @@ -0,0 +1 @@ +(fixed/xy 20 20 :hello-world) diff --git a/tek/src/arranger/arranger_tui.rs b/tek/src/arranger/arranger_tui.rs index fbd0cb7a..e600a7fa 100644 --- a/tek/src/arranger/arranger_tui.rs +++ b/tek/src/arranger/arranger_tui.rs @@ -31,6 +31,43 @@ impl Arranger { pub const LEFT_SEP: char = '▎'; pub const TRACK_MIN_WIDTH: usize = 4; + pub fn scenes_with_heights (&self, h: usize) -> impl Iterator { + let mut y = 0; + let editing = self.editing; + let (selected_track, selected_scene) = match self.selected { + ArrangerSelection::Clip(t, s) => (Some(t), Some(s)), + _ => (None, None) + }; + self.scenes.iter().enumerate().map(move|(s, scene)|{ + let active = editing && selected_track.is_some() && selected_scene == Some(s); + let height = if active { 15 } else { h }; + let data = (s, scene, y, y + height); + y += height; + data + }) + } + pub fn tracks_with_widths (&self) + -> impl Iterator + { + let active = match self.selected { + ArrangerSelection::Track(t) => Some(t), + ArrangerSelection::Clip(t, _) => Some(t), + _ => None + }; + Self::tracks_with_widths_static(self.tracks.as_slice(), active) + } + fn tracks_with_widths_static (tracks: &[ArrangerTrack], active: Option) + -> impl Iterator + { + let mut x = 0; + tracks.iter().enumerate().map(move |(index, track)|{ + let width = if Some(index) == active { 40 } else { track.width }; + let data = (index, track, x, x + width); + x += width; + data + }) + } + fn output_row_header <'a> (&'a self) -> BoxThunk<'a, TuiOut> { let fg = TuiTheme::g(192); let bg = TuiTheme::g(48); @@ -108,22 +145,6 @@ impl Arranger { })).boxed()).into() } - pub fn scenes_with_heights (&self, h: usize) -> impl Iterator { - let mut y = 0; - let editing = self.editing; - let (selected_track, selected_scene) = match self.selected { - ArrangerSelection::Clip(t, s) => (Some(t), Some(s)), - _ => (None, None) - }; - self.scenes.iter().enumerate().map(move|(s, scene)|{ - let active = editing && selected_track.is_some() && selected_scene == Some(s); - let height = if active { 15 } else { h }; - let data = (s, scene, y, y + height); - y += height; - data - }) - } - fn scene_row_headers <'a> (&'a self) -> BoxThunk<'a, TuiOut> { (||{ let scenes_w = 16;//.max(SCENES_W_OFFSET + ArrangerScene::longest_name(&self.scenes) as u16); @@ -160,27 +181,6 @@ impl Arranger { ))).boxed() }).into() } - pub fn tracks_with_widths (&self) - -> impl Iterator - { - let active = match self.selected { - ArrangerSelection::Track(t) => Some(t), - ArrangerSelection::Clip(t, _) => Some(t), - _ => None - }; - Self::tracks_with_widths_static(self.tracks.as_slice(), active) - } - fn tracks_with_widths_static (tracks: &[ArrangerTrack], active: Option) - -> impl Iterator - { - let mut x = 0; - tracks.iter().enumerate().map(move |(index, track)|{ - let width = if Some(index) == active { 40 } else { track.width }; - let data = (index, track, x, x + width); - x += width; - data - }) - } fn scene_row_cells <'a> (&'a self) -> BoxThunk<'a, TuiOut> { let editing = self.editing; let (selected_track, selected_scene) = match self.selected { @@ -459,7 +459,7 @@ fn phat_cell_3 > ( ) -> impl Content { Bsp::s(phat_lo(middle, top), Bsp::n(phat_hi(middle, bottom), - Fixed::y(1, Fill::x(Tui::bg(middle, field))), + Fill::y(Fill::x(Tui::bg(middle, field))), ) ) }