mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
88 lines
2.3 KiB
Rust
88 lines
2.3 KiB
Rust
use crate::*;
|
|
|
|
/// Stores and displays time-related info.
|
|
pub struct TransportTui {
|
|
pub jack: Arc<RwLock<JackClient>>,
|
|
pub clock: ClockModel,
|
|
pub size: Measure<Tui>,
|
|
pub cursor: (usize, usize),
|
|
pub focus: FocusState<TransportFocus>,
|
|
}
|
|
|
|
/// Create app state from JACK handle.
|
|
impl TryFrom<&Arc<RwLock<JackClient>>> for TransportTui {
|
|
type Error = Box<dyn std::error::Error>;
|
|
fn try_from (jack: &Arc<RwLock<JackClient>>) -> Usually<Self> {
|
|
Ok(Self {
|
|
jack: jack.clone(),
|
|
clock: ClockModel::from(&Arc::new(jack.read().unwrap().transport())),
|
|
size: Measure::new(),
|
|
cursor: (0, 0),
|
|
focus: FocusState::Entered(TransportFocus::PlayPause)
|
|
})
|
|
}
|
|
}
|
|
|
|
/// Which item of the transport toolbar is focused
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
pub enum TransportFocus {
|
|
Bpm,
|
|
Sync,
|
|
PlayPause,
|
|
Clock,
|
|
Quant,
|
|
}
|
|
|
|
impl FocusWrap<TransportFocus> for TransportFocus {
|
|
fn wrap <'a, W: Widget<Engine = Tui>> (self, focus: TransportFocus, content: &'a W)
|
|
-> impl Widget<Engine = Tui> + 'a
|
|
{
|
|
let focused = focus == self;
|
|
let corners = focused.then_some(CORNERS);
|
|
let highlight = focused.then_some(Background(Color::Rgb(60, 70, 50)));
|
|
lay!(corners, highlight, *content)
|
|
}
|
|
}
|
|
|
|
impl FocusWrap<TransportFocus> for Option<TransportFocus> {
|
|
fn wrap <'a, W: Widget<Engine = Tui>> (self, focus: TransportFocus, content: &'a W)
|
|
-> impl Widget<Engine = Tui> + 'a
|
|
{
|
|
let focused = Some(focus) == self;
|
|
let corners = focused.then_some(CORNERS);
|
|
let highlight = focused.then_some(Background(Color::Rgb(60, 70, 50)));
|
|
lay!(corners, highlight, *content)
|
|
}
|
|
}
|
|
|
|
impl_focus!(TransportTui TransportFocus [
|
|
//&[Menu],
|
|
&[
|
|
PlayPause,
|
|
Bpm,
|
|
Sync,
|
|
Quant,
|
|
Clock,
|
|
],
|
|
]);
|
|
|
|
#[derive(Copy, Clone)]
|
|
pub struct TransportStatusBar;
|
|
|
|
impl StatusBar for TransportStatusBar {
|
|
type State = ();
|
|
fn hotkey_fg () -> Color {
|
|
TuiTheme::hotkey_fg()
|
|
}
|
|
fn update (&mut self, state: &()) {
|
|
todo!()
|
|
}
|
|
}
|
|
|
|
impl Content for TransportStatusBar {
|
|
type Engine = Tui;
|
|
fn content (&self) -> impl Widget<Engine = Tui> {
|
|
todo!();
|
|
""
|
|
}
|
|
}
|