mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
implement Measure component
This commit is contained in:
parent
4983523da6
commit
75c9a4ce49
3 changed files with 53 additions and 53 deletions
|
|
@ -66,10 +66,8 @@ pub struct Arrangement<E: Engine> {
|
|||
pub focused: bool,
|
||||
/// Background color of arrangement
|
||||
pub color: Color,
|
||||
/// Width of arrangement area at last render
|
||||
pub width: AtomicUsize,
|
||||
/// Height of arrangement area at last render
|
||||
pub height: AtomicUsize,
|
||||
/// Width and height of arrangement area at last render
|
||||
pub size: Measure<E>,
|
||||
}
|
||||
/// Represents a track in the arrangement
|
||||
pub struct ArrangementTrack<E: Engine> {
|
||||
|
|
@ -238,8 +236,7 @@ impl<E: Engine> Arrangement<E> {
|
|||
tracks: vec![],
|
||||
focused: false,
|
||||
color: Color::Rgb(28, 35, 25),
|
||||
width: 0.into(),
|
||||
height: 0.into(),
|
||||
size: Measure::new(),
|
||||
}
|
||||
}
|
||||
pub fn activate (&mut self) {
|
||||
|
|
|
|||
|
|
@ -146,30 +146,21 @@ impl<'a> Content for VerticalArranger<'a, Tui> {
|
|||
let rows: &[(usize, usize)] = rows.as_ref();
|
||||
let cols: &[(usize, usize)] = cols.as_ref();
|
||||
let any_size = |_|Ok(Some([0,0]));
|
||||
|
||||
// store render area
|
||||
add(&CustomWidget::new(any_size, move|to: &mut TuiOutput|{
|
||||
let [x, y, w, h] = to.area();
|
||||
self.0.width.store(w as usize, Ordering::Relaxed);
|
||||
self.0.height.store(h as usize, Ordering::Relaxed);
|
||||
Ok(())
|
||||
}))?;
|
||||
|
||||
add(&self.0.size)?;
|
||||
// column separators
|
||||
add(&CustomWidget::new(any_size, move|to: &mut TuiOutput|{
|
||||
let area = to.area();
|
||||
let style = Some(Style::default().fg(COLOR_SEPARATOR));
|
||||
for x in cols.iter().map(|col|col.1) {
|
||||
Ok(for x in cols.iter().map(|col|col.1) {
|
||||
let x = scene_title_w + area.x() + x as u16;
|
||||
for y in area.y()..area.y2() { to.blit(&"▎", x, y, style); }
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
}))?;
|
||||
|
||||
// row separators
|
||||
add(&CustomWidget::new(any_size, move|to: &mut TuiOutput|{
|
||||
let area = to.area();
|
||||
for y in rows.iter().map(|row|row.1) {
|
||||
Ok(for y in rows.iter().map(|row|row.1) {
|
||||
let y = area.y() + (y / PPQ) as u16 + 1;
|
||||
if y >= to.buffer.area.height { break }
|
||||
for x in area.x()..area.x2().saturating_sub(2) {
|
||||
|
|
@ -179,10 +170,8 @@ impl<'a> Content for VerticalArranger<'a, Tui> {
|
|||
cell.underline_color = COLOR_SEPARATOR;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
}))?;
|
||||
|
||||
// track titles
|
||||
let header = row!((track, w) in tracks.iter().zip(cols.iter().map(|col|col.0))=>{
|
||||
let name = track.name.read().unwrap();
|
||||
|
|
@ -211,13 +200,11 @@ impl<'a> Content for VerticalArranger<'a, Tui> {
|
|||
.bg(track.color)
|
||||
.push_x(scene_title_w)
|
||||
});
|
||||
|
||||
// scene titles
|
||||
let scene_name = |scene, playing: bool, height|row!(
|
||||
if playing { "▶ " } else { " " },
|
||||
TuiStyle::bold((scene as &Scene).name.read().unwrap().as_str(), true),
|
||||
).fixed_xy(scene_title_w, height);
|
||||
|
||||
// scene clips
|
||||
let scene_clip = |scene, track: usize, w: u16, h: u16|Layers::new(move |add|{
|
||||
let mut color = clip_bg;
|
||||
|
|
@ -233,27 +220,22 @@ impl<'a> Content for VerticalArranger<'a, Tui> {
|
|||
};
|
||||
add(&Background(color))
|
||||
}).fixed_xy(w, h);
|
||||
|
||||
add(&col!(
|
||||
header,
|
||||
col!(
|
||||
// scenes:
|
||||
(scene, pulses) in scenes.iter().zip(rows.iter().map(|row|row.0)) => {
|
||||
let height = 1.max((pulses / PPQ) as u16);
|
||||
let playing = scene.is_playing(tracks);
|
||||
Stack::right(move |add| {
|
||||
// scene title:
|
||||
add(&scene_name(scene, playing, height).bg(scene.color))?;
|
||||
// clip per track:
|
||||
for (track, w) in cols.iter().map(|col|col.0).enumerate() {
|
||||
add(&scene_clip(scene, track, w as u16, height))?;
|
||||
}
|
||||
Ok(())
|
||||
}).fixed_y(height)
|
||||
}
|
||||
),
|
||||
))?;
|
||||
|
||||
// tracks and scenes
|
||||
add(&col!(header, col!(
|
||||
// scenes:
|
||||
(scene, pulses) in scenes.iter().zip(rows.iter().map(|row|row.0)) => {
|
||||
let height = 1.max((pulses / PPQ) as u16);
|
||||
let playing = scene.is_playing(tracks);
|
||||
Stack::right(move |add| {
|
||||
// scene title:
|
||||
add(&scene_name(scene, playing, height).bg(scene.color))?;
|
||||
// clip per track:
|
||||
Ok(for (track, w) in cols.iter().map(|col|col.0).enumerate() {
|
||||
add(&scene_clip(scene, track, w as u16, height))?;
|
||||
})
|
||||
}).fixed_y(height)
|
||||
}
|
||||
)))?;
|
||||
// cursor
|
||||
add(&CustomWidget::new(any_size, move|to: &mut TuiOutput|{
|
||||
let area = to.area();
|
||||
|
|
@ -317,18 +299,14 @@ impl<'a> Content for VerticalArranger<'a, Tui> {
|
|||
}
|
||||
}
|
||||
Ok(())
|
||||
}))?;
|
||||
|
||||
Ok(())
|
||||
}))
|
||||
}).bg(bg).grow_y(1).border(border);
|
||||
|
||||
let title_color = if self.0.focused {
|
||||
Color::Rgb(150, 160, 90)
|
||||
} else {
|
||||
Color::Rgb(120, 130, 100)
|
||||
};
|
||||
let w = self.0.width.load(Ordering::Relaxed);
|
||||
let h = self.0.height.load(Ordering::Relaxed);
|
||||
let [w, h] = self.0.size.wh();
|
||||
let lower_right = TuiStyle::fg(format!("{w}x{h}"), title_color)
|
||||
.pull_x(1).align_se().fill_xy();
|
||||
lay!(content, lower_right)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue