app: flatten
Some checks failed
/ build (push) Has been cancelled

This commit is contained in:
🪞👃🪞 2025-08-04 15:18:12 +03:00
parent f488811767
commit 75b5190cfc
14 changed files with 945 additions and 1088 deletions

View file

@ -1,20 +0,0 @@
use crate::*;
mod dialog_api; pub use self::dialog_api::*;
mod dialog_view; pub use self::dialog_view::*;
/// Various possible dialog overlays
#[derive(Clone, Debug)]
pub enum Dialog {
Help(usize),
Menu(usize),
Device(usize),
Message(Message),
Browser(BrowserTarget, Browser),
Options,
}
/// Various possible messages
#[derive(PartialEq, Clone, Copy, Debug)]
pub enum Message {
FailedToAddDevice,
}

View file

@ -1,48 +0,0 @@
use crate::*;
#[tengri_proc::command(Option<Dialog>)]
impl DialogCommand {
fn open (dialog: &mut Option<Dialog>, new: Dialog) -> Perhaps<Self> {
*dialog = Some(new);
Ok(None)
}
fn close (dialog: &mut Option<Dialog>) -> Perhaps<Self> {
*dialog = None;
Ok(None)
}
}
//#[derive(Clone, Debug)]
//pub enum DialogCommand {
//Open { dialog: Dialog },
//Close
//}
//impl Command<Option<Dialog>> for DialogCommand {
//fn execute (self, state: &mut Option<Dialog>) -> Perhaps<Self> {
//match self {
//Self::Open { dialog } => {
//*state = Some(dialog);
//},
//Self::Close => {
//*state = None;
//}
//};
//Ok(None)
//}
//}
//dsl!(DialogCommand: |self: Dialog, iter|todo!());
//Dsl::take(&mut self.dialog, iter));
//#[tengri_proc::command(Option<Dialog>)]//Nope.
//impl DialogCommand {
//fn open (dialog: &mut Option<Dialog>, new: Dialog) -> Perhaps<Self> {
//*dialog = Some(new);
//Ok(None)
//}
//fn close (dialog: &mut Option<Dialog>) -> Perhaps<Self> {
//*dialog = None;
//Ok(None)
//}
//}

View file

@ -1,101 +0,0 @@
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"
}
}

View file

@ -22,7 +22,6 @@ pub(crate) use ratatui::{prelude::Rect, widgets::{Widget, canvas::{Canvas, Line}
pub(crate) use Color::*;
mod device; pub use self::device::*;
mod dialog; pub use self::dialog::*;
/// Define a type alias for iterators of sized items (columns).
macro_rules! def_sizes_iter {