mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-01-11 18:46:41 +01:00
output: refactor Content and Render traits
This commit is contained in:
parent
74b3af2212
commit
1c21a85f27
24 changed files with 346 additions and 613 deletions
|
|
@ -48,33 +48,36 @@ impl<A> Align<A> {
|
|||
#[inline] pub const fn se (a: A) -> Self { Self(Alignment::SE, a) }
|
||||
}
|
||||
|
||||
impl<E: Output, A: Content<E>> Content<E> for Align<A> {
|
||||
fn content (&self) -> impl Render<E> + '_ {
|
||||
&self.1
|
||||
}
|
||||
impl<E: Output, A: Render<E>> Render<E> for Align<A> {
|
||||
fn layout (&self, on: E::Area) -> E::Area {
|
||||
self.0.align(on, &self.1)
|
||||
}
|
||||
fn render (&self, to: &mut E) {
|
||||
to.place(self.layout(to.area()), &self.1)
|
||||
}
|
||||
}
|
||||
|
||||
impl Alignment {
|
||||
fn align <E: Output> (&self, on: E::Area, content: impl Render<E>) -> E::Area {
|
||||
use Alignment::*;
|
||||
let it = Render::layout(&self.content(), on).xywh();
|
||||
let it = content.layout(on).xywh();
|
||||
let cx = on.x()+(on.w().minus(it.w())/2.into());
|
||||
let cy = on.y()+(on.h().minus(it.h())/2.into());
|
||||
let fx = (on.x()+on.w()).minus(it.w());
|
||||
let fy = (on.y()+on.h()).minus(it.h());
|
||||
let [x, y] = match self.0 {
|
||||
Center => [cx, cy],
|
||||
X => [cx, it.y()],
|
||||
Y => [it.x(), cy],
|
||||
NW => [on.x(), on.y()],
|
||||
N => [cx, on.y()],
|
||||
NE => [fx, on.y()],
|
||||
W => [on.x(), cy],
|
||||
E => [fx, cy],
|
||||
SW => [on.x(), fy],
|
||||
S => [cx, fy],
|
||||
SE => [fx, fy],
|
||||
}.into();
|
||||
let [x, y] = match self {
|
||||
Center => [cx, cy],
|
||||
X => [cx, it.y()],
|
||||
Y => [it.x(), cy],
|
||||
NW => [on.x(), on.y()],
|
||||
N => [cx, on.y()],
|
||||
NE => [fx, on.y()],
|
||||
W => [on.x(), cy],
|
||||
E => [fx, cy],
|
||||
SW => [on.x(), fy],
|
||||
S => [cx, fy],
|
||||
SE => [fx, fy],
|
||||
};
|
||||
[x, y, it.w(), it.h()].into()
|
||||
}
|
||||
fn render (&self, to: &mut E) {
|
||||
to.place(Content::layout(self, to.area()), &self.content())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue