remove PhraseViewState

This commit is contained in:
🪞👃🪞 2024-11-25 18:32:23 +01:00
parent 9319315595
commit 3569019b86
16 changed files with 432 additions and 473 deletions

View file

@ -10,10 +10,6 @@ pub(crate) use std::ffi::OsString;
pub(crate) use std::fs::read_dir;
submod! {
tui_focus
tui_menu
tui_status
tui_app_arranger
tui_app_sequencer
tui_app_transport
@ -240,3 +236,117 @@ impl Debug for PhrasePlayerModel {
.finish()
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum AppFocus<T: Copy + Debug + PartialEq> {
/// The menu bar is focused
Menu,
/// The app content is focused
Content(T)
}
pub trait FocusWrap<T> {
fn wrap <'a, W: Widget<Engine = Tui>> (self, focus: T, content: &'a W)
-> impl Widget<Engine = Tui> + 'a;
}
#[macro_export] macro_rules! impl_focus {
($Struct:ident $Focus:ident $Grid:expr) => {
impl HasFocus for $Struct {
type Item = AppFocus<$Focus>;
/// Get the currently focused item.
fn focused (&self) -> Self::Item {
self.focus.inner()
}
/// Get the currently focused item.
fn set_focused (&mut self, to: Self::Item) {
self.focus.set_inner(to)
}
}
impl HasEnter for $Struct {
/// Get the currently focused item.
fn entered (&self) -> bool {
self.focus.is_entered()
}
/// Get the currently focused item.
fn set_entered (&mut self, entered: bool) {
if entered {
self.focus.to_entered()
} else {
self.focus.to_focused()
}
}
}
impl FocusGrid for $Struct {
fn focus_cursor (&self) -> (usize, usize) {
self.cursor
}
fn focus_cursor_mut (&mut self) -> &mut (usize, usize) {
&mut self.cursor
}
fn focus_layout (&self) -> &[&[AppFocus<$Focus>]] {
use AppFocus::*;
use $Focus::*;
&$Grid
}
}
}
}
pub trait StatusBar: Copy + Widget<Engine = Tui> {
type State;
fn hotkey_fg () -> Color where Self: Sized;
fn update (&mut self, state: &Self::State) where Self: Sized;
fn command (commands: &[[impl Widget<Engine = Tui>;3]])
-> impl Widget<Engine = Tui> + '_
where
Self: Sized
{
let hotkey_fg = Self::hotkey_fg();
Stack::right(move |add|{
Ok(for [a, b, c] in commands.iter() {
add(&row!(
" ",
widget(a),
widget(b).bold(true).fg(hotkey_fg),
widget(c),
))?;
})
})
}
}
fn content_with_menu_and_status <'a, A, S, C> (
content: &'a A,
menu_bar: &'a Option<MenuBar<Tui, S, C>>,
status_bar: &'a Option<impl StatusBar>
) -> impl Widget<Engine = Tui> + 'a
where
A: Widget<Engine = Tui>,
S: Send + Sync + 'a,
C: Command<S>
{
let menus = menu_bar.as_ref().map_or_else(
||&[] as &[Menu<_, _, _>],
|m|m.menus.as_slice()
);
Either(
menu_bar.is_none(),
Either(
status_bar.is_none(),
widget(content),
Split::up(
1,
widget(status_bar.as_ref().unwrap()),
widget(content)
),
),
Split::down(
1,
row!(menu in menus.iter() => {
row!(" ", menu.title.as_str(), " ")
}),
widget(content)
)
)
}