use egui::{Context, RawInput, Rect, Shape, Vec2, pos2};
use elegance::{Theme, Toast, Toasts};
fn visit(shape: &Shape, f: &mut dyn FnMut(&Shape)) {
match shape {
Shape::Vec(shapes) => {
for shape in shapes {
visit(shape, f);
}
}
other => f(other),
}
}
#[test]
fn toast_text_is_never_justified() {
let ctx = Context::default();
Theme::slate().install(&ctx);
let input = RawInput {
screen_rect: Some(Rect::from_min_size(pos2(0.0, 0.0), Vec2::new(600.0, 400.0))),
..Default::default()
};
let frame = |ui: &mut egui::Ui| {
Toast::new("Export finished")
.description("Saved /var/tmp/exports/quarterly-report-archive.tar.gz")
.show(ui.ctx());
Toasts::new().render(ui.ctx());
};
let mut output = ctx.run_ui(input.clone(), frame);
output.textures_delta.clear();
let mut output = ctx.run_ui(input, frame);
output.textures_delta.clear();
let mut wrapped = false;
for clipped in &output.shapes {
visit(&clipped.shape, &mut |shape| {
if let Shape::Text(text) = shape {
assert!(
!text.galley.job.justify,
"justified toast text: {:?}",
text.galley.job.text
);
wrapped |= text.galley.rows.len() > 1;
}
});
}
assert!(wrapped, "the toast description did not wrap");
}