looks like layout must return size only

This commit is contained in:
🪞👃🪞 2024-09-13 03:47:36 +03:00
parent 70cef99931
commit 4e0eb0c335
3 changed files with 195 additions and 230 deletions

View file

@ -303,155 +303,6 @@ impl Widget for Background {
} }
} }
pub const COLOR_BG0: Color = Color::Rgb(30, 33, 36);
pub const COLOR_BG1: Color = Color::Rgb(41, 46, 57);
pub const COLOR_BG2: Color = Color::Rgb(46, 52, 64);
pub const COLOR_BG3: Color = Color::Rgb(59, 66, 82);
pub const COLOR_BG4: Color = Color::Rgb(67, 76, 94);
pub const COLOR_BG5: Color = Color::Rgb(76, 86, 106);
pub trait Theme {
const BG0: Color;
const BG1: Color;
const BG2: Color;
const BG3: Color;
const BG4: Color;
const RED: Color;
const YELLOW: Color;
const GREEN: Color;
const PLAYING: Color;
const SEPARATOR: Color;
fn bg_hier (focused: bool, entered: bool) -> Color {
if focused && entered {
Self::BG3
} else if focused {
Self::BG2
} else {
Self::BG1
}
}
fn bg_hi (focused: bool, entered: bool) -> Color {
if focused && entered {
Self::BG2
} else if focused {
Self::BG1
} else {
Self::BG0
}
}
fn bg_lo (focused: bool, entered: bool) -> Color {
if focused && entered {
Self::BG1
} else if focused {
Self::BG0
} else {
Color::Reset
}
}
fn style_hi (focused: bool, highlight: bool) -> Style {
if highlight && focused {
Style::default().yellow().not_dim()
} else if highlight {
Style::default().yellow().dim()
} else {
Style::default()
}
}
}
pub struct Nord;
impl Theme for Nord {
const BG0: Color = Color::Rgb(41, 46, 57);
const BG1: Color = Color::Rgb(46, 52, 64);
const BG2: Color = Color::Rgb(59, 66, 82);
const BG3: Color = Color::Rgb(67, 76, 94);
const BG4: Color = Color::Rgb(76, 86, 106);
const RED: Color = Color::Rgb(191, 97, 106);
const YELLOW: Color = Color::Rgb(235, 203, 139);
const GREEN: Color = Color::Rgb(163, 190, 140);
const PLAYING: Color = Color::Rgb(60, 100, 50);
const SEPARATOR: Color = Color::Rgb(0, 0, 0);
}
pub const GRAY: Style = Style {
fg: Some(Color::Gray),
bg: None,
underline_color: None,
add_modifier: Modifier::empty(),
sub_modifier: Modifier::empty(),
};
pub const GRAY_NOT_DIM: Style = Style {
fg: Some(Color::Gray),
bg: None,
underline_color: None,
add_modifier: Modifier::empty(),
sub_modifier: Modifier::DIM,
};
pub const DIM: Style = Style {
fg: None,
bg: None,
underline_color: None,
add_modifier: Modifier::DIM,
sub_modifier: Modifier::empty(),
};
pub const GRAY_DIM: Style = Style {
fg: Some(Color::Gray),
bg: None,
underline_color: None,
add_modifier: Modifier::DIM,
sub_modifier: Modifier::empty(),
};
pub const WHITE_NOT_DIM_BOLD: Style = Style {
fg: Some(Color::White),
bg: None,
underline_color: None,
add_modifier: Modifier::BOLD,
sub_modifier: Modifier::DIM,
};
pub const GRAY_NOT_DIM_BOLD: Style = Style {
fg: Some(Color::Gray),
bg: None,
underline_color: None,
add_modifier: Modifier::BOLD,
sub_modifier: Modifier::DIM,
};
pub const NOT_DIM: Style = Style {
fg: None,
bg: None,
underline_color: None,
add_modifier: Modifier::empty(),
sub_modifier: Modifier::DIM,
};
pub const NOT_DIM_GREEN: Style = Style {
fg: Some(Color::Rgb(96, 255, 32)),
bg: Some(COLOR_BG1),
underline_color: None,
add_modifier: Modifier::empty(),
sub_modifier: Modifier::DIM,
};
pub const NOT_DIM_BOLD: Style = Style {
fg: None,
bg: None,
underline_color: None,
add_modifier: Modifier::BOLD,
sub_modifier: Modifier::DIM,
};
impl<T: Widget<Engine = Tui>> Widget for Fixed<u16, T> { impl<T: Widget<Engine = Tui>> Widget for Fixed<u16, T> {
type Engine = Tui; type Engine = Tui;
fn layout (&self, to: [u16;4]) -> Perhaps<[u16;4]> { fn layout (&self, to: [u16;4]) -> Perhaps<[u16;4]> {
@ -578,30 +429,19 @@ impl<T: Widget<Engine = Tui>> Content for Inset<u16, T> {
type Engine = Tui; type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> { fn content (&self) -> impl Widget<Engine = Tui> {
match self { match self {
Self::X(x, inner) => Self::X(x, inner) => Plus::X(
Plus::X(*x, Shrink::X(*x + *x, Align::X(inner as &dyn Widget<Engine = Tui>))), *x, Shrink::X(*x + *x, Align::X(inner as &dyn Widget<Engine = Tui>))
Self::Y(y, inner) => ),
Plus::Y(*y, Shrink::X(*y + *y, Align::Y(inner as &dyn Widget<Engine = Tui>))), Self::Y(y, inner) => Plus::Y(
Self::XY(x, y, inner) => *y, Shrink::X(*y + *y, Align::Y(inner as &dyn Widget<Engine = Tui>))
Plus::XY(*x, *y, Shrink::XY(*x, *y, Align::Center(inner as &dyn Widget<Engine = Tui>))), ),
Self::XY(x, y, inner) => Plus::XY(
*x, *y, Shrink::XY(*x, *y, Align::Center(inner as &dyn Widget<Engine = Tui>))
),
} }
} }
} }
//impl<T: Widget<Engine = Tui>> Widget for Inset<u16, T> {
//type Engine = Tui;
//fn layout (&self, to: [u16;4]) -> Perhaps<[u16;4]> {
//match self {
//Self::X(x, inner) => Shrink::X(*x + *x, Align::Center(inner as &dyn Widget<Engine = Tui>)),
//Self::Y(y, inner) => Shrink::X(*y + *y, Align::Center(inner as &dyn Widget<Engine = Tui>)),
//Self::XY(x, y, inner) => Shrink::XY(*x, *y, Align::Center(inner as &dyn Widget<Engine = Tui>)),
//}.layout(to)
//}
//fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
//Ok(self.layout(to.area())?.map(|a|to.render_in(a, self.inner())).transpose()?.flatten())
//}
//}
impl<T: Widget<Engine = Tui>> Widget for Outset<u16, T> { impl<T: Widget<Engine = Tui>> Widget for Outset<u16, T> {
type Engine = Tui; type Engine = Tui;
fn layout (&self, to: [u16;4]) -> Perhaps<[u16;4]> { fn layout (&self, to: [u16;4]) -> Perhaps<[u16;4]> {
@ -875,3 +715,152 @@ border! {
} }
} }
} }
pub const COLOR_BG0: Color = Color::Rgb(30, 33, 36);
pub const COLOR_BG1: Color = Color::Rgb(41, 46, 57);
pub const COLOR_BG2: Color = Color::Rgb(46, 52, 64);
pub const COLOR_BG3: Color = Color::Rgb(59, 66, 82);
pub const COLOR_BG4: Color = Color::Rgb(67, 76, 94);
pub const COLOR_BG5: Color = Color::Rgb(76, 86, 106);
pub trait Theme {
const BG0: Color;
const BG1: Color;
const BG2: Color;
const BG3: Color;
const BG4: Color;
const RED: Color;
const YELLOW: Color;
const GREEN: Color;
const PLAYING: Color;
const SEPARATOR: Color;
fn bg_hier (focused: bool, entered: bool) -> Color {
if focused && entered {
Self::BG3
} else if focused {
Self::BG2
} else {
Self::BG1
}
}
fn bg_hi (focused: bool, entered: bool) -> Color {
if focused && entered {
Self::BG2
} else if focused {
Self::BG1
} else {
Self::BG0
}
}
fn bg_lo (focused: bool, entered: bool) -> Color {
if focused && entered {
Self::BG1
} else if focused {
Self::BG0
} else {
Color::Reset
}
}
fn style_hi (focused: bool, highlight: bool) -> Style {
if highlight && focused {
Style::default().yellow().not_dim()
} else if highlight {
Style::default().yellow().dim()
} else {
Style::default()
}
}
}
pub struct Nord;
impl Theme for Nord {
const BG0: Color = Color::Rgb(41, 46, 57);
const BG1: Color = Color::Rgb(46, 52, 64);
const BG2: Color = Color::Rgb(59, 66, 82);
const BG3: Color = Color::Rgb(67, 76, 94);
const BG4: Color = Color::Rgb(76, 86, 106);
const RED: Color = Color::Rgb(191, 97, 106);
const YELLOW: Color = Color::Rgb(235, 203, 139);
const GREEN: Color = Color::Rgb(163, 190, 140);
const PLAYING: Color = Color::Rgb(60, 100, 50);
const SEPARATOR: Color = Color::Rgb(0, 0, 0);
}
pub const GRAY: Style = Style {
fg: Some(Color::Gray),
bg: None,
underline_color: None,
add_modifier: Modifier::empty(),
sub_modifier: Modifier::empty(),
};
pub const GRAY_NOT_DIM: Style = Style {
fg: Some(Color::Gray),
bg: None,
underline_color: None,
add_modifier: Modifier::empty(),
sub_modifier: Modifier::DIM,
};
pub const DIM: Style = Style {
fg: None,
bg: None,
underline_color: None,
add_modifier: Modifier::DIM,
sub_modifier: Modifier::empty(),
};
pub const GRAY_DIM: Style = Style {
fg: Some(Color::Gray),
bg: None,
underline_color: None,
add_modifier: Modifier::DIM,
sub_modifier: Modifier::empty(),
};
pub const WHITE_NOT_DIM_BOLD: Style = Style {
fg: Some(Color::White),
bg: None,
underline_color: None,
add_modifier: Modifier::BOLD,
sub_modifier: Modifier::DIM,
};
pub const GRAY_NOT_DIM_BOLD: Style = Style {
fg: Some(Color::Gray),
bg: None,
underline_color: None,
add_modifier: Modifier::BOLD,
sub_modifier: Modifier::DIM,
};
pub const NOT_DIM: Style = Style {
fg: None,
bg: None,
underline_color: None,
add_modifier: Modifier::empty(),
sub_modifier: Modifier::DIM,
};
pub const NOT_DIM_GREEN: Style = Style {
fg: Some(Color::Rgb(96, 255, 32)),
bg: Some(COLOR_BG1),
underline_color: None,
add_modifier: Modifier::empty(),
sub_modifier: Modifier::DIM,
};
pub const NOT_DIM_BOLD: Style = Style {
fg: None,
bg: None,
underline_color: None,
add_modifier: Modifier::BOLD,
sub_modifier: Modifier::DIM,
};

View file

@ -230,8 +230,7 @@ impl Handle<Tui> for Arranger<Tui> {
match from.event() { match from.event() {
// mode_switch: switch the display mode // mode_switch: switch the display mode
key!(KeyCode::Char('`')) => { key!(KeyCode::Char('`')) => {
self.mode.to_next(); self.mode.to_next()
Ok(Some(true))
}, },
// cursor_up: move cursor up // cursor_up: move cursor up
key!(KeyCode::Up) => { key!(KeyCode::Up) => {
@ -240,7 +239,6 @@ impl Handle<Tui> for Arranger<Tui> {
_ => self.scene_prev(), _ => self.scene_prev(),
}; };
self.show_phrase()?; self.show_phrase()?;
Ok(Some(true))
}, },
// cursor_down // cursor_down
key!(KeyCode::Down) => { key!(KeyCode::Down) => {
@ -249,7 +247,6 @@ impl Handle<Tui> for Arranger<Tui> {
_ => self.scene_next(), _ => self.scene_next(),
}; };
self.show_phrase()?; self.show_phrase()?;
Ok(Some(true))
}, },
// cursor left // cursor left
key!(KeyCode::Left) => { key!(KeyCode::Left) => {
@ -258,7 +255,6 @@ impl Handle<Tui> for Arranger<Tui> {
_ => self.track_prev(), _ => self.track_prev(),
}; };
self.show_phrase()?; self.show_phrase()?;
Ok(Some(true))
}, },
// cursor right // cursor right
key!(KeyCode::Right) => { key!(KeyCode::Right) => {
@ -267,67 +263,45 @@ impl Handle<Tui> for Arranger<Tui> {
_ => self.track_next(), _ => self.track_next(),
}; };
self.show_phrase()?; self.show_phrase()?;
Ok(Some(true))
}, },
// increment: use next clip here // increment: use next clip here
key!(KeyCode::Char('.')) => { key!(KeyCode::Char('.')) => {
self.phrase_next(); self.phrase_next();
Ok(Some(true))
}, },
// decrement: use previous next clip here // decrement: use previous next clip here
key!(KeyCode::Char(',')) => { key!(KeyCode::Char(',')) => {
self.phrase_prev(); self.phrase_prev();
Ok(Some(true))
}, },
// decrement: use previous clip here // decrement: use previous clip here
key!(KeyCode::Enter) => { key!(KeyCode::Enter) => {
self.activate(); self.activate();
Ok(Some(true))
}, },
// scene_add: add a new scene // scene_add: add a new scene
key!(Ctrl-KeyCode::Char('a')) => { key!(Ctrl-KeyCode::Char('a')) => {
self.scene_add(None)?; self.scene_add(None)?;
Ok(Some(true))
}, },
// track_add: add a new scene // track_add: add a new scene
key!(Ctrl-KeyCode::Char('t')) => { key!(Ctrl-KeyCode::Char('t')) => {
self.track_add(None)?; self.track_add(None)?;
Ok(Some(true))
}, },
// rename: add a new scene // rename: add a new scene
key!(KeyCode::Char('n')) => { key!(KeyCode::Char('n')) => {
self.rename_selected(); self.rename_selected();
Ok(Some(true))
}, },
// length: add a new scene // length: add a new scene
key!(KeyCode::Char('l')) => { key!(KeyCode::Char('l')) => {
todo!(); todo!();
Ok(Some(true))
}, },
// color: set color of item at cursor // color: set color of item at cursor
key!(KeyCode::Char('c')) => { key!(KeyCode::Char('c')) => {
todo!(); todo!();
Ok(Some(true))
}, },
_ => Ok(None) _ => return Ok(None)
}
}
}
/// Display mode of arranger
#[derive(PartialEq)]
pub enum ArrangerViewMode { VerticalExpanded, VerticalCompact1, VerticalCompact2, Horizontal }
/// Arranger display mode can be cycled
impl ArrangerViewMode {
/// Cycle arranger display mode
pub fn to_next (&mut self) {
*self = match self {
Self::VerticalExpanded => Self::VerticalCompact1,
Self::VerticalCompact1 => Self::VerticalCompact2,
Self::VerticalCompact2 => Self::Horizontal,
Self::Horizontal => Self::VerticalExpanded,
} }
Ok(Some(true))
} }
} }
impl Content for Arranger<Tui> { impl Content for Arranger<Tui> {
type Engine = Tui; type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> { fn content (&self) -> impl Widget<Engine = Tui> {
@ -360,6 +334,21 @@ impl Content for Arranger<Tui> {
}) })
} }
} }
/// Display mode of arranger
#[derive(PartialEq)]
pub enum ArrangerViewMode { VerticalExpanded, VerticalCompact1, VerticalCompact2, Horizontal }
/// Arranger display mode can be cycled
impl ArrangerViewMode {
/// Cycle arranger display mode
pub fn to_next (&mut self) {
*self = match self {
Self::VerticalExpanded => Self::VerticalCompact1,
Self::VerticalCompact1 => Self::VerticalCompact2,
Self::VerticalCompact2 => Self::Horizontal,
Self::Horizontal => Self::VerticalExpanded,
}
}
}
struct ArrangerViewVertical<'a, 'b, E: Engine>( struct ArrangerViewVertical<'a, 'b, E: Engine>(
&'a Arranger<E>, &'b [(usize, usize)], &'b [(usize, usize)] &'a Arranger<E>, &'b [(usize, usize)], &'b [(usize, usize)]
@ -503,16 +492,16 @@ struct TracksHeader<'a>(
impl<'a> Content for TracksHeader<'a> { impl<'a> Content for TracksHeader<'a> {
type Engine = Tui; type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> { fn content (&self) -> impl Widget<Engine = Tui> {
let Self(_offset, columns, tracks) = *self; let Self(offset, columns, tracks) = *self;
Split::right(move |add|{ Plus::X(offset, Split::right(move |add|{
for (track, (w, _)) in tracks.iter().zip(columns) { for (track, (w, _)) in tracks.iter().zip(columns) {
add(&Min::X(*w as u16, Layers::new(|add|{ add(&Min::XY(*w as u16, 2, Layers::new(|add|{
add(&Background(COLOR_BG1))?; add(&Background(COLOR_BG1))?;
add(&track.name.read().unwrap().as_str()) add(&track.name.read().unwrap().as_str())
})))?; })))?;
} }
Ok(()) Ok(())
}) }))
} }
} }
@ -546,15 +535,16 @@ impl<'a> Content for SceneRow<'a> {
let playing = scene.is_playing(tracks); let playing = scene.is_playing(tracks);
Split::right(move |add| { Split::right(move |add| {
add(&Layers::new(|add|{ add(&Layers::new(|add|{
add(&Split::right(|add|{ //add(&Split::right(|add|{
add(&if playing { "" } else { " " })?; //add(&if playing { "▶" } else { " " })?;
add(&scene.name.read().unwrap().as_str()) add(&scene.name.read().unwrap().as_str())?;
}))?; //}))?;
add(&Background(COLOR_BG1)) //add(&Background(COLOR_BG1))
Ok(())
}))?; }))?;
for (track, (_w, _x)) in columns.iter().enumerate() { //for (track, (_w, _x)) in columns.iter().enumerate() {
add(&SceneClip(tracks.get(track), scene.clips.get(track)))?; //add(&SceneClip(tracks.get(track), scene.clips.get(track)))?;
} //}
Ok(()) Ok(())
}) })
} }
@ -589,8 +579,6 @@ struct ArrangerViewHorizontal<'a, E: Engine>(
impl<'a> Content for ArrangerViewHorizontal<'a, Tui> { impl<'a> Content for ArrangerViewHorizontal<'a, Tui> {
type Engine = Tui; type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> { fn content (&self) -> impl Widget<Engine = Tui> {
//let area = to.area();
//let area = [area.x(), area.y(), area.w(), area.h().min((2 + state.tracks.len() * 2) as u16)];
let Arranger { tracks, focused, selected, scenes, .. } = self.0; let Arranger { tracks, focused, selected, scenes, .. } = self.0;
let tracks = tracks.as_slice(); let tracks = tracks.as_slice();
Layers::new(|add|{ Layers::new(|add|{

View file

@ -98,47 +98,35 @@ impl Handle<Tui> for ArrangerStandalone<Tui> {
key!(KeyCode::Char(' ')) => { key!(KeyCode::Char(' ')) => {
if let Some(ref mut transport) = self.transport { if let Some(ref mut transport) = self.transport {
transport.toggle_play()?; transport.toggle_play()?;
Ok(Some(true))
} else { } else {
Ok(None) return Ok(None)
} }
}, },
key!(KeyCode::Tab) => { key!(KeyCode::Tab) => {
self.focus_next(); self.focus_next();
Ok(Some(true))
}, },
key!(KeyCode::BackTab) => { key!(KeyCode::BackTab) => {
self.focus_prev(); self.focus_prev();
Ok(Some(true))
}, },
key!(KeyCode::Down) => { key!(KeyCode::Down) => {
if self.focus == 0 || ( if self.focus == 0 || (
self.focus == 1 && self.arranger.is_last_row() self.focus == 1 && self.arranger.is_last_row()
) { ) {
self.focus_next(); self.focus_next();
Ok(Some(true))
} else { } else {
self.focused_mut().handle(from) return self.focused_mut().handle(from)
} }
}, },
key!(KeyCode::Up) => { key!(KeyCode::Up) => {
if self.focus == 1 && self.arranger.is_first_row() { if self.focus == 1 && self.arranger.is_first_row() {
self.focus_prev(); self.focus_prev();
Ok(Some(true))
} else { } else {
self.focused_mut().handle(from) return self.focused_mut().handle(from)
} }
}, },
_ => self.focused_mut().handle(from) _ => return self.focused_mut().handle(from)
} }
} Ok(Some(true))
}
struct SequencerProxy<E: Engine>(Arc<RwLock<Arranger<E>>>);
impl Handle<Tui> for SequencerProxy<Tui> {
fn handle (&mut self, from: &Tui) -> Perhaps<bool> {
self.0.write().unwrap().handle(from)
} }
} }