wip: fixing the modal

This commit is contained in:
🪞👃🪞 2024-09-26 03:29:18 +03:00
parent 29f11b5977
commit 2adf0028c3
5 changed files with 57 additions and 69 deletions

View file

@ -72,27 +72,33 @@ struct ArrangerStandalone<E: Engine> {
impl Content for ArrangerStandalone<Tui> {
type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> {
let show = self.arranger.modal.is_some();
let modal = self.arranger.modal.as_ref().map(|x|x as &dyn Content<Engine = Tui>);
ModalHost(show, modal, Split::down(move|add|{
add(&(&self.transport as &dyn Widget<Engine = Tui>).debug())?;
if let (Some(direction), Some(sequencer)) = (
self.show_sequencer,
self.arranger.sequencer(),
) {
add(&Split::new(direction, move|add|{
add(&(&self.arranger as &dyn Widget<Engine = Tui>)
.shrink_y(30)
.debug())?;
add(&(sequencer as &dyn Widget<Engine = Tui>)
.min_y(20)
.debug())?;
Ok(())
}))
} else {
add(&self.arranger)
Layers::new(|add|{
add(&Split::down(move|add|{
add(&(&self.transport as &dyn Widget<Engine = Tui>).debug())?;
if let (Some(direction), Some(sequencer)) = (
self.show_sequencer,
self.arranger.sequencer(),
) {
add(&Split::new(direction, move|add|{
add(&(&self.arranger as &dyn Widget<Engine = Tui>)
.shrink_y(30)
.debug())?;
add(&(sequencer as &dyn Widget<Engine = Tui>)
.min_y(20)
.debug())?;
Ok(())
}))
} else {
add(&self.arranger)
}
}));
if let Some(ref modal) = self.arranger.modal {
add(&Background(COLOR_BG1))?;
add(&Foreground(COLOR_BG2))?;
add(&modal as &dyn Widget<Engine = Tui>)?;
}
}))
Ok(())
})
}
}

View file

@ -34,7 +34,7 @@ pub struct Arranger<E: Engine> {
/// Display mode of arranger
pub mode: ArrangerViewMode,
/// Slot for modal dialog displayed on top of app.
pub modal: Option<Box<dyn ExitableComponent<E>>>,
pub modal: Option<Box<dyn ContentComponent<E>>>,
/// Whether the arranger is currently focused
pub focused: bool
}
@ -223,7 +223,7 @@ impl Handle<Tui> for Arranger<Tui> {
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
if let Some(modal) = self.modal.as_mut() {
let result = modal.handle(from)?;
if modal.exited() {
if from.is_done() {
self.modal = None;
}
return Ok(result)
@ -974,31 +974,30 @@ impl<E: Engine> ArrangerRenameModal<E> {
}
}
impl Widget for ArrangerRenameModal<Tui> {
impl Content for ArrangerRenameModal<Tui> {
type Engine = Tui;
fn layout (&self, _to: [u16;2]) -> Perhaps<[u16;2]> {
todo!()
}
fn render (&self, to: &mut TuiOutput) -> Usually<()> {
let area = to.area();
let y = area.y() + area.h() / 2;
let bg_area = [1, y - 1, area.w() - 2, 3];
to.fill_bg(bg_area, COLOR_BG1);
Lozenge(Style::default().bold().white().dim()).draw(to.with_rect(bg_area));
let label = match self.target {
ArrangerFocus::Mix => "Rename project:",
ArrangerFocus::Track(_) => "Rename track:",
ArrangerFocus::Scene(_) => "Rename scene:",
ArrangerFocus::Clip(_, _) => "Rename clip:",
};
let style = Some(Style::default().not_bold().white().not_dim());
to.blit(&label, area.x() + 3, y, style);
let style = Some(Style::default().bold().white().not_dim());
to.blit(&self.value, area.x() + 3 + label.len() as u16 + 1, y, style);
let style = Some(Style::default().bold().white().not_dim().reversed());
to.blit(&"", area.x() + 3 + label.len() as u16 + 1 + self.cursor as u16, y, style);
fn content (&self) -> impl Widget<Engine = Tui> {
todo!();
Layers::new(|add|{Ok(())})
//let area = to.area();
//let y = area.y() + area.h() / 2;
//let bg_area = [1, y - 1, area.w() - 2, 3];
//to.fill_bg(bg_area, COLOR_BG1);
//Lozenge(Style::default().bold().white().dim()).draw(to.with_rect(bg_area));
//let label = match self.target {
//ArrangerFocus::Mix => "Rename project:",
//ArrangerFocus::Track(_) => "Rename track:",
//ArrangerFocus::Scene(_) => "Rename scene:",
//ArrangerFocus::Clip(_, _) => "Rename clip:",
//};
//let style = Some(Style::default().not_bold().white().not_dim());
//to.blit(&label, area.x() + 3, y, style);
//let style = Some(Style::default().bold().white().not_dim());
//to.blit(&self.value, area.x() + 3 + label.len() as u16 + 1, y, style);
//let style = Some(Style::default().bold().white().not_dim().reversed());
//to.blit(&"▂", area.x() + 3 + label.len() as u16 + 1 + self.cursor as u16, y, style);
//Ok(Some(area))
Ok(())
//Ok(())
}
}