From 863d57447a5b7f01bd63be2179dd3135fdef780e Mon Sep 17 00:00:00 2001 From: unspeaker Date: Wed, 1 Jan 2025 19:38:10 +0100 Subject: [PATCH] fixed Bsp? --- layout/src/direction.rs | 84 +++++++++++++++++++++++++++-------------- src/transport.rs | 2 +- 2 files changed, 57 insertions(+), 29 deletions(-) diff --git a/layout/src/direction.rs b/layout/src/direction.rs index 37b79eb7..3319bf5a 100644 --- a/layout/src/direction.rs +++ b/layout/src/direction.rs @@ -20,6 +20,21 @@ impl Direction { pub struct Bsp, Y: Content>(Direction, X, Y, PhantomData); +impl, B: Content> Content for Bsp { + fn layout (&self, outer: E::Area) -> E::Area { + let [_, _, c] = self.areas(outer); + c + } + fn render (&self, to: &mut E::Output) { + let [area_a, area_b, _] = self.areas(to.area()); + let (a, b) = self.contents(); + match self.0 { + Below => { to.place(area_a, a); to.place(area_b, b); }, + _ => { to.place(area_b, b); to.place(area_a, a); } + } + } +} + impl, B: Content> Bsp { pub fn n (a: A, b: B) -> Self { Self(North, a, b, Default::default()) } pub fn s (a: A, b: B) -> Self { Self(South, a, b, Default::default()) } @@ -28,37 +43,50 @@ impl, B: Content> Bsp { pub fn a (a: A, b: B) -> Self { Self(Above, a, b, Default::default()) } pub fn b (a: A, b: B) -> Self { Self(Below, a, b, Default::default()) } pub fn contents (&self) -> (&A, &B) { (&self.1, &self.2) } - pub fn areas (&self, outer: E::Area) -> [E::Area;2] { + pub fn areas (&self, outer: E::Area) -> [E::Area;3] { let [x, y, w, h] = outer.xywh(); let (a, b) = self.contents(); - let a = a.layout(outer); - let b = match self.0 { - North => b.layout([x, y, w, h.minus(a.h())].into()), - South => b.layout([x, y + a.h(), w, h.minus(a.h())].into()), - East => b.layout([x + a.w(), y, w.minus(a.w()), h].into()), - West => b.layout([x, y, w.minus(a.w()), h].into()), - Above | Below => b.layout(outer), - }; - [a, b] - } -} - -impl, B: Content> Content for Bsp { - fn layout (&self, outer: E::Area) -> E::Area { - let [a, b] = self.areas(outer); - let [ax, ay, aw, ah] = a.xywh(); - let [bx, by, bw, bh] = b.xywh(); + let [ax, ay, aw, ah] = a.layout(outer).xywh(); + let [bx, by, bw, bh] = b.layout(match self.0 { + Above | Below => outer, + South => [x, y + ah, w, h.minus(ah)].into(), + North => [x, y, w, h.minus(ah)].into(), + East => [x + aw, y, w.minus(aw), h].into(), + West => [x, y, w.minus(aw), h].into(), + }).xywh(); match self.0 { - North | South => [ax.min(bx), ay.min(by), aw.max(bw), ah + bh ], - East | West => [ax.min(bx), ay.min(by), aw + bw, ah.max(bh)], - Above | Below => [ax.min(bx), ay.min(by), aw.max(bw), ah.max(bh)], - }.into() - } - fn render (&self, to: &mut E::Output) { - let [area_a, area_b] = self.areas(to.area()); - let (a, b) = self.contents(); - to.place(area_a, a); - to.place(area_b, b); + Above | Below => { + let x = ax.min(bx); + let w = (ax+aw).max(bx+bw).minus(x); + let y = ay.min(by); + let h = (ay+ah).max(by+bh).minus(y); + [[ax, ay, aw, ah].into(), [bx, by, bw, bh].into(), [x, y, w, h].into()] + }, + South => { + let [x, y, w, h] = outer.center_xy([aw.max(bw), ah + bh]); + let a = [x, y, aw, ah]; + let b = [x, y + ah, bw, bh]; + [a.into(), b.into(), [x, y, w, h].into()] + }, + North => { + let [x, y, w, h] = outer.center_xy([aw.max(bw), ah + bh]); + let a = [x, y + bh, aw, ah]; + let b = [x, y, bw, bh]; + [a.into(), b.into(), [x, y, w, h].into()] + }, + East => { + let [x, y, w, h] = outer.center_xy([aw.max(bw), ah + bh]); + let a = [x, y, aw, ah]; + let b = [x + aw, y, bw, bh]; + [a.into(), b.into(), [x, y, w, h].into()] + }, + West => { + let [x, y, w, h] = outer.center_xy([aw.max(bw), ah + bh]); + let a = [x + bw, y, aw, ah]; + let b = [x, y, bw, bh]; + [a.into(), b.into(), [x, y, w, h].into()] + }, + } } } diff --git a/src/transport.rs b/src/transport.rs index 72128660..0298f506 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -23,7 +23,7 @@ from_jack!(|jack|TransportTui Self { has_clock!(|self: TransportTui|&self.clock); audio!(|self: TransportTui, client, scope|ClockAudio(self).process(client, scope)); handle!(|self: TransportTui, from|TransportCommand::execute_with_state(self, from)); -render!(Tui: (self: TransportTui) => PlayPause(false)); +render!(Tui: (self: TransportTui) => Bsp::s("play", "pause"));//play/pause");//PlayPause(false)); /*Align::x(Fixed::y(3, row!( Fixed::x(5, Fixed::y(3, PlayPause(false))), TransportView::new(self, Some(self.color), true),