From 9f7b23a2525281ab746e0dd3c08262908c8b4975 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Tue, 31 Dec 2024 16:39:33 +0100 Subject: [PATCH] check pass, test pass.. but does it run? --- layout/src/collection.rs | 69 +++++++++++++++++++----------- layout/src/measure.rs | 10 ++--- layout/src/transform.rs | 10 ++--- src/arranger/arranger_v/v_clips.rs | 4 +- src/arranger/arranger_v/v_head.rs | 2 +- src/file.rs | 4 +- src/groovebox.rs | 2 +- src/pool.rs | 6 +-- src/sequencer.rs | 4 +- src/transport.rs | 2 +- 10 files changed, 65 insertions(+), 48 deletions(-) diff --git a/layout/src/collection.rs b/layout/src/collection.rs index 9e90fd3e..6fe8baa7 100644 --- a/layout/src/collection.rs +++ b/layout/src/collection.rs @@ -1,28 +1,47 @@ //! Groupings of elements. mod split; pub use self::split::*; -mod stack; pub use self::stack::*; +//mod stack; pub use self::stack::*; use crate::*; use std::sync::RwLock; -/// Conditional rendering, in unary and binary forms. -pub struct Cond; +impl Layout for E {} -impl Cond { +pub trait Layout { /// Content `item` when `cond` is true. - pub fn when > (cond: bool, item: A) -> When { + fn when > (cond: bool, item: A) -> When { When(cond, item, Default::default()) } /// Content `item` if `cond` is true, otherwise render `other`. - pub fn either , B: Content> (cond: bool, a: A, b: B) -> Either { + fn either , B: Content> (cond: bool, a: A, b: B) + -> Either + { Either(cond, a, b, Default::default()) } - - pub fn opt R, R: Content> (option: Option, cb: F) -> Opt { + /// Maps an [Option] through a callback `F` + fn opt R, R: Content> (option: Option, cb: F) + -> Opt + { Opt(option, cb, Default::default()) } + fn map (iterator: I, callback: F) -> Map where + E: Engine, + I: Iterator + Send + Sync, + R: Content, + F: Fn(T, usize)->R + Send + Sync + { + Map(Default::default(), RwLock::new(iterator), callback) + } + //pub fn reduce (iterator: I, callback: F) -> Reduce where + //E: Engine, + //I: Iterator + Send + Sync, + //R: Content, + //F: Fn(R, T, usize) -> R + Send + Sync + //{ + //Reduce(Default::default(), iterator, callback) + //} } pub struct OptR, R: Content>(Option, F, PhantomData); @@ -63,33 +82,31 @@ impl, B: Content> Content for Either { } } +pub trait Render { + fn area (&self, to: E::Area) -> E::Area; + fn render (&self, to: &mut E::Output); +} + +impl> Render for C { + fn area (&self, to: E::Area) -> E::Area { + Content::area(self, to) + } + fn render (&self, to: &mut E::Output) { + Content::render(self, to) + } +} + /// A function or closure that emits renderables. -pub trait Collector: Send + Sync + Fn(&mut dyn FnMut(&dyn Content)) {} +pub trait Collector: Send + Sync + Fn(&mut dyn FnMut(&dyn Render)) {} /// Any function or closure that emits renderables for the given engine matches [CollectCallback]. impl Collector for F -where E: Engine, F: Send + Sync + Fn(&mut dyn FnMut(&dyn Content)) {} +where E: Engine, F: Send + Sync + Fn(&mut dyn FnMut(&dyn Render)) {} /// Rendering of iterable collections, one-to-one and many-to one. pub struct Coll; impl Coll { - pub fn map (iterator: I, callback: F) -> Map where - E: Engine, - I: Iterator + Send + Sync, - R: Content, - F: Fn(T, usize)->R + Send + Sync - { - Map(Default::default(), RwLock::new(iterator), callback) - } - //pub fn reduce (iterator: I, callback: F) -> Reduce where - //E: Engine, - //I: Iterator + Send + Sync, - //R: Content, - //F: Fn(R, T, usize) -> R + Send + Sync - //{ - //Reduce(Default::default(), iterator, callback) - //} } pub struct Map(PhantomData, RwLock, F) where diff --git a/layout/src/measure.rs b/layout/src/measure.rs index 93cdaca2..cccdd1da 100644 --- a/layout/src/measure.rs +++ b/layout/src/measure.rs @@ -66,11 +66,11 @@ impl Measure { } } -/// A scrollable area. -pub struct Scroll(pub F, pub Direction, pub u64, PhantomData) -where - E: Engine, - F: Send + Sync + Fn(&mut dyn FnMut(&dyn Content)->Usually<()>)->Usually<()>; +///// A scrollable area. +//pub struct Scroll(pub F, pub Direction, pub u64, PhantomData) +//where + //E: Engine, + //F: Send + Sync + Fn(&mut dyn FnMut(&dyn Content)->Usually<()>)->Usually<()>; //pub trait ContentDebug { //fn debug > (other: W) -> DebugOverlay { diff --git a/layout/src/transform.rs b/layout/src/transform.rs index 87037ec8..20d5029a 100644 --- a/layout/src/transform.rs +++ b/layout/src/transform.rs @@ -42,7 +42,7 @@ macro_rules! transform_xy { transform_xy!(self: Fill |to|{ let [x0, y0, wmax, hmax] = to.xywh(); - let [x, y, w, h] = self.content().area(to).xywh(); + let [x, y, w, h] = Content::area(&self.content(), to).xywh(); return match self { Self::X(_) => [x0, y, wmax, h], Self::Y(_) => [x, y0, w, hmax], @@ -174,10 +174,10 @@ fn align, N: Coordinate, R: Area + From<[N;4]>> (ali impl> Content for Align { fn render (&self, to: &mut E::Output) { - let outer_area = to.area(); - let content = self.content(); - let inner_area = content.area(outer_area); - if let Some(aligned) = align(&self, outer_area.into(), inner_area.into()) { + let outer = to.area(); + let content = self.content(); + let inner = Content::area(&content, outer); + if let Some(aligned) = align(&self, outer.into(), inner.into()) { to.place(aligned, &content) } } diff --git a/src/arranger/arranger_v/v_clips.rs b/src/arranger/arranger_v/v_clips.rs index ec2f1a20..a3216224 100644 --- a/src/arranger/arranger_v/v_clips.rs +++ b/src/arranger/arranger_v/v_clips.rs @@ -20,7 +20,7 @@ impl<'a> ArrangerVClips<'a> { impl<'a> Content for ArrangerVClips<'a> { fn content (&self) -> impl Content { let iter = self.scenes.iter().zip(self.rows.iter().map(|row|row.0)); - let col = Coll::map(iter, |(scene, pulses), i|Self::format_scene(self.tracks, scene, pulses)); + let col = Tui::map(iter, |(scene, pulses), i|Self::format_scene(self.tracks, scene, pulses)); Fill::xy(col) } } @@ -37,7 +37,7 @@ impl<'a> ArrangerVClips<'a> { let name = Tui::fg_bg(scene.color.lightest.rgb, scene.color.base.rgb, Expand::x(1, Tui::bold(true, scene.name.read().unwrap().clone())) ); - let clips = Coll::map(ArrangerTrack::with_widths(tracks), move|(index, track, x1, x2), _| + let clips = Tui::map(ArrangerTrack::with_widths(tracks), move|(index, track, x1, x2), _| Push::x((x2 - x1) as u16, Self::format_clip(scene, index, track, (x2 - x1) as u16, height)) ); Fixed::y(height, row!(icon, name, clips)) diff --git a/src/arranger/arranger_v/v_head.rs b/src/arranger/arranger_v/v_head.rs index 5c18dbac..49146fb0 100644 --- a/src/arranger/arranger_v/v_head.rs +++ b/src/arranger/arranger_v/v_head.rs @@ -20,7 +20,7 @@ render!(Tui: (self: ArrangerVHead<'a>) => { row!(Tui::fg(color.light.rgb, "▎"), Tui::fg(color.lightest.rgb, field)) } Some(Push::x(self.scenes_w, - Coll::map(ArrangerTrack::with_widths(self.tracks), |(_, track, x1, x2), i| { + Tui::map(ArrangerTrack::with_widths(self.tracks), |(_, track, x1, x2), i| { let (w, h) = (ArrangerTrack::MIN_WIDTH.max(x2 - x1), HEADER_H); let color = track.color(); let input = Self::format_input(track); diff --git a/src/file.rs b/src/file.rs index 491cf2c8..5f2f1e1f 100644 --- a/src/file.rs +++ b/src/file.rs @@ -20,7 +20,7 @@ pub enum FileBrowserCommand { Chdir(PathBuf), Filter(String), } -render!(Tui: (self: FileBrowser) => Stack::down(|add|{ +render!(Tui: (self: FileBrowser) => /*Stack::down(|add|{ let mut i = 0; for (_, name) in self.dirs.iter() { if i >= self.scroll { @@ -36,7 +36,7 @@ render!(Tui: (self: FileBrowser) => Stack::down(|add|{ } add(&format!("{}/{i}", self.index))?; Ok(()) -})); +})*/"todo"); impl FileBrowser { pub fn new (cwd: Option) -> Usually { let cwd = if let Some(cwd) = cwd { cwd } else { std::env::current_dir()? }; diff --git a/src/groovebox.rs b/src/groovebox.rs index 883ecdf3..42198f94 100644 --- a/src/groovebox.rs +++ b/src/groovebox.rs @@ -178,7 +178,7 @@ render!(Tui: (self: GrooveboxSamples<'a>) => { let note_lo = self.0.editor.note_lo().load(Relaxed); let note_pt = self.0.editor.note_point(); let note_hi = self.0.editor.note_hi(); - Fill::xy(Coll::map((note_lo..=note_hi).rev(), move|note, i| { + Fill::xy(Tui::map((note_lo..=note_hi).rev(), move|note, i| { let mut bg = if note == note_pt { TuiTheme::g(64) } else { Color::Reset }; let mut fg = TuiTheme::g(160); if let Some((index, _)) = self.0.sampler.recording { diff --git a/src/pool.rs b/src/pool.rs index 605f7eff..da64d8d6 100644 --- a/src/pool.rs +++ b/src/pool.rs @@ -216,10 +216,10 @@ render!(Tui: (self: PoolView<'a>) => { let color = self.0.phrase().read().unwrap().color; let border = Fill::xy(Outer(Style::default().fg(color.base.rgb).bg(bg))); let enclose = |x|lay!(border, Padding::xy(0, 1, Tui::bg(bg, x))); - let content = Cond::either( + let content = Tui::either( self.0.file_picker().is_some(), Thunk::new(||self.0.file_picker().unwrap()), - Thunk::new(||Coll::map(phrases.iter(), |phrase, i|{ + Thunk::new(||Tui::map(phrases.iter(), |phrase, i|{ let MidiClip { ref name, color, length, .. } = *phrase.read().unwrap(); let mut length = PhraseLength::new(length, None); if let Some(PoolMode::Length(phrase, new_length, focus)) = self.0.mode { @@ -243,7 +243,7 @@ render!(Tui: (self: PoolView<'a>) => { row2 }), ))); - Push::y(i as u16 * 2, lay!(clip, Cond::when(i == self.0.phrase_index(), CORNERS))) + Push::y(i as u16 * 2, lay!(clip, Tui::when(i == self.0.phrase_index(), CORNERS))) }))); enclose(lay!( //add(&Lozenge(Style::default().bg(border_bg).fg(border_color)))?; diff --git a/src/sequencer.rs b/src/sequencer.rs index f6365fc1..727ea4bb 100644 --- a/src/sequencer.rs +++ b/src/sequencer.rs @@ -56,12 +56,12 @@ render!(Tui: (self: SequencerTui) => { p.as_ref().map(|p|p.read().unwrap().color) ).flatten().clone(); - let toolbar = Cond::when(self.transport, row!( + let toolbar = Tui::when(self.transport, row!( PlayPause(self.clock.is_rolling()), TransportView::new(self, color, true), )); - let play_queue = Cond::when(self.selectors, row!( + let play_queue = Tui::when(self.selectors, row!( PhraseSelector::play_phrase(&self.player), PhraseSelector::next_phrase(&self.player), )); diff --git a/src/transport.rs b/src/transport.rs index 387e3476..7fa382d4 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -121,7 +121,7 @@ render!(Tui: (self: TransportField) => row!( pub struct PlayPause(pub bool); render!(Tui: (self: PlayPause) => Tui::bg( if self.0{Color::Rgb(0,128,0)}else{Color::Rgb(128,64,0)}, - Fixed::x(5, Cond::either(self.0, Tui::fg(Color::Rgb(0, 255, 0), col!( + Fixed::x(5, Tui::either(self.0, Tui::fg(Color::Rgb(0, 255, 0), col!( " 🭍🭑🬽 ", " 🭞🭜🭘 ", )), Tui::fg(Color::Rgb(255, 128, 0), col!(