mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
implement has_size
This commit is contained in:
parent
aa8a1a3bd9
commit
c27a4a5232
3 changed files with 17 additions and 21 deletions
|
|
@ -4,20 +4,14 @@ pub trait HasSize<E: Engine> {
|
|||
fn size (&self) -> &Measure<E>;
|
||||
}
|
||||
|
||||
#[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<E: Engine> LayoutDebug<E> for E {}
|
||||
|
||||
pub trait LayoutDebug<E: Engine> {
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ impl Command<PhraseEditorModel> for PhraseCommand {
|
|||
/// Contains state for viewing and editing a phrase
|
||||
pub struct PhraseEditorModel {
|
||||
/// Renders the phrase
|
||||
pub mode: Box<dyn PhraseViewMode>,
|
||||
pub mode: Box<dyn PhraseViewMode>,
|
||||
}
|
||||
|
||||
impl Default for PhraseEditorModel {
|
||||
|
|
@ -111,12 +111,12 @@ impl Default for PhraseEditorModel {
|
|||
|
||||
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 redraw (&mut self);
|
||||
fn phrase (&self) -> &Option<Arc<RwLock<Phrase>>>;
|
||||
fn phrase_mut (&mut self) -> &mut Option<Arc<RwLock<Phrase>>>;
|
||||
fn set_phrase (&mut self, phrase: Option<&Arc<RwLock<Phrase>>>) {
|
||||
fn redraw (&mut self);
|
||||
fn phrase (&self) -> &Option<Arc<RwLock<Phrase>>>;
|
||||
fn phrase_mut (&mut self) -> &mut Option<Arc<RwLock<Phrase>>>;
|
||||
fn set_phrase (&mut self, phrase: Option<&Arc<RwLock<Phrase>>>) {
|
||||
*self.phrase_mut() = phrase.map(|p|p.clone());
|
||||
self.redraw();
|
||||
}
|
||||
|
|
@ -124,7 +124,7 @@ pub trait PhraseViewMode: Render<Tui> + MIDIRange + MIDIPoint + Debug + Send + S
|
|||
|
||||
impl MIDIViewport<Tui> for PhraseEditorModel {}
|
||||
|
||||
has_size!(|self:PhraseEditorModel|&self.size);
|
||||
has_size!(<Tui>|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<Arc<RwLock<Phrase>>> {
|
||||
fn phrase (&self) -> &Option<Arc<RwLock<Phrase>>> {
|
||||
self.mode.phrase()
|
||||
}
|
||||
fn phrase_mut (&mut self) -> &mut Option<Arc<RwLock<Phrase>>> {
|
||||
fn phrase_mut (&mut self) -> &mut Option<Arc<RwLock<Phrase>>> {
|
||||
self.mode.phrase_mut()
|
||||
}
|
||||
fn set_phrase (&mut self, phrase: Option<&Arc<RwLock<Phrase>>>) {
|
||||
fn set_phrase (&mut self, phrase: Option<&Arc<RwLock<Phrase>>>) {
|
||||
self.mode.set_phrase(phrase)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -241,6 +241,8 @@ impl PianoHorizontal {
|
|||
}
|
||||
}
|
||||
|
||||
has_size!(<Tui>|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); }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue