mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
impl Content instead of Widget for transport
This commit is contained in:
parent
56db9cfce1
commit
2733b6b947
1 changed files with 56 additions and 82 deletions
|
|
@ -315,28 +315,21 @@ impl Handle<Tui> for TransportBPM<Tui> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Widget for TransportBPM<Tui> {
|
impl Content for TransportBPM<Tui> {
|
||||||
type Engine = Tui;
|
type Engine = Tui;
|
||||||
fn layout (&self, area: [u16;2]) -> Perhaps<[u16;2]> {
|
fn content (&self) -> impl Widget<Engine = Tui> {
|
||||||
area.expect_min(10, 1)?;
|
|
||||||
Ok(Some([10, 1]))
|
|
||||||
}
|
|
||||||
fn render (&self, to: &mut TuiOutput) -> Usually<()> {
|
|
||||||
let area = to.area();
|
|
||||||
let [x, y, ..] = area;
|
|
||||||
let Self { value, focused, .. } = self;
|
let Self { value, focused, .. } = self;
|
||||||
to.blit(&"BPM", x, y, Some(NOT_DIM));
|
Layers::new(move|add|{
|
||||||
let bpm = format!("{}.{:03}", value, (value * 1000.0) % 1000.0);
|
add(&Outset::X(1u16, Split::down(|add|{
|
||||||
to.blit(&bpm, x, y + 1, Some(NOT_DIM_BOLD));
|
add(&"BPM")?;
|
||||||
let width = bpm.len() as u16;
|
add(&format!("{}.{:03}", value, (value * 1000.0) % 1000.0).as_str())
|
||||||
let area = [x, y, (width + 2).max(10), 2];
|
})))?;
|
||||||
if *focused {
|
if *focused {
|
||||||
let area = [area.x() - 1, area.y(), area.w() - 1, area.h() ];
|
add(&CORNERS)?;
|
||||||
CORNERS.draw(to)?;
|
add(&Background(COLOR_BG1))?;
|
||||||
to.fill_bg(area, COLOR_BG1);
|
}
|
||||||
}
|
Ok(())
|
||||||
//Ok(Some(area))
|
})
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -370,27 +363,21 @@ impl Handle<Tui> for TransportQuantize<Tui> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Widget for TransportQuantize<Tui> {
|
impl Content for TransportQuantize<Tui> {
|
||||||
type Engine = Tui;
|
type Engine = Tui;
|
||||||
fn layout (&self, area: [u16;2]) -> Perhaps<[u16;2]> {
|
fn content (&self) -> impl Widget<Engine = Tui> {
|
||||||
area.expect_min(10, 1)?;
|
|
||||||
Ok(Some([10, 1]))
|
|
||||||
}
|
|
||||||
fn render (&self, to: &mut TuiOutput) -> Usually<()> {
|
|
||||||
let [x, y, ..] = to.area();
|
|
||||||
let Self { value, focused, .. } = self;
|
let Self { value, focused, .. } = self;
|
||||||
to.blit(&"QUANT", x, y, Some(NOT_DIM));
|
Layers::new(move|add|{
|
||||||
let name = ppq_to_name(*value as usize);
|
add(&Outset::X(1u16, Split::down(|add|{
|
||||||
let width = name.len() as u16;
|
add(&"QUANT")?;
|
||||||
to.blit(&name, x, y + 1, Some(NOT_DIM_BOLD));
|
add(&ppq_to_name(*value as usize))
|
||||||
let area = [x, y, (width + 2).max(10), 2];
|
})))?;
|
||||||
if *focused {
|
if *focused {
|
||||||
let area = [area.x() - 1, area.y(), area.w() - 1, area.h() ];
|
add(&CORNERS)?;
|
||||||
CORNERS.draw(to)?;
|
add(&Background(COLOR_BG1))?;
|
||||||
to.fill_bg(area, COLOR_BG1);
|
}
|
||||||
}
|
Ok(())
|
||||||
//Ok(Some(area))
|
})
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -424,27 +411,21 @@ impl Handle<Tui> for TransportSync<Tui> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Widget for TransportSync<Tui> {
|
impl Content for TransportSync<Tui> {
|
||||||
type Engine = Tui;
|
type Engine = Tui;
|
||||||
fn layout (&self, area: [u16;2]) -> Perhaps<[u16;2]> {
|
fn content (&self) -> impl Widget<Engine = Tui> {
|
||||||
area.expect_min(10, 1)?;
|
|
||||||
Ok(Some([10, 1]))
|
|
||||||
}
|
|
||||||
fn render (&self, to: &mut TuiOutput) -> Usually<()> {
|
|
||||||
let [x, y, ..] = to.area();
|
|
||||||
let Self { value, focused, .. } = self;
|
let Self { value, focused, .. } = self;
|
||||||
to.blit(&"SYNC", x, y, Some(NOT_DIM));
|
Layers::new(move|add|{
|
||||||
let name = ppq_to_name(*value as usize);
|
add(&Outset::X(1u16, Split::down(|add|{
|
||||||
let width = name.len() as u16;
|
add(&"SYNC")?;
|
||||||
to.blit(&name, x, y + 1, Some(NOT_DIM_BOLD));
|
add(&ppq_to_name(*value as usize))
|
||||||
let area = [x, y, (width + 2).max(10), 2];
|
})))?;
|
||||||
if *focused {
|
if *focused {
|
||||||
let area = [area.x() - 1, area.y(), area.w() - 1, area.h() ];
|
add(&CORNERS)?;
|
||||||
CORNERS.draw(to)?;
|
add(&Background(COLOR_BG1))?;
|
||||||
to.fill_bg(area, COLOR_BG1);
|
}
|
||||||
}
|
Ok(())
|
||||||
//Ok(Some(area))
|
})
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -471,32 +452,25 @@ impl Handle<Tui> for TransportClock<Tui> {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Widget for TransportClock<Tui> {
|
impl Content for TransportClock<Tui> {
|
||||||
type Engine = Tui;
|
type Engine = Tui;
|
||||||
fn layout (&self, area: [u16;2]) -> Perhaps<[u16;2]> {
|
fn content (&self) -> impl Widget<Engine = Tui> {
|
||||||
area.expect_min(20, 1)?;
|
|
||||||
Ok(Some([20, 1]))
|
|
||||||
}
|
|
||||||
fn render (&self, to: &mut TuiOutput) -> Usually<()> {
|
|
||||||
let [x, y, width, _] = to.area();
|
|
||||||
let Self { frame: _frame, pulse, ppq, usecs, focused, .. } = self;
|
let Self { frame: _frame, pulse, ppq, usecs, focused, .. } = self;
|
||||||
let (beats, pulses) = if *ppq > 0 { (pulse / ppq, pulse % ppq) } else { (0, 0) };
|
Layers::new(move|add|{
|
||||||
let (bars, beats) = ((beats / 4) + 1, (beats % 4) + 1);
|
let (beats, pulses) = if *ppq > 0 { (pulse / ppq, pulse % ppq) } else { (0, 0) };
|
||||||
let (seconds, msecs) = (usecs / 1000000, usecs / 1000 % 1000);
|
let (bars, beats) = ((beats / 4) + 1, (beats % 4) + 1);
|
||||||
let (minutes, seconds) = (seconds / 60, seconds % 60);
|
let (seconds, msecs) = (usecs / 1000000, usecs / 1000 % 1000);
|
||||||
let timer = format!("{bars}.{beats}.{pulses:02}");
|
let (minutes, seconds) = (seconds / 60, seconds % 60);
|
||||||
to.blit(&timer, x + width - timer.len() as u16 - 1, y + 0, Some(NOT_DIM));
|
add(&Outset::X(1u16, Split::down(|add|{
|
||||||
let timer = format!("{minutes}:{seconds:02}:{msecs:03}");
|
add(&format!("{bars}.{beats}.{pulses:02}").as_str())?;
|
||||||
to.blit(&timer, x + width - timer.len() as u16 - 1, y + 1, Some(NOT_DIM));
|
add(&format!("{minutes}:{seconds:02}:{msecs:03}").as_str())
|
||||||
let area = to.area();
|
})))?;
|
||||||
let area = [area.x(), area.y(), area.w() + 1, area.h()];
|
if *focused {
|
||||||
if *focused {
|
add(&CORNERS)?;
|
||||||
let area = [area.x() - 1, area.y(), area.w(), area.h() ];
|
add(&Background(COLOR_BG1))?;
|
||||||
CORNERS.draw(to)?;
|
}
|
||||||
to.fill_bg(area, COLOR_BG1);
|
Ok(())
|
||||||
}
|
})
|
||||||
//Ok(Some(area))
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue