mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-16 17:06:45 +01:00
73 lines
2.4 KiB
Rust
73 lines
2.4 KiB
Rust
use crate::*;
|
|
|
|
/// Define a type alias for iterators of sized items (columns).
|
|
macro_rules! def_sizes_iter {
|
|
($Type:ident => $($Item:ty),+) => {
|
|
pub(crate) trait $Type<'a> =
|
|
Iterator<Item=(usize, $(&'a $Item,)+ usize, usize)> + Send + Sync + 'a;}}
|
|
|
|
def_sizes_iter!(ScenesSizes => Scene);
|
|
def_sizes_iter!(TracksSizes => Track);
|
|
def_sizes_iter!(InputsSizes => JackMidiIn);
|
|
def_sizes_iter!(OutputsSizes => JackMidiOut);
|
|
def_sizes_iter!(PortsSizes => Arc<str>, [PortConnect]);
|
|
|
|
impl Tek {
|
|
/// Spacing between tracks.
|
|
pub(crate) const TRACK_SPACING: usize = 0;
|
|
/// Default scene height.
|
|
pub(crate) const H_SCENE: usize = 2;
|
|
/// Default editor height.
|
|
pub(crate) const H_EDITOR: usize = 15;
|
|
|
|
/// Width of display
|
|
pub(crate) fn w (&self) -> u16 {
|
|
self.size.w() as u16
|
|
}
|
|
pub(crate) fn w_sidebar (&self) -> u16 {
|
|
self.w() / if self.is_editing() { 16 } else { 8 } as u16
|
|
}
|
|
/// Width taken by all tracks.
|
|
pub(crate) fn w_tracks (&self) -> u16 {
|
|
self.tracks_sizes().last().map(|(_, _, _, x)|x as u16).unwrap_or(0)
|
|
}
|
|
/// Width available to display tracks.
|
|
pub(crate) fn w_tracks_area (&self) -> u16 {
|
|
self.w().saturating_sub(2 * self.w_sidebar())
|
|
}
|
|
/// Height of display
|
|
pub(crate) fn h (&self) -> u16 {
|
|
self.size.h() as u16
|
|
}
|
|
/// Height available to display tracks.
|
|
pub(crate) fn h_tracks_area (&self) -> u16 {
|
|
self.h().saturating_sub(self.h_inputs() + self.h_outputs() + 10)
|
|
}
|
|
/// Height taken by all inputs.
|
|
pub(crate) fn h_inputs (&self) -> u16 {
|
|
1 + self.inputs_sizes().last().map(|(_, _, _, _, y)|y as u16).unwrap_or(0)
|
|
}
|
|
/// Height taken by all outputs.
|
|
pub(crate) fn h_outputs (&self) -> u16 {
|
|
1 + self.outputs_sizes().last().map(|(_, _, _, _, y)|y as u16).unwrap_or(0)
|
|
}
|
|
/// Height taken by all scenes.
|
|
pub(crate) fn h_scenes (&self) -> u16 {
|
|
self.scenes_sizes(self.is_editing(), Self::H_SCENE, Self::H_EDITOR).last()
|
|
.map(|(_, _, _, y)|y as u16).unwrap_or(0)
|
|
}
|
|
}
|
|
#[cfg(test)] mod test {
|
|
use super::*;
|
|
#[test] fn test_view_size () {
|
|
let app = Tek::default();
|
|
let _ = app.w();
|
|
let _ = app.w_sidebar();
|
|
let _ = app.w_tracks_area();
|
|
let _ = app.h();
|
|
let _ = app.h_tracks_area();
|
|
let _ = app.h_inputs();
|
|
let _ = app.h_outputs();
|
|
let _ = app.h_scenes();
|
|
}
|
|
}
|