mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
74 lines
2.1 KiB
Rust
74 lines
2.1 KiB
Rust
use crate::*;
|
|
|
|
pub struct AppContainer<T, E, C, U, A, S>
|
|
where
|
|
T: Send + Sync,
|
|
E: Engine,
|
|
C: Command<T>,
|
|
U: From<Arc<RwLock<T>>> + Widget<Engine = E> + Handle<E>,
|
|
A: From<Arc<RwLock<T>>> + Audio,
|
|
S: From<Arc<RwLock<T>>> + StatusBar<E>
|
|
{
|
|
pub cursor: (usize, usize),
|
|
pub entered: bool,
|
|
pub menu_bar: Option<MenuBar<E, T, C>>,
|
|
pub status_bar: Option<S>,
|
|
pub history: Vec<C>,
|
|
pub size: Measure<E>,
|
|
pub ui: U,
|
|
pub audio: A,
|
|
pub model: Arc<RwLock<T>>,
|
|
}
|
|
|
|
impl<T, E, C, U, A, S> From<T> for AppContainer<T, E, C, U, A, S>
|
|
where
|
|
T: Send + Sync,
|
|
E: Engine,
|
|
C: Command<T>,
|
|
U: From<Arc<RwLock<T>>> + Widget<Engine = E> + Handle<E>,
|
|
A: From<Arc<RwLock<T>>> + Audio,
|
|
S: From<Arc<RwLock<T>>> + StatusBar<E>
|
|
{
|
|
fn from (model: T) -> Self {
|
|
let model = Arc::new(RwLock::new(model));
|
|
Self {
|
|
cursor: (0, 0),
|
|
entered: false,
|
|
menu_bar: None,
|
|
status_bar: None,
|
|
history: vec![],
|
|
size: Measure::new(),
|
|
ui: U::from(model.clone()),
|
|
audio: A::from(model.clone()),
|
|
model,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<T, C, U, A, S> Content for AppContainer<T, Tui, C, U, A, S>
|
|
where
|
|
T: Send + Sync,
|
|
C: Command<T>,
|
|
U: From<Arc<RwLock<T>>> + Widget<Engine = Tui> + Handle<Tui>,
|
|
A: From<Arc<RwLock<T>>> + Audio,
|
|
S: From<Arc<RwLock<T>>> + 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.ui)
|
|
)
|
|
)
|
|
}
|
|
}
|