mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
turn Inset and Outset into Padding and Margin
This commit is contained in:
parent
e0e680eb7c
commit
9fa858f226
9 changed files with 57 additions and 57 deletions
|
|
@ -40,26 +40,26 @@ impl Content for Demo<Tui> {
|
|||
|
||||
add(&Background(Color::Rgb(0,128,128)))?;
|
||||
|
||||
add(&Outset::XY(1, 1, Stack::down(|add|{
|
||||
add(&Margin::XY(1, 1, Stack::down(|add|{
|
||||
|
||||
add(&Layers::new(|add|{
|
||||
add(&Background(Color::Rgb(128,96,0)))?;
|
||||
add(&Border(Square(border_style)))?;
|
||||
add(&Outset::XY(2, 1, "..."))?;
|
||||
add(&Margin::XY(2, 1, "..."))?;
|
||||
Ok(())
|
||||
}).debug())?;
|
||||
|
||||
add(&Layers::new(|add|{
|
||||
add(&Background(Color::Rgb(128,64,0)))?;
|
||||
add(&Border(Lozenge(border_style)))?;
|
||||
add(&Outset::XY(4, 2, "---"))?;
|
||||
add(&Margin::XY(4, 2, "---"))?;
|
||||
Ok(())
|
||||
}).debug())?;
|
||||
|
||||
add(&Layers::new(|add|{
|
||||
add(&Background(Color::Rgb(96,64,0)))?;
|
||||
add(&Border(SquareBold(border_style)))?;
|
||||
add(&Outset::XY(6, 3, "~~~"))?;
|
||||
add(&Margin::XY(6, 3, "~~~"))?;
|
||||
Ok(())
|
||||
}).debug())?;
|
||||
|
||||
|
|
@ -69,15 +69,15 @@ impl Content for Demo<Tui> {
|
|||
Ok(())
|
||||
|
||||
}))
|
||||
//Align::Center(Outset::X(1, Layers::new(|add|{
|
||||
//Align::Center(Margin::X(1, Layers::new(|add|{
|
||||
//add(&Background(Color::Rgb(128,0,0)))?;
|
||||
//add(&Stack::down(|add|{
|
||||
//add(&Outset::Y(1, Layers::new(|add|{
|
||||
//add(&Margin::Y(1, Layers::new(|add|{
|
||||
//add(&Background(Color::Rgb(0,128,0)))?;
|
||||
//add(&Align::Center("12345"))?;
|
||||
//add(&Align::Center("FOO"))
|
||||
//})))?;
|
||||
//add(&Outset::XY(1, 1, Layers::new(|add|{
|
||||
//add(&Margin::XY(1, 1, Layers::new(|add|{
|
||||
//add(&Align::Center("1234567"))?;
|
||||
//add(&Align::Center("BAR"))?;
|
||||
//add(&Background(Color::Rgb(0,0,128)))
|
||||
|
|
@ -87,13 +87,13 @@ impl Content for Demo<Tui> {
|
|||
|
||||
//Align::Y(Layers::new(|add|{
|
||||
//add(&Background(Color::Rgb(128,0,0)))?;
|
||||
//add(&Outset::X(1, Align::Center(Stack::down(|add|{
|
||||
//add(&Align::X(Outset::Y(1, Layers::new(|add|{
|
||||
//add(&Margin::X(1, Align::Center(Stack::down(|add|{
|
||||
//add(&Align::X(Margin::Y(1, Layers::new(|add|{
|
||||
//add(&Background(Color::Rgb(0,128,0)))?;
|
||||
//add(&Align::Center("12345"))?;
|
||||
//add(&Align::Center("FOO"))
|
||||
//})))?;
|
||||
//add(&Outset::XY(1, 1, Layers::new(|add|{
|
||||
//add(&Margin::XY(1, 1, Layers::new(|add|{
|
||||
//add(&Align::Center("1234567"))?;
|
||||
//add(&Align::Center("BAR"))?;
|
||||
//add(&Background(Color::Rgb(0,0,128)))
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ render!(<Tui>|self: PianoHorizontal|{
|
|||
let cursor = move||PianoHorizontalCursor(self);
|
||||
|
||||
let border = Fill::wh(Outer(Style::default().fg(self.color.dark.rgb).bg(self.color.darkest.rgb)));
|
||||
let with_border = |x|lay!([border, Inset::xy(0, 0, &x)]);
|
||||
let with_border = |x|lay!([border, Padding::xy(0, 0, &x)]);
|
||||
|
||||
with_border(lay!([
|
||||
Push::x(0, row!(![
|
||||
|
|
@ -86,7 +86,7 @@ render!(<Tui>|self: PianoHorizontal|{
|
|||
field("Length:", length.to_string()), " ",
|
||||
field("Loop:", looped.to_string())
|
||||
])),
|
||||
Inset::xy(0, 1, Fill::wh(Bsp::s(
|
||||
Padding::xy(0, 1, Fill::wh(Bsp::s(
|
||||
Fixed::h(1, Bsp::e(
|
||||
Fixed::w(self.keys_width, ""),
|
||||
Fill::w(timeline()),
|
||||
|
|
|
|||
|
|
@ -210,7 +210,7 @@ render!(<Tui>|self: PoolView<'a>|{
|
|||
Tui::bg(bg, lay!(move|add|{
|
||||
add(&Fill::wh(Outer(Style::default().fg(color.base.rgb).bg(bg))))?;
|
||||
//add(&Lozenge(Style::default().bg(border_bg).fg(border_color)))?;
|
||||
add(&Inset::xy(0, 1, Fill::wh(col!(move|add|match mode {
|
||||
add(&Padding::xy(0, 1, Fill::wh(col!(move|add|match mode {
|
||||
Some(PoolMode::Import(_, ref file_picker)) => add(file_picker),
|
||||
Some(PoolMode::Export(_, ref file_picker)) => add(file_picker),
|
||||
_ => Ok(for (i, phrase) in phrases.iter().enumerate() {
|
||||
|
|
|
|||
|
|
@ -296,7 +296,7 @@ pub enum Pull<E: Engine, T: Render<E>> {
|
|||
by_axis!(+Pull);
|
||||
|
||||
/// Shrink from each side
|
||||
pub enum Inset<E: Engine, T> {
|
||||
pub enum Padding<E: Engine, T> {
|
||||
/// Decrease width
|
||||
X(E::Unit, T),
|
||||
/// Decrease height
|
||||
|
|
@ -305,10 +305,10 @@ pub enum Inset<E: Engine, T> {
|
|||
XY(E::Unit, E::Unit, T),
|
||||
}
|
||||
|
||||
by_axis!(+Inset);
|
||||
by_axis!(+Padding);
|
||||
|
||||
/// Grow on each side
|
||||
pub enum Outset<E: Engine, T: Render<E>> {
|
||||
pub enum Margin<E: Engine, T: Render<E>> {
|
||||
/// Increase width
|
||||
X(E::Unit, T),
|
||||
/// Increase height
|
||||
|
|
@ -317,7 +317,7 @@ pub enum Outset<E: Engine, T: Render<E>> {
|
|||
XY(E::Unit, E::Unit, T),
|
||||
}
|
||||
|
||||
by_axis!(+Outset);
|
||||
by_axis!(+Margin);
|
||||
|
||||
/// A cardinal direction.
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ impl<E: Engine, T: Render<E>> Render<E> for Pull<E, T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<E: Engine, T: Render<E>> Inset<E, T> {
|
||||
impl<E: Engine, T: Render<E>> Padding<E, T> {
|
||||
pub fn inner (&self) -> &T {
|
||||
match self {
|
||||
Self::X(_, i) => i,
|
||||
|
|
@ -84,7 +84,7 @@ impl<E: Engine, T: Render<E>> Inset<E, T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<E: Engine, T: Render<E>> Render<E> for Inset<E, T> {
|
||||
impl<E: Engine, T: Render<E>> Render<E> for Padding<E, T> {
|
||||
fn render (&self, to: &mut E::Output) -> Usually<()> {
|
||||
match self {
|
||||
Self::X(x, inner) => Push::x(*x, Shrink::x(*x, inner)),
|
||||
|
|
@ -95,7 +95,7 @@ impl<E: Engine, T: Render<E>> Render<E> for Inset<E, T> {
|
|||
}
|
||||
|
||||
|
||||
impl<E: Engine, T: Render<E>> Outset<E, T> {
|
||||
impl<E: Engine, T: Render<E>> Margin<E, T> {
|
||||
pub fn inner (&self) -> &T {
|
||||
match self {
|
||||
Self::X(_, i) => i,
|
||||
|
|
@ -105,7 +105,7 @@ impl<E: Engine, T: Render<E>> Outset<E, T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<E: Engine, T: Render<E>> Render<E> for Outset<E, T> {
|
||||
impl<E: Engine, T: Render<E>> Render<E> for Margin<E, T> {
|
||||
fn min_size (&self, to: E::Size) -> Perhaps<E::Size> {
|
||||
match *self {
|
||||
Self::X(x, ref inner) => Grow::x(x + x, inner),
|
||||
|
|
|
|||
60
src/test.rs
60
src/test.rs
|
|
@ -50,10 +50,10 @@
|
|||
//let engine = TestEngine(area, vec![vec![' ';10];10]);
|
||||
//let test = TestArea(4, 4);
|
||||
//assert_eq!(test.layout(area)?, Some([0, 0, 4, 4]));
|
||||
//assert_eq!(Outset::X(1, test).layout(area)?, Some([0, 0, 6, 4]));
|
||||
//assert_eq!(Margin::X(1, test).layout(area)?, Some([0, 0, 6, 4]));
|
||||
//assert_eq!(Align::X(test).layout(area)?, Some([3, 0, 4, 4]));
|
||||
//assert_eq!(Align::X(Outset::X(1, test)).layout(area)?, Some([2, 0, 6, 4]));
|
||||
//assert_eq!(Outset::X(1, Align::X(test)).layout(area)?, Some([2, 0, 6, 4]));
|
||||
//assert_eq!(Align::X(Margin::X(1, test)).layout(area)?, Some([2, 0, 6, 4]));
|
||||
//assert_eq!(Margin::X(1, Align::X(test)).layout(area)?, Some([2, 0, 6, 4]));
|
||||
//Ok(())
|
||||
//}
|
||||
|
||||
|
|
@ -71,24 +71,24 @@
|
|||
////})).layout(area)?,
|
||||
////Some([3, 1, 4, 8]));
|
||||
////assert_eq!(Align::Center(Stack::down(|add|{
|
||||
////add(&Outset::XY(2, 2, test))?;
|
||||
////add(&Margin::XY(2, 2, test))?;
|
||||
////add(&test)
|
||||
////})).layout(area)?,
|
||||
////Some([2, 0, 6, 10]));
|
||||
////assert_eq!(Align::Center(Stack::down(|add|{
|
||||
////add(&Outset::XY(2, 2, test))?;
|
||||
////add(&Inset::XY(2, 2, test))
|
||||
////add(&Margin::XY(2, 2, test))?;
|
||||
////add(&Padding::XY(2, 2, test))
|
||||
////})).layout(area)?,
|
||||
////Some([2, 1, 6, 8]));
|
||||
////assert_eq!(Stack::down(|add|{
|
||||
////add(&Outset::XY(2, 2, test))?;
|
||||
////add(&Inset::XY(2, 2, test))
|
||||
////add(&Margin::XY(2, 2, test))?;
|
||||
////add(&Padding::XY(2, 2, test))
|
||||
////}).layout(area)?,
|
||||
////Some([0, 0, 6, 8]));
|
||||
////assert_eq!(Stack::right(|add|{
|
||||
////add(&Stack::down(|add|{
|
||||
////add(&Outset::XY(2, 2, test))?;
|
||||
////add(&Inset::XY(2, 2, test))
|
||||
////add(&Margin::XY(2, 2, test))?;
|
||||
////add(&Padding::XY(2, 2, test))
|
||||
////}))?;
|
||||
////add(&Align::Center(TestArea(2 ,2)))
|
||||
////}).layout(area)?,
|
||||
|
|
@ -110,19 +110,19 @@
|
|||
////fn test_outset () -> Usually<()> {
|
||||
////let area: [u16;4] = [50, 50, 100, 100];
|
||||
////let test = TestArea(3, 3);
|
||||
////assert_eq!(Outset::X(1, test).layout(area)?, Some([49, 50, 5, 3]));
|
||||
////assert_eq!(Outset::Y(1, test).layout(area)?, Some([50, 49, 3, 5]));
|
||||
////assert_eq!(Outset::XY(1, 1, test).layout(area)?, Some([49, 49, 5, 5]));
|
||||
////assert_eq!(Margin::X(1, test).layout(area)?, Some([49, 50, 5, 3]));
|
||||
////assert_eq!(Margin::Y(1, test).layout(area)?, Some([50, 49, 3, 5]));
|
||||
////assert_eq!(Margin::XY(1, 1, test).layout(area)?, Some([49, 49, 5, 5]));
|
||||
////Ok(())
|
||||
////}
|
||||
|
||||
////#[test]
|
||||
////fn test_inset () -> Usually<()> {
|
||||
////fn test_padding () -> Usually<()> {
|
||||
////let area: [u16;4] = [50, 50, 100, 100];
|
||||
////let test = TestArea(3, 3);
|
||||
////assert_eq!(Inset::X(1, test).layout(area)?, Some([51, 50, 1, 3]));
|
||||
////assert_eq!(Inset::Y(1, test).layout(area)?, Some([50, 51, 3, 1]));
|
||||
////assert_eq!(Inset::XY(1, 1, test).layout(area)?, Some([51, 51, 1, 1]));
|
||||
////assert_eq!(Padding::X(1, test).layout(area)?, Some([51, 50, 1, 3]));
|
||||
////assert_eq!(Padding::Y(1, test).layout(area)?, Some([50, 51, 3, 1]));
|
||||
////assert_eq!(Padding::XY(1, 1, test).layout(area)?, Some([51, 51, 1, 1]));
|
||||
////Ok(())
|
||||
////}
|
||||
|
||||
|
|
@ -145,35 +145,35 @@
|
|||
////}).layout(area)?,
|
||||
////Some([0, 0, 5, 2]));
|
||||
////let area: [u16;4] = [1, 1, 100, 100];
|
||||
////assert_eq!(Outset::X(1, Stack::right(|add|{add(&"1")?;add(&"333")})).layout(area)?,
|
||||
////assert_eq!(Margin::X(1, Stack::right(|add|{add(&"1")?;add(&"333")})).layout(area)?,
|
||||
////Some([0, 1, 6, 1]));
|
||||
////assert_eq!(Outset::Y(1, Stack::right(|add|{add(&"1")?;add(&"333")})).layout(area)?,
|
||||
////assert_eq!(Margin::Y(1, Stack::right(|add|{add(&"1")?;add(&"333")})).layout(area)?,
|
||||
////Some([1, 0, 4, 3]));
|
||||
////assert_eq!(Outset::XY(1, 1, Stack::right(|add|{add(&"1")?;add(&"333")})).layout(area)?,
|
||||
////assert_eq!(Margin::XY(1, 1, Stack::right(|add|{add(&"1")?;add(&"333")})).layout(area)?,
|
||||
////Some([0, 0, 6, 3]));
|
||||
////assert_eq!(Stack::down(|add|{
|
||||
////add(&Outset::XY(1, 1, "1"))?;
|
||||
////add(&Outset::XY(1, 1, "333"))
|
||||
////add(&Margin::XY(1, 1, "1"))?;
|
||||
////add(&Margin::XY(1, 1, "333"))
|
||||
////}).layout(area)?,
|
||||
////Some([1, 1, 5, 6]));
|
||||
////let area: [u16;4] = [1, 1, 95, 100];
|
||||
////assert_eq!(Align::Center(Stack::down(|add|{
|
||||
////add(&Outset::XY(1, 1, "1"))?;
|
||||
////add(&Outset::XY(1, 1, "333"))
|
||||
////add(&Margin::XY(1, 1, "1"))?;
|
||||
////add(&Margin::XY(1, 1, "333"))
|
||||
////})).layout(area)?,
|
||||
////Some([46, 48, 5, 6]));
|
||||
////assert_eq!(Align::Center(Stack::down(|add|{
|
||||
////add(&Layers::new(|add|{
|
||||
//////add(&Outset::XY(1, 1, Background(Color::Rgb(0,128,0))))?;
|
||||
////add(&Outset::XY(1, 1, "1"))?;
|
||||
////add(&Outset::XY(1, 1, "333"))?;
|
||||
//////add(&Margin::XY(1, 1, Background(Color::Rgb(0,128,0))))?;
|
||||
////add(&Margin::XY(1, 1, "1"))?;
|
||||
////add(&Margin::XY(1, 1, "333"))?;
|
||||
//////add(&Background(Color::Rgb(0,128,0)))?;
|
||||
////Ok(())
|
||||
////}))?;
|
||||
////add(&Layers::new(|add|{
|
||||
//////add(&Outset::XY(1, 1, Background(Color::Rgb(0,0,128))))?;
|
||||
////add(&Outset::XY(1, 1, "555"))?;
|
||||
////add(&Outset::XY(1, 1, "777777"))?;
|
||||
//////add(&Margin::XY(1, 1, Background(Color::Rgb(0,0,128))))?;
|
||||
////add(&Margin::XY(1, 1, "555"))?;
|
||||
////add(&Margin::XY(1, 1, "777777"))?;
|
||||
//////add(&Background(Color::Rgb(0,0,128)))?;
|
||||
////Ok(())
|
||||
////}))
|
||||
|
|
|
|||
|
|
@ -356,19 +356,19 @@ fn to_seek_command (input: &TuiInput) -> Option<TransportCommand> {
|
|||
//Field("MSU ", format!("00m00s00u"))
|
||||
//),
|
||||
//),
|
||||
//selected.wrap(TransportFocus::Bpm, &Outset::X(1u16, {
|
||||
//selected.wrap(TransportFocus::Bpm, &Margin::X(1u16, {
|
||||
//row! {
|
||||
//"BPM ",
|
||||
//format!("{}.{:03}", *bpm as usize, (bpm * 1000.0) % 1000.0)
|
||||
//}
|
||||
//})),
|
||||
//selected.wrap(TransportFocus::Sync, &Outset::X(1u16, row! {
|
||||
//selected.wrap(TransportFocus::Sync, &Margin::X(1u16, row! {
|
||||
//"SYNC ", pulses_to_name(*sync as usize)
|
||||
//})),
|
||||
//selected.wrap(TransportFocus::Quant, &Outset::X(1u16, row! {
|
||||
//selected.wrap(TransportFocus::Quant, &Margin::X(1u16, row! {
|
||||
//"QUANT ", pulses_to_name(*quant as usize)
|
||||
//})),
|
||||
//selected.wrap(TransportFocus::Clock, &{
|
||||
//row!("B" , beat.as_str(), " T", msu.as_str()).outset_x(1)
|
||||
//row!("B" , beat.as_str(), " T", msu.as_str()).margin_x(1)
|
||||
//}).align_e().fill_x(),
|
||||
//).fill_x().bg(Color::Rgb(40, 50, 30))
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use crate::*;
|
|||
pub struct Bordered<S: BorderStyle, W: Render<Tui>>(pub S, pub W);
|
||||
|
||||
render!(<Tui>|self: Bordered<S: BorderStyle, W: Render<Tui>>|{
|
||||
Fill::wh(lay!([Border(self.0), Inset::xy(1, 1, widget(&self.1))]))
|
||||
Fill::wh(lay!([Border(self.0), Padding::xy(1, 1, widget(&self.1))]))
|
||||
});
|
||||
|
||||
pub struct Border<S: BorderStyle>(pub S);
|
||||
|
|
|
|||
|
|
@ -91,6 +91,6 @@ impl Render<Tui> for Styled<&str> {
|
|||
//impl<S: BorderStyle, W: Render<Tui>> Content<Tui> for Bordered<S, W> {
|
||||
//fn content (&self) -> impl Render<Tui> {
|
||||
//let content: &dyn Render<Tui> = &self.1;
|
||||
//lay! { content.inset_xy(1, 1), Border(self.0) }.fill_xy()
|
||||
//lay! { content.padding_xy(1, 1), Border(self.0) }.fill_xy()
|
||||
//}
|
||||
//}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue