mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
wip: fixing Bsp
This commit is contained in:
parent
d17d20e7db
commit
8454b95df8
2 changed files with 56 additions and 67 deletions
|
|
@ -60,6 +60,34 @@ impl<E: Engine, X: Content<E>, Y: Content<E>> Bsp<E, X, Y> {
|
||||||
pub fn w (x: X, y: Y) -> Self { Self::West(None, Some(x), Some(y)) }
|
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 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 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<E: Engine, X: Content<E>, Y: Content<E>> Default for Bsp<E, X, Y> {
|
impl<E: Engine, X: Content<E>, Y: Content<E>> Default for Bsp<E, X, Y> {
|
||||||
|
|
@ -70,75 +98,36 @@ impl<E: Engine, X: Content<E>, Y: Content<E>> Default for Bsp<E, X, Y> {
|
||||||
|
|
||||||
impl<E: Engine, X: Content<E>, Y: Content<E>> Content<E> for Bsp<E, X, Y> {
|
impl<E: Engine, X: Content<E>, Y: Content<E>> Content<E> for Bsp<E, X, Y> {
|
||||||
fn layout (&self, outer: E::Area) -> E::Area {
|
fn layout (&self, outer: E::Area) -> E::Area {
|
||||||
|
let [a, b] = self.areas(outer);
|
||||||
|
let [x, y] = outer.center();
|
||||||
match self {
|
match self {
|
||||||
Self::Null(_) => [0.into(), 0.into(), 0.into(), 0.into()].into(),
|
Self::Null(_) =>
|
||||||
Self::North(_, a, b) => {
|
[x, y, 0.into(), 0.into()],
|
||||||
let a = a.layout(outer);
|
Self::North(_, _, _) =>
|
||||||
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()],
|
||||||
[a.x().min(b.x()), a.y().min(b.y()), a.w().max(b.w()), a.h() + b.h()].into()
|
Self::South(_, _, _) =>
|
||||||
}
|
[a.x().min(b.x()), a.y().min(b.y()), a.w().max(b.w()), a.h() + b.h()],
|
||||||
Self::South(_, a, b) => {
|
Self::East(_, _, _) =>
|
||||||
let a = a.layout(outer);
|
[a.x().min(b.x()), a.y().min(b.y()), a.w() + b.w(), a.h().max(b.h())],
|
||||||
let b = b.layout(South.split_fixed(outer, a.y() + a.h()).1.into());
|
Self::West(_, _, _) =>
|
||||||
[a.x().min(b.x()), a.y().min(b.y()), a.w().max(b.w()), a.h() + b.h()].into()
|
[a.x().min(b.x()), a.y().min(b.y()), a.w() + b.w(), a.h().max(b.h())],
|
||||||
},
|
Self::Above(_, _) | Self::Below(_, _) =>
|
||||||
Self::East(_, a, b) => {
|
[a.x().min(b.x()), a.y().min(b.y()), a.w().max(b.w()), a.h().max(b.h())]
|
||||||
let a = a.layout(outer);
|
}.into()
|
||||||
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()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fn render (&self, to: &mut E::Output) {
|
fn render (&self, to: &mut E::Output) {
|
||||||
let area = to.area().clone();
|
let [area_a, area_b] = self.areas(to.area());
|
||||||
match self {
|
match self {
|
||||||
Self::North(_, a, b) => {
|
Self::North(_, a, b) |
|
||||||
let area_a = a.layout(area);
|
Self::South(_, a, b) |
|
||||||
let area_b = b.layout(North.split_fixed(area, area_a.y() + area_a.h()).1.into());
|
Self::East(_, a, b) |
|
||||||
to.place(area_a, a);
|
Self::West(_, a, b) |
|
||||||
to.place(area_b, b);
|
Self::Above(a, 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::Below(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_a, a);
|
||||||
to.place(area_b, b);
|
to.place(area_b, b);
|
||||||
},
|
},
|
||||||
Self::Null(_) => {}
|
_ => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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) => {
|
render!(Tui: (self: TransportView) => {
|
||||||
let color = self.color;
|
let color = self.color;
|
||||||
//let transport_field = move|label, value|row!(
|
//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 {
|
impl HasFocus for TransportTui {
|
||||||
type Item = TransportFocus;
|
type Item = TransportFocus;
|
||||||
fn focused (&self) -> Self::Item {
|
fn focused (&self) -> Self::Item {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue