From 77091671a33fc36edef30ad4aa5e9c7f7712c49f Mon Sep 17 00:00:00 2001 From: unspeaker Date: Wed, 1 Jan 2025 21:25:49 +0100 Subject: [PATCH] almost correctly working phrase list --- layout/src/lib.rs | 11 ++++++++++ src/pool.rs | 56 +++++++++++++++++++++++++---------------------- 2 files changed, 41 insertions(+), 26 deletions(-) diff --git a/layout/src/lib.rs b/layout/src/lib.rs index f3fb9d25..b41d9f0b 100644 --- a/layout/src/lib.rs +++ b/layout/src/lib.rs @@ -38,5 +38,16 @@ pub(crate) use std::marker::PhantomData; assert_eq!(Align::sw(four()).layout(area), [10, 26, 4, 4]); assert_eq!(Align::w(four()).layout(area), [10, 18, 4, 4]); + let two_by_four = ||Fixed::::xy(4, 2, unit); + + assert_eq!(Align::nw(two_by_four()).layout(area), [10, 10, 4, 2]); + assert_eq!(Align::n(two_by_four()).layout(area), [18, 10, 4, 2]); + assert_eq!(Align::ne(two_by_four()).layout(area), [26, 10, 4, 2]); + assert_eq!(Align::e(two_by_four()).layout(area), [26, 19, 4, 2]); + assert_eq!(Align::se(two_by_four()).layout(area), [26, 28, 4, 2]); + assert_eq!(Align::s(two_by_four()).layout(area), [18, 28, 4, 2]); + assert_eq!(Align::sw(two_by_four()).layout(area), [10, 28, 4, 2]); + assert_eq!(Align::w(two_by_four()).layout(area), [10, 19, 4, 2]); + Ok(()) } diff --git a/src/pool.rs b/src/pool.rs index 597a7a7e..d68d1c47 100644 --- a/src/pool.rs +++ b/src/pool.rs @@ -208,27 +208,24 @@ impl PoolModel { pub struct PoolView<'a>(pub(crate) &'a PoolModel); // TODO: Display phrases always in order of appearance render!(Tui: (self: PoolView<'a>) => { - //let content = "..."; - //let content = Tui::map(||["abc", "def", "ghi"].iter(), |item, index|Push::y(index as u16, item)); let PoolModel { phrases, mode, .. } = self.0; - //let bg = TuiTheme::g(32); - //let title_color = TuiTheme::ti1(); - //let upper_left = "Pool:"; - //let upper_right = format!("({})", phrases.len()); - //let color = self.0.phrase().read().unwrap().color; - ////let with_files = |x|Tui::either(self.0.file_picker().is_some(), - ////Thunk::new(||self.0.file_picker().unwrap()), - ////Thunk::new(x)); - let content = Tui::map(||phrases.iter(), |clip, i|{ + let color = self.0.phrase().read().unwrap().color; + let content = Tui::bg(Color::Black, Tui::map(||self.0.phrases().iter(), |clip, i|{ let MidiClip { ref name, color, length, .. } = *clip.read().unwrap(); - //let mut length = PhraseLength::new(length, None); - //if let Some(PoolMode::Length(clip, new_length, focus)) = self.0.mode { - //if i == clip { - //length.pulses = new_length; - //length.focus = Some(focus); - //} - //} - Push::y(i as u16, format!(" {i} {name} {length} "))/* + let item_height = 1; + let item_offset = i as u16 * item_height; + let selected = i == self.0.phrase_index(); + let offset = |a|Push::y(item_offset, Align::n(Fixed::y(item_height, Fill::x(a)))); + offset(Tui::bg(if selected { color.light.rgb } else { color.base.rgb }, lay!( + Align::w(Tui::fg(color.lightest.rgb, format!(" {i:>3} {name}"))), + Align::e(Tui::fg(color.lightest.rgb, format!("{length} "))), + Align::w(Tui::when(selected, Tui::bold(true, Tui::fg(color.lightest.rgb, "[")))), + Align::e(Tui::when(selected, Tui::bold(true, Tui::fg(color.lightest.rgb, "]")))), + //Tui::when(, Fixed::y(1, Tui::fg(Color::Green, lay!( + //Align::w(format!("[")), + //Align::e(format!("]")), + //)))) + )))/* //format!(" {i} {name} {length} ")[> //Push::y(i as u16 * 2, Fixed::y(2, Tui::bg(color.base.rgb, Fill::x( //format!(" {i} {name} {length} ")))))[>, @@ -247,13 +244,20 @@ render!(Tui: (self: PoolView<'a>) => { row2 }), ))))//lay!(clip, Tui::when(i == self.0.clip_index(), CORNERS)))*/ - }); - Tui::bg(Color::Red, content) - //let border = Outer(Style::default().fg(color.base.rgb).bg(color.dark.rgb)); - //let enclose = |x|lay!( - //Fill::xy(border), - //Padding::xy(0, 1, Tui::bg(bg, x)) - //); + })); + let border = Outer(Style::default().fg(color.base.rgb).bg(color.darker.rgb)); + let enclose = |x|lay!(Fill::xy(border), Tui::bg(color.darkest.rgb, x)); + ////let with_files = |x|Tui::either(self.0.file_picker().is_some(), + ////Thunk::new(||self.0.file_picker().unwrap()), + ////Thunk::new(x)); + //let mut length = PhraseLength::new(length, None); + //if let Some(PoolMode::Length(clip, new_length, focus)) = self.0.mode { + //if i == clip { + //length.pulses = new_length; + //length.focus = Some(focus); + //} + //} + enclose(content) //enclose(lay!( ////add(&Lozenge(Style::default().bg(border_bg).fg(border_color)))?; //Fill::xy(content),