mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
handle transport focus in parent
This commit is contained in:
parent
5c8cb8e413
commit
d577449b72
1 changed files with 32 additions and 57 deletions
|
|
@ -155,27 +155,29 @@ impl<E: Engine> Audio for TransportToolbar<E> {
|
|||
impl Handle<Tui> for TransportToolbar<Tui> {
|
||||
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
||||
match from.event() {
|
||||
key!(KeyCode::Left) => {
|
||||
self.focus_prev();
|
||||
Ok(Some(true))
|
||||
},
|
||||
key!(KeyCode::Right) => {
|
||||
self.focus_next();
|
||||
Ok(Some(true))
|
||||
},
|
||||
_ => self.focused_mut().handle(from)
|
||||
key!(KeyCode::Left) => { self.focus_prev(); },
|
||||
key!(KeyCode::Right) => { self.focus_next(); },
|
||||
_ => return self.focused_mut().handle(from)
|
||||
}
|
||||
Ok(Some(true))
|
||||
}
|
||||
}
|
||||
impl Content for TransportToolbar<Tui> {
|
||||
type Engine = Tui;
|
||||
fn content (&self) -> impl Widget<Engine = Tui> {
|
||||
Split::right(|add|{
|
||||
add(&self.playing)?;
|
||||
add(&self.bpm)?;
|
||||
add(&self.quant)?;
|
||||
add(&self.sync)?;
|
||||
add(&self.clock)?;
|
||||
let focus_wrap = |focused, component|Layers::new(move |add|{
|
||||
if focused {
|
||||
add(&CORNERS)?;
|
||||
add(&Background(COLOR_BG1))?;
|
||||
}
|
||||
add(component)
|
||||
});
|
||||
add(&focus_wrap(self.focused && self.playing.focused, &self.playing))?;
|
||||
add(&focus_wrap(self.focused && self.bpm.focused, &self.bpm))?;
|
||||
add(&focus_wrap(self.focused && self.quant.focused, &self.quant))?;
|
||||
add(&focus_wrap(self.focused && self.sync.focused, &self.sync))?;
|
||||
add(&focus_wrap(self.focused && self.clock.focused, &self.clock))?;
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
|
@ -260,7 +262,6 @@ impl Content for TransportPlayPauseButton<Tui> {
|
|||
type Engine = Tui;
|
||||
fn content (&self) -> impl Widget<Engine = Tui> {
|
||||
Layers::new(|add|{
|
||||
add(&self.focused.then_some(CORNERS))?;
|
||||
add(&Plus::X(1, Min::Y(2, Styled(match self.value {
|
||||
Some(TransportState::Stopped) => Some(GRAY_DIM.bold()),
|
||||
Some(TransportState::Starting) => Some(GRAY_NOT_DIM_BOLD),
|
||||
|
|
@ -307,18 +308,11 @@ impl Handle<Tui> for TransportBPM<Tui> {
|
|||
impl Content for TransportBPM<Tui> {
|
||||
type Engine = Tui;
|
||||
fn content (&self) -> impl Widget<Engine = Tui> {
|
||||
let Self { value, focused, .. } = self;
|
||||
Layers::new(move|add|{
|
||||
add(&Outset::X(1u16, Split::down(|add|{
|
||||
add(&"BPM")?;
|
||||
add(&format!("{}.{:03}", *value as usize, (value * 1000.0) % 1000.0).as_str())
|
||||
})))?;
|
||||
if *focused {
|
||||
add(&CORNERS)?;
|
||||
add(&Background(COLOR_BG1))?;
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
let Self { value, .. } = self;
|
||||
Outset::X(1u16, Split::down(move |add|{
|
||||
add(&"BPM")?;
|
||||
add(&format!("{}.{:03}", *value as usize, (value * 1000.0) % 1000.0).as_str())
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -355,18 +349,11 @@ impl Handle<Tui> for TransportQuantize<Tui> {
|
|||
impl Content for TransportQuantize<Tui> {
|
||||
type Engine = Tui;
|
||||
fn content (&self) -> impl Widget<Engine = Tui> {
|
||||
let Self { value, focused, .. } = self;
|
||||
Layers::new(move|add|{
|
||||
add(&Outset::X(1u16, Split::down(|add|{
|
||||
add(&"QUANT")?;
|
||||
add(&ppq_to_name(*value as usize))
|
||||
})))?;
|
||||
if *focused {
|
||||
add(&CORNERS)?;
|
||||
add(&Background(COLOR_BG1))?;
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
let Self { value, .. } = self;
|
||||
Outset::X(1u16, Split::down(|add|{
|
||||
add(&"QUANT")?;
|
||||
add(&ppq_to_name(*value as usize))
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -403,18 +390,11 @@ impl Handle<Tui> for TransportSync<Tui> {
|
|||
impl Content for TransportSync<Tui> {
|
||||
type Engine = Tui;
|
||||
fn content (&self) -> impl Widget<Engine = Tui> {
|
||||
let Self { value, focused, .. } = self;
|
||||
Layers::new(move|add|{
|
||||
add(&Outset::X(1u16, Split::down(|add|{
|
||||
add(&"SYNC")?;
|
||||
add(&ppq_to_name(*value as usize))
|
||||
})))?;
|
||||
if *focused {
|
||||
add(&CORNERS)?;
|
||||
add(&Background(COLOR_BG1))?;
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
let Self { value, .. } = self;
|
||||
Outset::X(1u16, Split::down(|add|{
|
||||
add(&"SYNC")?;
|
||||
add(&ppq_to_name(*value as usize))
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -453,12 +433,7 @@ impl Content for TransportClock<Tui> {
|
|||
add(&Outset::X(1u16, Split::down(|add|{
|
||||
add(&format!("{bars}.{beats}.{pulses:02}").as_str())?;
|
||||
add(&format!("{minutes}:{seconds:02}:{msecs:03}").as_str())
|
||||
})))?;
|
||||
if *focused {
|
||||
add(&CORNERS)?;
|
||||
add(&Background(COLOR_BG1))?;
|
||||
}
|
||||
Ok(())
|
||||
})))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue