diff --git a/crates/tek/src/layout/measure.rs b/crates/tek/src/layout/measure.rs index af163125..27429cb6 100644 --- a/crates/tek/src/layout/measure.rs +++ b/crates/tek/src/layout/measure.rs @@ -4,20 +4,14 @@ pub trait HasSize { fn size (&self) -> &Measure; } -#[macro_export] macro_rules! implementor { - ($name:ident => $Trait:ident) => { - #[macro_export] macro_rules! $name { - (|$self:ident:$Struct:ident$(<$($L:lifetime),*$($T:ident$(:$U:path)?),*>)?|$cb:expr) => { - impl $(<$($L),*$($T $(: $U)?),*>)? $Trait for $Struct $(<$($L),*$($T),*>)? { - fn clock (&$self) -> &ClockModel { $cb } - } - } +#[macro_export] macro_rules! has_size { + (<$E:ty>|$self:ident:$Struct:ident$(<$($L:lifetime),*$($T:ident$(:$U:path)?),*>)?|$cb:expr) => { + impl $(<$($L),*$($T $(: $U)?),*>)? HasSize<$E> for $Struct $(<$($L),*$($T),*>)? { + fn size (&$self) -> &Measure<$E> { $cb } // TODO provide trait body } } } -implementor!(has_size => HasSize); - impl LayoutDebug for E {} pub trait LayoutDebug { diff --git a/crates/tek/src/tui/phrase_editor.rs b/crates/tek/src/tui/phrase_editor.rs index c2793400..fc579483 100644 --- a/crates/tek/src/tui/phrase_editor.rs +++ b/crates/tek/src/tui/phrase_editor.rs @@ -100,7 +100,7 @@ impl Command for PhraseCommand { /// Contains state for viewing and editing a phrase pub struct PhraseEditorModel { /// Renders the phrase - pub mode: Box, + pub mode: Box, } impl Default for PhraseEditorModel { @@ -111,12 +111,12 @@ impl Default for PhraseEditorModel { render!(|self: PhraseEditorModel|self.mode); -pub trait PhraseViewMode: Render + MIDIRange + MIDIPoint + Debug + Send + Sync { +pub trait PhraseViewMode: Render + HasSize + MIDIRange + MIDIPoint + Debug + Send + Sync { fn buffer_size (&self, phrase: &Phrase) -> (usize, usize); - fn redraw (&mut self); - fn phrase (&self) -> &Option>>; - fn phrase_mut (&mut self) -> &mut Option>>; - fn set_phrase (&mut self, phrase: Option<&Arc>>) { + fn redraw (&mut self); + fn phrase (&self) -> &Option>>; + fn phrase_mut (&mut self) -> &mut Option>>; + fn set_phrase (&mut self, phrase: Option<&Arc>>) { *self.phrase_mut() = phrase.map(|p|p.clone()); self.redraw(); } @@ -124,7 +124,7 @@ pub trait PhraseViewMode: Render + MIDIRange + MIDIPoint + Debug + Send + S impl MIDIViewport for PhraseEditorModel {} -has_size!(|self:PhraseEditorModel|&self.size); +has_size!(|self:PhraseEditorModel|self.mode.size()); impl MIDIRange for PhraseEditorModel { fn time_zoom (&self) -> usize { self.mode.time_zoom() } @@ -150,16 +150,16 @@ impl PhraseViewMode for PhraseEditorModel { fn buffer_size (&self, phrase: &Phrase) -> (usize, usize) { self.mode.buffer_size(phrase) } - fn redraw (&mut self) { + fn redraw (&mut self) { self.mode.redraw() } - fn phrase (&self) -> &Option>> { + fn phrase (&self) -> &Option>> { self.mode.phrase() } - fn phrase_mut (&mut self) -> &mut Option>> { + fn phrase_mut (&mut self) -> &mut Option>> { self.mode.phrase_mut() } - fn set_phrase (&mut self, phrase: Option<&Arc>>) { + fn set_phrase (&mut self, phrase: Option<&Arc>>) { self.mode.set_phrase(phrase) } } diff --git a/crates/tek/src/tui/piano_horizontal.rs b/crates/tek/src/tui/piano_horizontal.rs index ca559a2e..5cabba28 100644 --- a/crates/tek/src/tui/piano_horizontal.rs +++ b/crates/tek/src/tui/piano_horizontal.rs @@ -241,6 +241,8 @@ impl PianoHorizontal { } } +has_size!(|self:PianoHorizontal|&self.size); + impl MIDIRange for PianoHorizontal { fn time_zoom (&self) -> usize { self.range.time_zoom() } fn set_time_zoom (&self, x: usize) { self.range.set_time_zoom(x); }