diff --git a/layout/src/bsp.rs b/layout/src/bsp.rs index 013aca31..b9e50ffd 100644 --- a/layout/src/bsp.rs +++ b/layout/src/bsp.rs @@ -60,6 +60,34 @@ impl, Y: Content> Bsp { pub fn w (x: X, y: Y) -> Self { Self::West(None, Some(x), Some(y)) } pub fn a (x: X, y: Y) -> Self { Self::Above(Some(x), Some(y)) } pub fn b (x: X, y: Y) -> Self { Self::Below(Some(x), Some(y)) } + + pub fn areas (&self, outer: E::Area) -> [E::Area;2] { + let [x, y, w, h] = outer.xywh(); + match self { + Self::Null(_) => [[x, y, 0.into(), 0.into()].into(), [x, y, 0.into(), 0.into()].into()], + Self::Above(a, b) | Self::Below(a, b) => [a.layout(outer), b.layout(outer)], + Self::North(_, a, b) => { + let a = a.layout(outer); + let b = b.layout([x, y, w, h.minus(a.h())].into()); + [a, b] + } + Self::South(_, a, b) => { + let a = a.layout(outer); + let b = b.layout([x, y + a.h(), w, h.minus(a.h())].into()); + [a, b] + }, + Self::East(_, a, b) => { + let a = a.layout(outer); + let b = b.layout([x + a.w(), y, w.minus(a.w()), h].into()); + [a, b] + }, + Self::West(_, a, b) => { + let a = a.layout(outer); + let b = b.layout([x, y, w.minus(a.w()), h].into()); + [a, b] + }, + } + } } impl, Y: Content> Default for Bsp { @@ -70,75 +98,36 @@ impl, Y: Content> Default for Bsp { impl, Y: Content> Content for Bsp { fn layout (&self, outer: E::Area) -> E::Area { + let [a, b] = self.areas(outer); + let [x, y] = outer.center(); match self { - Self::Null(_) => [0.into(), 0.into(), 0.into(), 0.into()].into(), - Self::North(_, a, b) => { - let a = a.layout(outer); - let b = b.layout(North.split_fixed(outer, a.y() + a.h()).1.into()); - [a.x().min(b.x()), a.y().min(b.y()), a.w().max(b.w()), a.h() + b.h()].into() - } - Self::South(_, a, b) => { - let a = a.layout(outer); - let b = b.layout(South.split_fixed(outer, a.y() + a.h()).1.into()); - [a.x().min(b.x()), a.y().min(b.y()), a.w().max(b.w()), a.h() + b.h()].into() - }, - Self::East(_, a, b) => { - let a = a.layout(outer); - let b = b.layout(East.split_fixed(outer, a.x() + a.w()).1.into()); - [a.x().min(b.x()), a.y().min(b.y()), a.w() + b.w(), a.h().max(b.h())].into() - }, - Self::West(_, a, b) => { - let a = a.layout(outer); - let b = b.layout(West.split_fixed(outer, a.x() + a.w()).1.into()); - [a.x().min(b.x()), a.y().min(b.y()), a.w() + b.w(), a.h().max(b.h())].into() - }, - Self::Above(a, b) | Self::Below(a, b) => { - let a = a.layout(outer); - let b = b.layout(outer); - [a.x().min(b.x()), a.y().min(b.y()), a.w().max(b.w()), a.h().max(b.h())].into() - } - } + Self::Null(_) => + [x, y, 0.into(), 0.into()], + Self::North(_, _, _) => + [a.x().min(b.x()), a.y().min(b.y()), a.w().max(b.w()), a.h() + b.h()], + Self::South(_, _, _) => + [a.x().min(b.x()), a.y().min(b.y()), a.w().max(b.w()), a.h() + b.h()], + Self::East(_, _, _) => + [a.x().min(b.x()), a.y().min(b.y()), a.w() + b.w(), a.h().max(b.h())], + Self::West(_, _, _) => + [a.x().min(b.x()), a.y().min(b.y()), a.w() + b.w(), a.h().max(b.h())], + Self::Above(_, _) | Self::Below(_, _) => + [a.x().min(b.x()), a.y().min(b.y()), a.w().max(b.w()), a.h().max(b.h())] + }.into() } fn render (&self, to: &mut E::Output) { - let area = to.area().clone(); + let [area_a, area_b] = self.areas(to.area()); match self { - Self::North(_, a, b) => { - let area_a = a.layout(area); - let area_b = b.layout(North.split_fixed(area, area_a.y() + area_a.h()).1.into()); - to.place(area_a, a); - to.place(area_b, b); - }, - Self::South(_, a, b) => { - let area_a = a.layout(area).clone(); - let area_b = b.layout(South.split_fixed(area, area_a.y() + area_a.h()).1.into()).clone(); - to.place(area_a, a); - to.place(area_b, b); - }, - Self::East(_, a, b) => { - let area_a = a.layout(area); - let area_b = b.layout(East.split_fixed(area, area_a.x() + area_a.w()).1.into()); - to.place(area_a, a); - to.place(area_b, b); - }, - Self::West(_, a, b) => { - let area_a = a.layout(area); - let area_b = b.layout(West.split_fixed(area, area_a.x() + area_a.w()).1.into()); - to.place(area_a, a); - to.place(area_b, b); - }, - Self::Above(a, b) => { - let area_a = a.layout(area); - let area_b = b.layout(area); - to.place(area_b, b); - to.place(area_a, a); - }, + Self::North(_, a, b) | + Self::South(_, a, b) | + Self::East(_, a, b) | + Self::West(_, a, b) | + Self::Above(a, b) | Self::Below(a, b) => { - let area_a = a.layout(area); - let area_b = b.layout(area); to.place(area_a, a); to.place(area_b, b); }, - Self::Null(_) => {} + _ => {}, } } } diff --git a/src/transport.rs b/src/transport.rs index c67c9ea4..72128660 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -88,6 +88,12 @@ impl TransportView { } } } +pub struct PlayPause(pub bool); +render!(Tui: (self: PlayPause) => Tui::bg( + if self.0{Color::Rgb(0,128,0)}else{Color::Rgb(128,64,0)}, + Fixed::x(5, Tui::either(self.0, + Tui::fg(Color::Rgb(0, 255, 0), Bsp::s(" 🭍🭑🬽 ", " 🭞🭜🭘 ",)), + Tui::fg(Color::Rgb(255, 128, 0), Bsp::s(" ▗▄▖ ", " ▝▀▘ ",)))))); render!(Tui: (self: TransportView) => { let color = self.color; //let transport_field = move|label, value|row!( @@ -109,12 +115,6 @@ render!(Tui: (self: TransportView) => { )), )))*/ }); -pub struct PlayPause(pub bool); -render!(Tui: (self: PlayPause) => Tui::bg( - if self.0{Color::Rgb(0,128,0)}else{Color::Rgb(128,64,0)}, - Fixed::x(5, Tui::either(self.0, - Tui::fg(Color::Rgb(0, 255, 0), Bsp::s(" 🭍🭑🬽 ", " 🭞🭜🭘 ",)), - Tui::fg(Color::Rgb(255, 128, 0), Bsp::s(" ▗▄▖ ", " ▝▀▘ ",)))))); impl HasFocus for TransportTui { type Item = TransportFocus; fn focused (&self) -> Self::Item {