From 86188b59db653babf6fb6fed2308cb4f21c48326 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Fri, 10 Jan 2025 19:58:26 +0100 Subject: [PATCH] fix alignments (when used in the right order) --- output/src/align.rs | 41 +++++++++++++++++++---------------------- tek/examples/edn12.edn | 18 +++++++++--------- 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/output/src/align.rs b/output/src/align.rs index 530aef63..acc52fb6 100644 --- a/output/src/align.rs +++ b/output/src/align.rs @@ -26,29 +26,26 @@ impl> Content for Align { fn layout (&self, on: E::Area) -> E::Area { use Alignment::*; let it = Render::layout(&self.content(), on).xywh(); - let centered = on.center_xy(it.wh()); - let far_x = (on.x() + on.w()).minus(it.w()); - let far_y = (on.y() + on.h()).minus(it.h()); + 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 { - NW => [on.x(), on.y()], - N => [centered.x(), on.y()], - NE => [far_x, on.y()], - E => [far_x, centered.y()], - SE => [far_x, far_y ], - S => [centered.x(), far_y ], - SW => [on.x(), far_y ], - W => [on.x(), centered.y()], - - Center => centered.xy(), - - X => [centered.x(), it.y()], - Y => [it.x(), centered.y()], - }; - [x, y, centered.w(), centered.h()].into() + 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(); + [x, y, it.w(), it.h()].into() } - fn render (&self, render: &mut E) { - let content = &self.content(); - let it = Render::layout(content, render.area()).xywh(); - render.place(it.into(), content) + fn render (&self, to: &mut E) { + to.place(Content::layout(self, to.area()), &self.content()) } } diff --git a/tek/examples/edn12.edn b/tek/examples/edn12.edn index 130caed2..26e3f5f0 100644 --- a/tek/examples/edn12.edn +++ b/tek/examples/edn12.edn @@ -1,11 +1,11 @@ (bsp/s - (bsp/e (fixed/xy 5 3 (align/nw :hello)) - (bsp/e (fixed/xy 5 3 (align/n :hello)) - (fixed/xy 5 3 (align/ne :hello)))) + (bsp/e (fixed/xy 8 5 (align/nw :hello)) + (bsp/e (fixed/xy 8 5 (align/n :hello)) + (fixed/xy 8 5 (align/ne :hello)))) (bsp/s - (bsp/e (fixed/xy 5 3 (align/w :hello)) - (bsp/e (fixed/xy 5 3 (align/c :hello)) - (fixed/xy 5 3 (align/e :hello)))) - (bsp/e (fixed/xy 5 3 (align/sw :hello)) - (bsp/e (fixed/xy 5 3 (align/s :hello)) - (fixed/xy 5 3 (align/se :hello)))))) + (bsp/e (fixed/xy 8 5 (align/w :hello)) + (bsp/e (fixed/xy 8 5 (align/c :hello)) + (fixed/xy 8 5 (align/e :hello)))) + (bsp/e (fixed/xy 8 5 (align/sw :hello)) + (bsp/e (fixed/xy 8 5 (align/s :hello)) + (fixed/xy 8 5 (align/se :hello))))))