Verify top and bottom alignment through rendered GUI buttons
This commit is contained in:
parent
f0da880d35
commit
6ab4100527
|
|
@ -1422,6 +1422,88 @@ mod tests {
|
|||
assert!(app.marquee.is_none());
|
||||
}
|
||||
#[test]
|
||||
fn top_and_bottom_buttons_align_rendered_edges_for_every_target() {
|
||||
for target in [
|
||||
AlignTarget::Selection,
|
||||
AlignTarget::Screen,
|
||||
AlignTarget::Layer(0),
|
||||
AlignTarget::Layer(1),
|
||||
] {
|
||||
for (title, expected_y) in [
|
||||
(
|
||||
"Align top",
|
||||
match target {
|
||||
AlignTarget::Selection | AlignTarget::Layer(0) => [60.0, 60.0],
|
||||
AlignTarget::Screen => [0.0, 0.0],
|
||||
AlignTarget::Layer(_) => [180.0, 180.0],
|
||||
},
|
||||
),
|
||||
(
|
||||
"Align bottom",
|
||||
match target {
|
||||
AlignTarget::Selection | AlignTarget::Layer(1) => [340.0, 180.0],
|
||||
AlignTarget::Screen => [880.0, 720.0],
|
||||
AlignTarget::Layer(_) => [60.0, -100.0],
|
||||
},
|
||||
),
|
||||
] {
|
||||
let mut app = Editor::default();
|
||||
app.layout
|
||||
.apply(
|
||||
0,
|
||||
Geometry {
|
||||
x: 90.0,
|
||||
y: 60.0,
|
||||
width: 300.0,
|
||||
height: 200.0,
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
app.layout.set_selection([true; 2]);
|
||||
app.align_target = target;
|
||||
let before = *app.layout.layers();
|
||||
let ctx = egui::Context::default();
|
||||
let output = frame(&mut app, &ctx, vec![]);
|
||||
let pos = output
|
||||
.shapes
|
||||
.iter()
|
||||
.find_map(|s| match &s.shape {
|
||||
egui::epaint::Shape::Text(t) if t.galley.job.text == title => {
|
||||
Some(t.pos + Vec2::new(20.0, 6.0))
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.unwrap();
|
||||
frame(
|
||||
&mut app,
|
||||
&ctx,
|
||||
vec![egui::Event::PointerMoved(pos), mouse(pos, true)],
|
||||
);
|
||||
frame(&mut app, &ctx, vec![mouse(pos, false)]);
|
||||
let output = frame(&mut app, &ctx, vec![]);
|
||||
let rects = layer_rects(&output);
|
||||
assert_eq!(rects.len(), 2);
|
||||
let edges = if title == "Align top" {
|
||||
[rects[0].top(), rects[1].top()]
|
||||
} else {
|
||||
[rects[0].bottom(), rects[1].bottom()]
|
||||
};
|
||||
assert!((edges[0] - edges[1]).abs() < 0.001, "{title}: {target:?}");
|
||||
for i in 0..2 {
|
||||
assert_eq!(
|
||||
app.layout.layers()[i].y,
|
||||
expected_y[i],
|
||||
"{title}: {target:?}"
|
||||
);
|
||||
assert_eq!(app.layout.layers()[i].x, before[i].x);
|
||||
assert_eq!(app.layout.layers()[i].height, before[i].height);
|
||||
}
|
||||
app.layout.undo();
|
||||
assert_eq!(*app.layout.layers(), before);
|
||||
}
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn alignment_button_updates_selected_layers_and_undo_restores() {
|
||||
let mut app = Editor::default();
|
||||
let ctx = egui::Context::default();
|
||||
|
|
|
|||
Loading…
Reference in New Issue