Tui::fill_ -> Fill::w/h/wh

This commit is contained in:
🪞👃🪞 2024-12-17 19:32:10 +01:00
parent da39c84ba4
commit e127924227
10 changed files with 34 additions and 39 deletions

View file

@ -1,19 +1,5 @@
use crate::*;
impl<E: Engine> LayoutFill<E> for E {}
pub trait LayoutFill<E: Engine> {
fn fill_x <W: Render<E>> (fill: W) -> Fill<E, W> {
Fill::X(fill)
}
fn fill_y <W: Render<E>> (fill: W) -> Fill<E, W> {
Fill::Y(fill)
}
fn fill_xy <W: Render<E>> (fill: W) -> Fill<E, W> {
Fill::XY(fill)
}
}
pub enum Fill<E: Engine, W: Render<E>> {
X(W),
Y(W),
@ -30,6 +16,15 @@ impl<E: Engine, W: Render<E>> Fill<E, W> {
_ => unreachable!(),
}
}
pub fn w (fill: W) -> Self {
Self::X(fill)
}
pub fn h (fill: W) -> Self {
Self::Y(fill)
}
pub fn wh (fill: W) -> Self {
Self::XY(fill)
}
}
impl<E: Engine, W: Render<E>> Render<E> for Fill<E, W> {

View file

@ -20,13 +20,13 @@ impl<E: Engine, T: Render<E>> Fixed<E, T> {
_ => unreachable!(),
}
}
pub fn w (x: E::Unit, w: T) -> Fixed<E, T> {
pub fn w (x: E::Unit, w: T) -> Self {
Self::X(x, w)
}
pub fn h (y: E::Unit, w: T) -> Fixed<E, T> {
pub fn h (y: E::Unit, w: T) -> Self {
Self::Y(y, w)
}
pub fn wh (x: E::Unit, y: E::Unit, w: T) -> Fixed<E, T> {
pub fn wh (x: E::Unit, y: E::Unit, w: T) -> Self {
Self::XY(x, y, w)
}
}

View file

@ -588,7 +588,7 @@ render!(|self: ArrangerStatus|{
};
//let commands = commands.iter().reduce(String::new(), |s, (a, b, c)| format!("{s} {a}{b}{c}"));
Tui::bg(status_bar_bg, Tui::fill_x(row!([mode, commands])))
Tui::bg(status_bar_bg, Fill::w(row!([mode, commands])))
});
@ -645,7 +645,7 @@ pub fn arranger_content_vertical (
factor: usize
) -> impl Render<Tui> + use<'_> {
lay!([
Tui::at_se(Tui::fill_xy(Tui::pull_x(1, Tui::fg(TuiTheme::title_fg(view.arranger_focused()),
Tui::at_se(Fill::wh(Tui::pull_x(1, Tui::fg(TuiTheme::title_fg(view.arranger_focused()),
format!("{}x{}", view.size.w(), view.size.h()))
))),
Tui::bg(view.color.rgb, lay!(![

View file

@ -66,9 +66,9 @@ pub enum SamplerFocus {
audio!(|self: SamplerTui, _client, _scope|Control::Continue);
render!(|self: SamplerTui|{
Tui::fill_xy(lay!([
Fill::wh(lay!([
Tui::fill_xy(render(|to|{ // border
Fill::wh(render(|to|{ // border
let [x, y, w, h] = to.area();
let green = Some(Style::default().fg(Color::Green));
to.blit(&"🭚", x, y, green);

View file

@ -140,13 +140,13 @@ render!(|self: SequencerTui|{
let w = self.size.w();
let phrase_w = if w > 60 { 20 } else if w > 40 { 15 } else { 10 };
let pool_w = if self.show_pool { phrase_w } else { 0 };
let pool = Tui::fill_y(Tui::at_e(PhraseListView(&self.phrases)));
let pool = Fill::h(Tui::at_e(PhraseListView(&self.phrases)));
let with_pool = move|x|Tui::split_w(false, pool_w, pool, x);
let status = SequencerStatusBar::from(self);
let with_status = |x|Tui::split_n(false, if self.status { 2 } else { 0 }, status, x);
let with_editbar = |x|Tui::split_n(false, 3, PhraseEditStatus(&self.editor), x);
let with_size = |x|lay!([self.size, x]);
let editor = with_editbar(with_pool(Tui::fill_xy(&self.editor)));
let editor = with_editbar(with_pool(Fill::wh(&self.editor)));
let color = self.player.play_phrase().as_ref().map(|(_,p)|p.as_ref().map(|p|p.read().unwrap().color)).flatten().clone();
let play = Fixed::wh(5, 2, PlayPause(self.clock.is_rolling()));
let transport = Fixed::h(2, TransportView::from((self, color, true)));
@ -244,7 +244,7 @@ render!(|self: SequencerStatusBar|Fixed::h(2, lay!([
double(("q", "enqueue"), ("e", "edit"), ),
]))
},
Tui::fill_xy(Tui::at_se({
Fill::wh(Tui::at_se({
Tui::fg_bg(TuiTheme::orange(), TuiTheme::g(25), row!([
&self.cpu,
&self.res,

View file

@ -108,7 +108,7 @@ render!(|self: TransportView|{
Tui::fg_bg(self.2.lighter.rgb, self.2.base.rgb, format!("{:>10}", self.1)),
]));
Tui::bg(color.base.rgb, Tui::fill_x(row!([
Tui::bg(color.base.rgb, Fill::w(row!([
//PlayPause(self.started), " ",
col!([
Field(" Beat", self.beat.as_str(), &color),

View file

@ -244,7 +244,7 @@ render!(|self:PhraseEditStatus<'a>|row!(|add|{
Tui::fg_bg(color.lighter.rgb, Color::Reset, Tui::bold(true, "")),
&y
]);
add(&Tui::fill_x(Tui::fg_bg(fg, bg, row!(|add|{
add(&Fill::w(Tui::fg_bg(fg, bg, row!(|add|{
add(&Fixed::wh(26, 3, col!(![
field(" Edit", format!("{name}")),
field(" Length", format!("{length}")),

View file

@ -214,7 +214,7 @@ render!(|self: PhraseListView<'a>|{
let upper_right = format!("({})", phrases.len());
Tui::bg(bg, lay!(move|add|{
//add(&Lozenge(Style::default().bg(border_bg).fg(border_color)))?;
add(&Tui::inset_xy(0, 1, Tui::fill_xy(col!(move|add|match mode {
add(&Tui::inset_xy(0, 1, Fill::wh(col!(move|add|match mode {
Some(PhraseListMode::Import(_, ref file_picker)) => add(file_picker),
Some(PhraseListMode::Export(_, ref file_picker)) => add(file_picker),
_ => Ok(for (i, phrase) in phrases.iter().enumerate() {
@ -227,10 +227,10 @@ render!(|self: PhraseListView<'a>|{
length.focus = Some(*focus);
}
}
add(&Tui::bg(color.base.rgb, Tui::fill_x(col!([
Tui::fill_x(lay!(|add|{
add(&Tui::fill_x(Tui::at_w(format!(" {i}"))))?;
add(&Tui::fill_x(Tui::at_e(Tui::pull_x(1, length.clone()))))
add(&Tui::bg(color.base.rgb, Fill::w(col!([
Fill::w(lay!(|add|{
add(&Fill::w(Tui::at_w(format!(" {i}"))))?;
add(&Fill::w(Tui::at_e(Tui::pull_x(1, length.clone()))))
})),
Tui::bold(true, {
let mut row2 = format!(" {name}");
@ -249,8 +249,8 @@ render!(|self: PhraseListView<'a>|{
}))?;
})
}))))?;
add(&Tui::fill_x(Tui::at_nw(Tui::push_x(1, Tui::fg(title_color, upper_left.to_string())))))?;
add(&Tui::fill_x(Tui::at_ne(Tui::pull_x(1, Tui::fg(title_color, upper_right.to_string())))))?;
add(&Fill::w(Tui::at_nw(Tui::push_x(1, Tui::fg(title_color, upper_left.to_string())))))?;
add(&Fill::w(Tui::at_ne(Tui::pull_x(1, Tui::fg(title_color, upper_right.to_string())))))?;
add(&self.0.size)
}))
});

View file

@ -66,17 +66,17 @@ render!(|self: PianoHorizontal|{
let notes = move||PianoHorizontalNotes(&self);
let cursor = move||PianoHorizontalCursor(&self);
let keys_width = 5;
Tui::fill_xy(Tui::bg(color.darker.rgb,
Fill::wh(Tui::bg(color.darker.rgb,
Bsp::s(
Fixed::h(1, Bsp::e(
Fixed::w(keys_width, ""),
Tui::fill_x(timeline()),
Fill::w(timeline()),
)),
Bsp::e(
Fixed::w(keys_width, keys()),
Tui::fill_xy(lay!([&self.size, Tui::fill_xy(lay!([
Tui::fill_xy(notes()),
Tui::fill_xy(cursor()),
Fill::wh(lay!([&self.size, Fill::wh(lay!([
Fill::wh(notes()),
Fill::wh(cursor()),
]))])),
),
)

View file

@ -3,7 +3,7 @@ use crate::*;
pub struct Bordered<S: BorderStyle, W: Render<Tui>>(pub S, pub W);
render!(|self: Bordered<S: BorderStyle, W: Render<Tui>>|{
Tui::fill_xy(lay!([Border(self.0), Tui::inset_xy(1, 1, widget(&self.1))]))
Fill::wh(lay!([Border(self.0), Tui::inset_xy(1, 1, widget(&self.1))]))
});
pub struct Border<S: BorderStyle>(pub S);