From e21ef1af9469f80810bb56a3a817bca05a732d1f Mon Sep 17 00:00:00 2001 From: unspeaker Date: Mon, 30 Dec 2024 21:38:41 +0100 Subject: [PATCH] wip: big flat pt.12, down to 1 error --- layout/src/space.rs | 10 ++++++- src/arranger/arranger_v/v_cursor.rs | 2 +- src/lib.rs | 2 +- src/midi/midi_editor.rs | 8 ++++++ src/piano_h.rs | 2 +- src/piano_h/piano_h_cursor.rs | 6 ++-- src/sampler/sample_import.rs | 2 +- src/sampler/sample_viewer.rs | 8 +----- src/sampler/sampler_tui.rs | 43 +++++++++++++++++++---------- 9 files changed, 53 insertions(+), 30 deletions(-) diff --git a/layout/src/space.rs b/layout/src/space.rs index 9d4ec207..fde0acfe 100644 --- a/layout/src/space.rs +++ b/layout/src/space.rs @@ -1,5 +1,5 @@ use crate::*; -use std::sync::{Arc, atomic::AtomicUsize}; +use std::sync::{Arc, atomic::{AtomicUsize, Ordering::Relaxed}}; impl Direction { pub fn is_north (&self) -> bool { matches!(self, Self::North) } @@ -46,6 +46,14 @@ pub struct Measure { pub y: Arc, } +render!(Measure + |self, layout|Ok(Some(layout)), + |self, render|{ + self.x.store(render.area().w().into(), Relaxed); + self.y.store(render.area().h().into(), Relaxed); + Ok(()) + }); + impl Clone for Measure { fn clone (&self) -> Self { Self { diff --git a/src/arranger/arranger_v/v_cursor.rs b/src/arranger/arranger_v/v_cursor.rs index 79474951..eb945a85 100644 --- a/src/arranger/arranger_v/v_cursor.rs +++ b/src/arranger/arranger_v/v_cursor.rs @@ -26,7 +26,7 @@ from!(|args:(&ArrangerTui, usize)|ArrangerVCursor = Self { }); render!((self: ArrangerVCursor) - |layout|Ok([0, 0]), + |layout|Ok(Some([0, 0])), |render|{ let area = render.area(); let focused = true; diff --git a/src/lib.rs b/src/lib.rs index 92302e94..986130f1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,7 +21,7 @@ pub(crate) use ::tek_layout::{ }, ratatui::{ self, - prelude::{Color, Style, Buffer, Modifier}, + prelude::{Color, Style, Stylize, Buffer, Modifier}, buffer::Cell, } } diff --git a/src/midi/midi_editor.rs b/src/midi/midi_editor.rs index 2f23a620..50da17c5 100644 --- a/src/midi/midi_editor.rs +++ b/src/midi/midi_editor.rs @@ -135,6 +135,14 @@ impl Content for Box { Some(&(*self)) } } +impl Render for Box { + fn min_size (&self, to: [u16;2]) -> Perhaps<[u16;2]> { + self.content().unwrap().min_size(to) + } + fn render (&self, to: &mut TuiOutput) -> Usually<()> { + self.content().unwrap().render(to) + } +} impl MidiView for MidiEditor {} diff --git a/src/piano_h.rs b/src/piano_h.rs index 0d6b09bb..b63d544e 100644 --- a/src/piano_h.rs +++ b/src/piano_h.rs @@ -89,7 +89,7 @@ render!(|self: PianoHorizontal|{ Padding::xy(0, 1, Fill::xy(Bsp::s( Fixed::y(1, Bsp::e( Fixed::x(self.keys_width, ""), - Fill::w(timeline()), + Fill::x(timeline()), )), Bsp::e( Fixed::x(self.keys_width, keys()), diff --git a/src/piano_h/piano_h_cursor.rs b/src/piano_h/piano_h_cursor.rs index ffaf0e5d..6674f2d0 100644 --- a/src/piano_h/piano_h_cursor.rs +++ b/src/piano_h/piano_h_cursor.rs @@ -3,8 +3,8 @@ use super::note_y_iter; pub struct PianoHorizontalCursor<'a>(pub(crate) &'a PianoHorizontal); render!((self: PianoHorizontalCursor<'a>) - |layout|Ok([0, 0]), - |render|{ + |layout|Ok(Some([0, 0])), + |render|Ok({ let style = Some(Style::default().fg(self.0.color.lightest.rgb)); let note_hi = self.0.note_hi(); let note_len = self.0.note_len(); @@ -32,4 +32,4 @@ render!((self: PianoHorizontalCursor<'a>) break } } - }); + })); diff --git a/src/sampler/sample_import.rs b/src/sampler/sample_import.rs index e14609ff..9d3fb60c 100644 --- a/src/sampler/sample_import.rs +++ b/src/sampler/sample_import.rs @@ -21,7 +21,7 @@ pub struct AddSampleModal { _search: Option, } -impl Exit for AddSampleModal { +impl AddSampleModal { fn exited (&self) -> bool { self.exited } diff --git a/src/sampler/sample_viewer.rs b/src/sampler/sample_viewer.rs index c6b2e1c3..ee4222f5 100644 --- a/src/sampler/sample_viewer.rs +++ b/src/sampler/sample_viewer.rs @@ -49,16 +49,10 @@ render!((self: SampleViewer) ) }; - let draw = |ctx| { - for line in lines.iter() { - ctx.draw(line) - } - }; - Canvas::default() .x_bounds(x_bounds) .y_bounds(y_bounds) - .paint(draw) + .paint(|ctx| { for line in lines.iter() { ctx.draw(line) } }) .render(area, &mut render.buffer); Ok(()) diff --git a/src/sampler/sampler_tui.rs b/src/sampler/sampler_tui.rs index dcde284d..750a82d7 100644 --- a/src/sampler/sampler_tui.rs +++ b/src/sampler/sampler_tui.rs @@ -56,25 +56,38 @@ render!(|self: SamplerTui|{ Tui::fg(self.color.light.rgb, Tui::bold(true, &"Sampler")), with_size(Shrink::y(1, Bsp::e( Fixed::x(keys_width, keys()), - Fill::xy(render(|to: &mut TuiOutput|Ok({ - let x = to.area.x(); - let bg_base = self.color.darkest.rgb; - let bg_selected = self.color.darker.rgb; - let style_empty = Style::default().fg(self.color.base.rgb); - let style_full = Style::default().fg(self.color.lighter.rgb); - let note_hi = self.note_hi(); - let note_pt = self.note_point(); - for y in 0..self.size.h() { - let note = note_hi - y as usize; - let bg = if note == note_pt { bg_selected } else { bg_base }; - let style = Some(style_empty.bg(bg)); - to.blit(&" (no sample) ", x, to.area.y() + y as u16, style) - } - }))) + Fill::xy(SamplesTui { + color: self.color, + note_hi: self.note_hi(), + note_pt: self.note_point(), + height: self.size.h(), + }), ))), )))) }); +struct SamplesTui { + color: ItemPalette, + note_hi: usize, + note_pt: usize, + height: usize, +} +render!((self: SamplesTui) + |area|Ok(Some([15, 1])), + |render|Ok({ + let x = render.area.x(); + let bg_base = self.color.darkest.rgb; + let bg_selected = self.color.darker.rgb; + let style_empty = Style::default().fg(self.color.base.rgb); + let style_full = Style::default().fg(self.color.lighter.rgb); + for y in 0..self.height { + let note = self.note_hi - y as usize; + let bg = if note == self.note_pt { bg_selected } else { bg_base }; + let style = Some(style_empty.bg(bg)); + render.blit(&" (no sample) ", x, render.area.y() + y as u16, style) + } + })); + impl NoteRange for SamplerTui { fn note_lo (&self) -> &AtomicUsize { &self.note_lo } fn note_axis (&self) -> &AtomicUsize { &self.size.y }