mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
159 lines
7.7 KiB
Rust
159 lines
7.7 KiB
Rust
use crate::*;
|
|
pub(crate) use std::marker::PhantomData;
|
|
content!(TuiOut:|self: App|"kyp");//VIEW.content(self, "(bg :color/black (fill/xy (bsp/a overlay content)))"));
|
|
struct DslView<'s, O: Output, T> {
|
|
symbol: &'s str,
|
|
callback: Option<for<'t> fn (&'t T) -> Box<dyn Render<O> + 't>>,
|
|
next: Option<&'s Self>
|
|
}
|
|
pub const VIEW: DslView<'static, TuiOut, App> = DslView::new()
|
|
.def("browser", view_browser)
|
|
.def("content", view_content)
|
|
.def("device", view_device)
|
|
.def("menu", view_menu)
|
|
//.def("options", view_options)
|
|
.def("overlay", view_overlay);
|
|
impl<'s, O: Output, T> DslView<'s, O, T> {
|
|
pub const fn new () -> Self {
|
|
DslView { symbol: "", callback: None, next: None }
|
|
}
|
|
pub const fn def (
|
|
&'static self,
|
|
symbol: &'static str,
|
|
callback: fn (&T) -> Box<dyn Render<O> + '_>
|
|
) -> Self {
|
|
DslView { symbol, callback: Some(callback), next: Some(self) }
|
|
}
|
|
pub fn content <'t> (
|
|
&'static self, state: &'t T, src: impl Dsl) -> Usually<Box<dyn Render<O> + 't>> {
|
|
Ok(if src.sym()? == Some(self.symbol) && let Some(callback) = self.callback {
|
|
callback(&state)
|
|
} else if let Some(next) = self.next {
|
|
next.content(state, src)?
|
|
} else {
|
|
return Err("DslView::content: undefined".into())
|
|
})
|
|
}
|
|
//fn render (&self, state: &T, output: &mut O, src: impl Dsl) -> Usually<()> {
|
|
//Ok(if src.sym()? == Some(self.0) && let Some(callback) = self.1 {
|
|
//let view = callback(&state);
|
|
//output.place(output.area(), &view)
|
|
//} else if let Some(next) = self.2 {
|
|
//next.render(state, output, src)?
|
|
//} else {
|
|
//return Err("DslView::render: undefined".into())
|
|
//})
|
|
//}
|
|
}
|
|
|
|
|
|
fn view_content (app: &App) -> Box<dyn Render<TuiOut> + '_> {
|
|
Fill::xy(ErrorBoundary::new(Ok(Some("·")))).boxed()
|
|
}
|
|
fn view_overlay <'s> (state: &'s App) -> Box<dyn Render<TuiOut> + 's> {
|
|
match &state.dialog {
|
|
Dialog::Menu(_) => view_menu(state),
|
|
Dialog::Device(_) => view_device(state),
|
|
Dialog::Browser(_, _) => view_browser(state),
|
|
//Dialog::Help(_) => view_help,
|
|
//Dialog::Message(_) => view_message,
|
|
//Dialog::Options => view_options,
|
|
_ => unimplemented!()
|
|
}
|
|
}
|
|
fn wrap_dialog <'s> (dialog: impl Content<TuiOut> + 's) -> impl Content<TuiOut> + 's {
|
|
Fixed::xy(70, 23, Tui::fg_bg(Rgb(255,255,255), Rgb(16,16,16), Bsp::b(
|
|
Repeat(" "), Outer(true, Style::default().fg(Tui::g(96))).enclose(dialog))))
|
|
}
|
|
fn wrap_dialog_menu <'a> (content: impl Content<TuiOut> + 'a) -> Box<dyn Render<TuiOut> + 'a> {
|
|
Box::new(Tui::bg(Rgb(0,0,0), Bsp::s(
|
|
Fill::x(Fixed::y(3, Tui::bg(Rgb(33,33,33), Tui::bold(true, "tek 0.3.0-rc0")))),
|
|
Bsp::n(
|
|
Fill::x(Fixed::y(3, Tui::bg(Rgb(33,33,33), Bsp::e(Tui::fg(Rgb(255,192,48), "[Enter]"), " new session")))),
|
|
Fill::y(Align::n(Fill::x(content)))))))
|
|
}
|
|
fn view_menu <'s> (state: &'s App) -> Box<dyn Render<TuiOut> + 's> {
|
|
let views = state.config.views.clone();
|
|
let selected = state.dialog.menu_selected();
|
|
wrap_dialog_menu(Stack::south(move|add: &mut dyn FnMut(&dyn Render<TuiOut>)|{
|
|
////let options = ||["Projects", "Settings", "Help", "Quit"].iter();
|
|
////let option = |a,i|Tui::fg(Rgb(255,255,255), format!("{}", a));
|
|
////Bsp::s(Tui::bold(true, "tek!"), Bsp::s("", Map::south(1, options, option)))
|
|
for (index, (id, profile)) in views.read().unwrap().iter().enumerate() {
|
|
let bg = if index == 0 { Rgb(64,64,64) } else { Rgb(32,32,32) };
|
|
let name = profile.name.as_ref().map(|x|unquote(unquote(x.as_ref())));
|
|
let info = profile.info.as_ref().map(|x|unquote(unquote(x.as_ref())));
|
|
add(&Fixed::y(3, Tui::bg(bg, Bsp::s(
|
|
Fill::x(Bsp::a(
|
|
Fill::x(Align::w(Tui::fg(Rgb(224,192,128), name))),
|
|
Fill::x(Align::e(Tui::fg(Rgb(224,128,32), &id)))
|
|
)),
|
|
Fill::x(Align::w(info)))))); } }))
|
|
}
|
|
fn view_browser <'s> (state: &'s App) -> Box<dyn Render<TuiOut> + 's> {
|
|
let target = &state.dialog.browser_target().clone().unwrap();
|
|
Box::new(Bsp::s(
|
|
Padding::xy(3, 1, Fill::x(Align::w(FieldV(
|
|
Default::default(),
|
|
match &target {
|
|
BrowserTarget::SaveProject => "Save project:",
|
|
BrowserTarget::LoadProject => "Load project:",
|
|
BrowserTarget::ImportSample(_) => "Import sample:",
|
|
BrowserTarget::ExportSample(_) => "Export sample:",
|
|
BrowserTarget::ImportClip(_) => "Import clip:",
|
|
BrowserTarget::ExportClip(_) => "Export clip:",
|
|
},
|
|
Shrink::x(3, Fixed::y(1, Tui::fg(Tui::g(96), RepeatH("🭻")))))))),
|
|
Outer(true, Style::default().fg(Tui::g(96)))
|
|
.enclose(Fill::xy(state.dialog.browser()))))
|
|
}
|
|
fn view_device <'s> (state: &'s App) -> Box<dyn Render<TuiOut> + 's> {
|
|
let selected = state.dialog.device_selected().unwrap();
|
|
Box::new(Bsp::s(Tui::bold(true, "Add device"), Map::south(1,
|
|
move||device_kinds().iter(),
|
|
move|label: &&'static str, i|
|
|
Fill::x(Tui::bg(if i == selected { Rgb(64,128,32) } else { Rgb(0,0,0) },
|
|
Bsp::e(if i == state.dialog.device_selected().unwrap() { "[ " } else { " " },
|
|
Bsp::w(if i == state.dialog.device_selected().unwrap() { " ]" } else { " " },
|
|
"FIXME device name")))))))
|
|
}
|
|
|
|
//Bsp::s("",
|
|
//Map::south(1,
|
|
//move||app.config.binds.layers.iter()
|
|
//.filter_map(|a|(a.0)(app).then_some(a.1))
|
|
//.flat_map(|a|a)
|
|
//.filter_map(|x|if let Value::Exp(_, iter)=x.value{ Some(iter) } else { None })
|
|
//.skip(offset)
|
|
//.take(20),
|
|
//|mut b,i|Fixed::x(60, Align::w(Bsp::e("(", Bsp::e(
|
|
//b.next().map(|t|Fixed::x(16, Align::w(Tui::fg(Rgb(64,224,0), format!("{}", t.value))))),
|
|
//Bsp::e(" ", Align::w(format!("{}", b.0.0.trim()))))))))))),
|
|
|
|
//Dialog::Browser(BrowserTarget::Load, browser) => {
|
|
//"bobcat".boxed()
|
|
////Bsp::s(
|
|
////Fill::x(Align::w(Margin::xy(1, 1, Bsp::e(
|
|
////Tui::bold(true, " Load project: "),
|
|
////Shrink::x(3, Fixed::y(1, RepeatH("🭻"))))))),
|
|
////Outer(true, Style::default().fg(Tui::g(96)))
|
|
////.enclose(Fill::xy(browser)))
|
|
//},
|
|
//Dialog::Browser(BrowserTarget::Export, browser) => {
|
|
//"bobcat".boxed()
|
|
////Bsp::s(
|
|
////Fill::x(Align::w(Margin::xy(1, 1, Bsp::e(
|
|
////Tui::bold(true, " Export: "),
|
|
////Shrink::x(3, Fixed::y(1, RepeatH("🭻"))))))),
|
|
////Outer(true, Style::default().fg(Tui::g(96)))
|
|
////.enclose(Fill::xy(browser)))
|
|
//},
|
|
//Dialog::Browser(BrowserTarget::Import, browser) => {
|
|
//"bobcat".boxed()
|
|
////Bsp::s(
|
|
////Fill::x(Align::w(Margin::xy(1, 1, Bsp::e(
|
|
////Tui::bold(true, " Import: "),
|
|
////Shrink::x(3, Fixed::y(1, RepeatH("🭻"))))))),
|
|
////Outer(true, Style::default().fg(Tui::g(96)))
|
|
////.enclose(Fill::xy(browser)))
|
|
//},
|