tek/crates/device/src/dialog/dialog_view.rs
unspeaker 447638ee71
Some checks are pending
/ build (push) Waiting to run
wip: general overhaul of core and ports
2025-05-20 22:05:09 +03:00

101 lines
4.7 KiB
Rust

use crate::*;
impl Content<TuiOut> for Dialog {
fn content (&self) -> impl Render<TuiOut> + '_ {
Some(match self {
Self::Menu(_) => self.view_dialog_menu().boxed(),
_ => "kyp".boxed()
})
//Self::Help(offset) =>
//self.view_dialog_help(*offset).boxed(),
//Self::Browser(target, browser) =>
//self.view_dialog_browser(target, browser).boxed(),
//Self::Options =>
//self.view_dialog_options().boxed(),
//Self::Device(index) =>
//self.view_dialog_device(*index).boxed(),
//Self::Message(message) =>
//self.view_dialog_message(message).boxed(),
//})
}
}
content!(TuiOut: |self: Message| match self {
Self::FailedToAddDevice => "Failed to add device."
});
impl Dialog {
pub fn view_dialog_menu (&self) -> impl Content<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)))
}
pub fn view_dialog_help <'a> (&'a self, offset: usize) -> impl Content<TuiOut> + 'a {
Bsp::s(Tui::bold(true, "Help"), "FIXME")
//Bsp::s(Tui::bold(true, "Help"), Bsp::s("", Map::south(1,
//move||self.config.keys.layers.iter()
//.filter_map(|a|(a.0)(self).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()))))))))))
}
pub fn view_dialog_device (&self, index: usize) -> impl Content<TuiOut> + use<'_> {
let choices = ||device_kinds().iter();
let choice = move|label, i|
Fill::x(Tui::bg(if i == index { Rgb(64,128,32) } else { Rgb(0,0,0) },
Bsp::e(if i == index { "[ " } else { " " },
Bsp::w(if i == index { " ]" } else { " " },
label))));
Bsp::s(Tui::bold(true, "Add device"), Map::south(1, choices, choice))
}
pub fn view_dialog_message <'a> (&'a self, message: &'a Message) -> impl Content<TuiOut> + use<'a> {
Bsp::s(message, Bsp::s("", "[ OK ]"))
}
pub fn view_dialog_browser <'a> (&'a self, target: &BrowserTarget, browser: &'a Browser) -> impl Content<TuiOut> + use<'a> {
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(browser)))
}
pub fn view_dialog_load <'a> (&'a self, browser: &'a Browser) -> impl Content<TuiOut> + use<'a> {
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)))
}
pub fn view_dialog_export <'a> (&'a self, browser: &'a Browser) -> impl Content<TuiOut> + use<'a> {
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)))
}
pub fn view_dialog_import <'a> (&'a self, browser: &'a Browser) -> impl Content<TuiOut> + use<'a> {
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)))
}
pub fn view_dialog_options <'a> (&'a self) -> impl Content<TuiOut> + use<'a> {
"TODO"
}
}