mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
implement has_size
This commit is contained in:
parent
aa8a1a3bd9
commit
c27a4a5232
3 changed files with 17 additions and 21 deletions
|
|
@ -4,19 +4,13 @@ pub trait HasSize<E: Engine> {
|
||||||
fn size (&self) -> &Measure<E>;
|
fn size (&self) -> &Measure<E>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export] macro_rules! implementor {
|
#[macro_export] macro_rules! has_size {
|
||||||
($name:ident => $Trait:ident) => {
|
(<$E:ty>|$self:ident:$Struct:ident$(<$($L:lifetime),*$($T:ident$(:$U:path)?),*>)?|$cb:expr) => {
|
||||||
#[macro_export] macro_rules! $name {
|
impl $(<$($L),*$($T $(: $U)?),*>)? HasSize<$E> for $Struct $(<$($L),*$($T),*>)? {
|
||||||
(|$self:ident:$Struct:ident$(<$($L:lifetime),*$($T:ident$(:$U:path)?),*>)?|$cb:expr) => {
|
fn size (&$self) -> &Measure<$E> { $cb } // TODO provide trait body
|
||||||
impl $(<$($L),*$($T $(: $U)?),*>)? $Trait for $Struct $(<$($L),*$($T),*>)? {
|
|
||||||
fn clock (&$self) -> &ClockModel { $cb }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
implementor!(has_size => HasSize);
|
|
||||||
|
|
||||||
impl<E: Engine> LayoutDebug<E> for E {}
|
impl<E: Engine> LayoutDebug<E> for E {}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ impl Default for PhraseEditorModel {
|
||||||
|
|
||||||
render!(|self: PhraseEditorModel|self.mode);
|
render!(|self: PhraseEditorModel|self.mode);
|
||||||
|
|
||||||
pub trait PhraseViewMode: Render<Tui> + MIDIRange + MIDIPoint + Debug + Send + Sync {
|
pub trait PhraseViewMode: Render<Tui> + HasSize<Tui> + MIDIRange + MIDIPoint + Debug + Send + Sync {
|
||||||
fn buffer_size (&self, phrase: &Phrase) -> (usize, usize);
|
fn buffer_size (&self, phrase: &Phrase) -> (usize, usize);
|
||||||
fn redraw (&mut self);
|
fn redraw (&mut self);
|
||||||
fn phrase (&self) -> &Option<Arc<RwLock<Phrase>>>;
|
fn phrase (&self) -> &Option<Arc<RwLock<Phrase>>>;
|
||||||
|
|
@ -124,7 +124,7 @@ pub trait PhraseViewMode: Render<Tui> + MIDIRange + MIDIPoint + Debug + Send + S
|
||||||
|
|
||||||
impl MIDIViewport<Tui> for PhraseEditorModel {}
|
impl MIDIViewport<Tui> for PhraseEditorModel {}
|
||||||
|
|
||||||
has_size!(|self:PhraseEditorModel|&self.size);
|
has_size!(<Tui>|self:PhraseEditorModel|self.mode.size());
|
||||||
|
|
||||||
impl MIDIRange for PhraseEditorModel {
|
impl MIDIRange for PhraseEditorModel {
|
||||||
fn time_zoom (&self) -> usize { self.mode.time_zoom() }
|
fn time_zoom (&self) -> usize { self.mode.time_zoom() }
|
||||||
|
|
|
||||||
|
|
@ -241,6 +241,8 @@ impl PianoHorizontal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
has_size!(<Tui>|self:PianoHorizontal|&self.size);
|
||||||
|
|
||||||
impl MIDIRange for PianoHorizontal {
|
impl MIDIRange for PianoHorizontal {
|
||||||
fn time_zoom (&self) -> usize { self.range.time_zoom() }
|
fn time_zoom (&self) -> usize { self.range.time_zoom() }
|
||||||
fn set_time_zoom (&self, x: usize) { self.range.set_time_zoom(x); }
|
fn set_time_zoom (&self, x: usize) { self.range.set_time_zoom(x); }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue