mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 05:06:43 +01:00
wip: refactor pt.20: 44 errors
This commit is contained in:
parent
914c2d6c09
commit
2188bccd63
25 changed files with 664 additions and 486 deletions
|
|
@ -1,7 +1,8 @@
|
|||
pub(crate) use tek_api::*;
|
||||
pub(crate) use tek_core::crossterm::event::{KeyCode, KeyModifiers};
|
||||
pub(crate) use tek_core::midly::{num::u7, live::LiveEvent, MidiMessage};
|
||||
pub(crate) use tek_core::jack::*;
|
||||
pub(crate) use tek_api::*;
|
||||
pub(crate) use tek_snd::*;
|
||||
|
||||
pub(crate) use std::collections::BTreeMap;
|
||||
pub(crate) use std::sync::{Arc, Mutex, RwLock};
|
||||
|
|
@ -10,9 +11,6 @@ pub(crate) use std::ffi::OsString;
|
|||
pub(crate) use std::fs::read_dir;
|
||||
|
||||
submod! {
|
||||
tui_app
|
||||
tui_app_foc
|
||||
|
||||
tui_arranger
|
||||
tui_arranger_bar
|
||||
tui_arranger_cmd
|
||||
|
|
@ -53,3 +51,142 @@ submod! {
|
|||
tui_transport_cmd
|
||||
tui_transport_foc
|
||||
}
|
||||
|
||||
pub struct AppContainer<E, M, V, C, A, S>
|
||||
where
|
||||
E: Engine,
|
||||
M: Send + Sync,
|
||||
V: Widget<Engine = E> + Handle<E>,
|
||||
C: Command<V>,
|
||||
A: Audio,
|
||||
S: StatusBar<E>
|
||||
{
|
||||
pub cursor: (usize, usize),
|
||||
pub entered: bool,
|
||||
pub menu_bar: Option<MenuBar<E, V, C>>,
|
||||
pub status_bar: Option<S>,
|
||||
pub history: Vec<C>,
|
||||
pub size: Measure<E>,
|
||||
pub model: Arc<RwLock<M>>,
|
||||
pub view: V,
|
||||
pub audio: A,
|
||||
}
|
||||
|
||||
impl<E, M, V, C, A, S> AppContainer<E, M, V, C, A, S>
|
||||
where
|
||||
E: Engine,
|
||||
M: Send + Sync,
|
||||
V: Widget<Engine = E> + Handle<E>,
|
||||
C: Command<V>,
|
||||
A: Audio,
|
||||
S: StatusBar<E>
|
||||
{
|
||||
pub fn new (
|
||||
model: &Arc<RwLock<M>>,
|
||||
view: V,
|
||||
audio: A,
|
||||
menu_bar: Option<MenuBar<E, V, C>>,
|
||||
status_bar: Option<S>,
|
||||
) -> Self {
|
||||
Self {
|
||||
cursor: (0, 0),
|
||||
entered: false,
|
||||
history: vec![],
|
||||
size: Measure::new(),
|
||||
model: model.clone(),
|
||||
view,
|
||||
audio,
|
||||
menu_bar,
|
||||
status_bar,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<M, V, C, A, S> Content for AppContainer<Tui, M, V, C, A, S>
|
||||
where
|
||||
M: Send + Sync,
|
||||
V: Widget<Engine = Tui> + Handle<Tui>,
|
||||
C: Command<V>,
|
||||
A: Audio,
|
||||
S: StatusBar<Tui>,
|
||||
{
|
||||
type Engine = Tui;
|
||||
fn content (&self) -> impl Widget<Engine = Tui> {
|
||||
let menus = self.menu_bar.as_ref().map_or_else(
|
||||
||&[] as &[Menu<_, _, _>],
|
||||
|m|m.menus.as_slice()
|
||||
);
|
||||
Split::down(
|
||||
if self.menu_bar.is_some() { 1 } else { 0 },
|
||||
row!(menu in menus.iter() => {
|
||||
row!(" ", menu.title.as_str(), " ")
|
||||
}),
|
||||
Split::up(
|
||||
if self.status_bar.is_some() { 1 } else { 0 },
|
||||
widget(&self.status_bar),
|
||||
widget(&self.view)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum AppContainerCommand<T: std::fmt::Debug + Copy + Clone> {
|
||||
Focus(FocusCommand),
|
||||
Undo,
|
||||
Redo,
|
||||
App(T)
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||
pub enum AppContainerFocus<F: std::fmt::Debug + Copy + Clone + PartialEq> {
|
||||
Menu,
|
||||
Content(F),
|
||||
}
|
||||
|
||||
impl<T, U, C, A, S> FocusGrid for AppContainer<Tui, T, U, C, A, S>
|
||||
where
|
||||
T: Send + Sync,
|
||||
U: From<Arc<RwLock<T>>> + Widget<Engine = Tui> + Handle<Tui> + FocusGrid,
|
||||
C: Command<U>,
|
||||
A: From<Arc<RwLock<T>>> + Audio,
|
||||
S: From<Arc<RwLock<T>>> + StatusBar<Tui>
|
||||
{
|
||||
type Item = AppContainerFocus<<U as FocusGrid>::Item>;
|
||||
fn cursor (&self) -> (usize, usize) {
|
||||
self.cursor
|
||||
}
|
||||
fn cursor_mut (&mut self) -> &mut (usize, usize) {
|
||||
&mut self.cursor
|
||||
}
|
||||
fn focus_enter (&mut self) {
|
||||
let focused = self.focused();
|
||||
if !self.entered {
|
||||
self.entered = true;
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
fn focus_exit (&mut self) {
|
||||
if self.entered {
|
||||
self.entered = false;
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
fn entered (&self) -> Option<Self::Item> {
|
||||
if self.entered {
|
||||
Some(self.focused())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn layout (&self) -> &[&[Self::Item]] {
|
||||
&[
|
||||
&[AppContainerFocus::Menu],
|
||||
FocusGrid::layout(&self.ui)
|
||||
//&[AppContainerFocus::Content(())],
|
||||
]
|
||||
}
|
||||
fn update_focus (&mut self) {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue