ClipsView: refactor those horrible nested closures

This commit is contained in:
🪞👃🪞 2025-05-17 08:07:51 +03:00
parent 4d0868add8
commit e9b4a2ca78

View file

@ -31,36 +31,45 @@ impl ClipCommand {
} }
} }
impl Arrangement {
}
impl ClipsView for Arrangement {} impl ClipsView for Arrangement {}
impl<'a> ClipsView for ArrangerView<'a> {} impl<'a> ClipsView for ArrangerView<'a> {}
pub trait ClipsView: HasTrackScroll + HasSceneScroll + Send + Sync { pub trait ClipsView: HasTrackScroll + HasSceneScroll + Send + Sync {
fn scenes_clips_2 <'a> (&'a self, theme: ItemTheme) -> impl Content<TuiOut> + 'a { fn scenes_clips_2 <'a> (
Fixed::y(self.scenes().len() as u16 * 2, &'a self,
Tui::bg(theme.darker.rgb, theme: ItemTheme
Align::w(Fill::x(Map::new( ) -> impl Content<TuiOut> + 'a {
||self.scenes().iter().skip(self.scene_scroll()), Fixed::y(self.scenes().len() as u16 * 2, Tui::bg(theme.darker.rgb,
move|scene: &'a Scene, index|self.track_scenes(scene, index)))))) Align::w(Fill::x(Map::new(||self.scenes().iter().skip(self.scene_scroll()),
move|scene: &'a Scene, index|self.track_scenes(index, scene))))))
} }
fn track_scenes (&self, scene: &Scene, scene_index: usize) -> impl Content<TuiOut> { fn track_scenes <'a> (
&'a self,
scene_index: usize,
scene: &'a Scene
) -> impl Content<TuiOut> + 'a {
Push::y(scene_index as u16 * 2u16, Fixed::xy(20, 2, Map::new( Push::y(scene_index as u16 * 2u16, Fixed::xy(20, 2, Map::new(
move||scene.clips.iter().skip(self.track_scroll()), move||scene.clips.iter().skip(self.track_scroll()),
move|clip: &Option<Arc<RwLock<MidiClip>>>, track_index|{ move|clip: &'a Option<Arc<RwLock<MidiClip>>>, track_index|
let (theme, text) = if let Some(clip) = clip { self.track_scene_clip(scene_index, scene, track_index, clip))))
let clip = clip.read().unwrap(); }
(clip.color, clip.name.clone()) fn track_scene_clip (
} else { &self,
(scene.color, Default::default()) scene_index: usize,
}; scene: &Scene,
Push::x(track_index as u16 * 14, Tui::bg(theme.dark.rgb, Bsp::e( track_index: usize,
format!(" {scene_index:2} {track_index:2} "), clip: &Option<Arc<RwLock<MidiClip>>>
Tui::fg(Rgb(255, 255, 255), ) -> impl Content<TuiOut> {
Tui::bold(true, format!("{}", text)))))) let (theme, text) = if let Some(clip) = clip {
}))) let clip = clip.read().unwrap();
(clip.color, clip.name.clone())
} else {
(scene.color, Default::default())
};
Push::x(track_index as u16 * 14, Tui::bg(theme.dark.rgb, Bsp::e(
format!(" {scene_index:2} {track_index:2} "),
Tui::fg(Rgb(255, 255, 255),
Tui::bold(true, format!("{}", text))))))
} }
} }