fix alignments (when used in the right order)

This commit is contained in:
🪞👃🪞 2025-01-10 19:58:26 +01:00
parent e460ceaf48
commit 86188b59db
2 changed files with 28 additions and 31 deletions

View file

@ -26,29 +26,26 @@ impl<E: Output, T: Content<E>> Content<E> for Align<T> {
fn layout (&self, on: E::Area) -> E::Area { fn layout (&self, on: E::Area) -> E::Area {
use Alignment::*; use Alignment::*;
let it = Render::layout(&self.content(), on).xywh(); let it = Render::layout(&self.content(), on).xywh();
let centered = on.center_xy(it.wh()); let cx = on.x()+(on.w().minus(it.w())/2.into());
let far_x = (on.x() + on.w()).minus(it.w()); let cy = on.y()+(on.h().minus(it.h())/2.into());
let far_y = (on.y() + on.h()).minus(it.h()); let fx = (on.x()+on.w()).minus(it.w());
let fy = (on.y()+on.h()).minus(it.h());
let [x, y] = match self.0 { let [x, y] = match self.0 {
Center => [cx, cy],
X => [cx, it.y()],
Y => [it.x(), cy],
NW => [on.x(), on.y()], NW => [on.x(), on.y()],
N => [centered.x(), on.y()], N => [cx, on.y()],
NE => [far_x, on.y()], NE => [fx, on.y()],
E => [far_x, centered.y()], W => [on.x(), cy],
SE => [far_x, far_y ], E => [fx, cy],
S => [centered.x(), far_y ], SW => [on.x(), fy],
SW => [on.x(), far_y ], S => [cx, fy],
W => [on.x(), centered.y()], SE => [fx, fy],
}.into();
Center => centered.xy(), [x, y, it.w(), it.h()].into()
X => [centered.x(), it.y()],
Y => [it.x(), centered.y()],
};
[x, y, centered.w(), centered.h()].into()
} }
fn render (&self, render: &mut E) { fn render (&self, to: &mut E) {
let content = &self.content(); to.place(Content::layout(self, to.area()), &self.content())
let it = Render::layout(content, render.area()).xywh();
render.place(it.into(), content)
} }
} }

View file

@ -1,11 +1,11 @@
(bsp/s (bsp/s
(bsp/e (fixed/xy 5 3 (align/nw :hello)) (bsp/e (fixed/xy 8 5 (align/nw :hello))
(bsp/e (fixed/xy 5 3 (align/n :hello)) (bsp/e (fixed/xy 8 5 (align/n :hello))
(fixed/xy 5 3 (align/ne :hello)))) (fixed/xy 8 5 (align/ne :hello))))
(bsp/s (bsp/s
(bsp/e (fixed/xy 5 3 (align/w :hello)) (bsp/e (fixed/xy 8 5 (align/w :hello))
(bsp/e (fixed/xy 5 3 (align/c :hello)) (bsp/e (fixed/xy 8 5 (align/c :hello))
(fixed/xy 5 3 (align/e :hello)))) (fixed/xy 8 5 (align/e :hello))))
(bsp/e (fixed/xy 5 3 (align/sw :hello)) (bsp/e (fixed/xy 8 5 (align/sw :hello))
(bsp/e (fixed/xy 5 3 (align/s :hello)) (bsp/e (fixed/xy 8 5 (align/s :hello))
(fixed/xy 5 3 (align/se :hello)))))) (fixed/xy 8 5 (align/se :hello))))))