From 5b57f2b998f3642ec3b5f45dc3a19abbceb267f1 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Thu, 2 Jan 2025 14:11:32 +0100 Subject: [PATCH] add Measure::of --- layout/src/measure.rs | 3 ++ src/midi/midi_editor.rs | 2 +- src/piano/piano_h.rs | 65 ++++++++------------------------------ src/piano/piano_h_notes.rs | 5 +-- 4 files changed, 21 insertions(+), 54 deletions(-) diff --git a/layout/src/measure.rs b/layout/src/measure.rs index d0529df4..98ccf85f 100644 --- a/layout/src/measure.rs +++ b/layout/src/measure.rs @@ -65,6 +65,9 @@ impl Measure { y: Arc::new(0.into()), } } + pub fn of > (&self, item: T) -> Bsp, T> { + Bsp::b(Fill::xy(&self), item) + } } ///// A scrollable area. diff --git a/src/midi/midi_editor.rs b/src/midi/midi_editor.rs index 612eda0e..deb2a508 100644 --- a/src/midi/midi_editor.rs +++ b/src/midi/midi_editor.rs @@ -45,7 +45,7 @@ has_size!(|self: MidiEditor|&self.size); render!(Tui: (self: MidiEditor) => { self.autoscroll(); self.autozoom(); - Fill::xy(Tui::bg(Color::Black, Bsp::b(&self.size, &self.mode))) + Fill::xy(Bsp::b(&self.size, &self.mode)) }); impl MidiView for MidiEditor {} diff --git a/src/piano/piano_h.rs b/src/piano/piano_h.rs index 6272b886..a0eb1dd6 100644 --- a/src/piano/piano_h.rs +++ b/src/piano/piano_h.rs @@ -11,67 +11,30 @@ render!(Tui: (self: PianoHorizontal) => { } else { (ItemPalette::from(TuiTheme::g(64)), String::new(), 0, false) }; - //let field = move|x, y|row!( - //Tui::fg_bg(color.lighter.rgb, color.darker.rgb, Tui::bold(true, x)), - //Tui::fg_bg(color.lighter.rgb, color.dark.rgb, y), - //); - let keys_width = 5; - let keys = move||PianoHorizontalKeys(self); - let timeline = move||PianoHorizontalTimeline(self); - let notes = move||PianoHorizontalNotes(self); - let cursor = move||PianoHorizontalCursor(self); - let status = move||row!( - //" ", - row!("Edit:", name.to_string()), " ", - row!("Length:", length.to_string()), " ", - row!("Loop:", looped.to_string()) + let field = move|x, y|row!( + Tui::fg_bg(color.lighter.rgb, color.darker.rgb, Tui::bold(true, x)), + Tui::fg_bg(color.lighter.rgb, color.dark.rgb, y), ); Bsp::s( - Fixed::y(1, status()), + Fixed::y(1, row!( + field("Edit:", name.to_string()), " ", + field("Length:", length.to_string()), " ", + field("Loop:", looped.to_string()) + )), Bsp::s( Fixed::y(1, Bsp::e( Fixed::x(self.keys_width, ""), - Fill::x(timeline()), + Fill::x(PianoHorizontalTimeline(self)), )), Fill::xy(Bsp::e( - Fixed::x(self.keys_width, keys()), - Fill::xy("test") - //Fill::xy(lay!( - //&self.size, - //Fill::xy(lay!( - //Fill::xy(notes()), - //Fill::xy(cursor()), - //)) - //)), + Fixed::x(self.keys_width, PianoHorizontalKeys(self)), + Fill::xy(self.size.of(lay!( + Fill::xy(PianoHorizontalNotes(self)), + Fill::xy(PianoHorizontalCursor(self)), + ))), )), ) ) - //"kyp" - //Outer(Style::default().fg(self.color.dark.rgb).bg(self.color.darkest.rgb)).enclose("kyp"); - //with_border(lay!( - //row!( - ////" ", - //field("Edit:", name.to_string()), " ", - //field("Length:", length.to_string()), " ", - //field("Loop:", looped.to_string()) - //)), - //Padding::xy(0, 1, Fill::xy(Bsp::s( - //Fixed::y(1, Bsp::e( - //Fixed::x(self.keys_width, ""), - //Fill::x(timeline()), - //)), - //Bsp::e( - //Fixed::x(self.keys_width, keys()), - //Fill::xy(lay!( - //&self.size, - //Fill::xy(lay!( - //Fill::xy(notes()), - //Fill::xy(cursor()), - //)) - //)), - //), - //))) - //)) }); impl PianoHorizontal { diff --git a/src/piano/piano_h_notes.rs b/src/piano/piano_h_notes.rs index 541b681c..3bc42f6c 100644 --- a/src/piano/piano_h_notes.rs +++ b/src/piano/piano_h_notes.rs @@ -5,13 +5,14 @@ pub struct PianoHorizontalNotes<'a>(pub(crate) &'a PianoHorizontal); render!(Tui: |self: PianoHorizontalNotes<'a>, render|{ let time_start = self.0.time_start().get(); + let note_axis = self.0.note_axis().get(); let note_lo = self.0.note_lo().get(); let note_hi = self.0.note_hi(); let note_point = self.0.note_point(); let source = &self.0.buffer; let [x0, y0, w, h] = render.area().xywh(); - if h as usize != self.0.note_axis().get() { - panic!("area height mismatch"); + if h as usize != note_axis { + panic!("area height mismatch: {h} <> {note_axis}"); } for (area_x, screen_x) in (x0..x0+w).enumerate() { for (area_y, screen_y, note) in note_y_iter(note_lo, note_hi, y0) {