mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
fix alignments (when used in the right order)
This commit is contained in:
parent
e460ceaf48
commit
86188b59db
2 changed files with 28 additions and 31 deletions
|
|
@ -26,29 +26,26 @@ impl<E: Output, T: Content<E>> Content<E> for Align<T> {
|
|||
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())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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))))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue