1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 14:20:04 -04:00

Test that halign & justify works the same

This commit is contained in:
Emil Ernerfeldt
2025-03-30 16:58:19 +02:00
parent 4ee4572f02
commit b0d0d2f279

View File

@@ -997,6 +997,7 @@ mod tests {
use super::*; use super::*;
use crate::{text::TextFormat, Stroke}; use crate::{text::TextFormat, Stroke};
use ecolor::Color32; use ecolor::Color32;
use emath::Align;
fn jobs() -> Vec<LayoutJob> { fn jobs() -> Vec<LayoutJob> {
vec![ vec![
@@ -1021,7 +1022,6 @@ mod tests {
{ {
let mut job = LayoutJob { let mut job = LayoutJob {
first_row_min_height: 20.0, first_row_min_height: 20.0,
justify: true,
..Default::default() ..Default::default()
}; };
job.append( job.append(
@@ -1067,33 +1067,40 @@ mod tests {
FontDefinitions::default(), FontDefinitions::default(),
); );
for job in jobs() { for halign in [Align::Min, Align::Center, Align::Max] {
let whole = GalleyCache::default().layout(&mut fonts, job.clone(), false); for justify in [false, true] {
for mut job in jobs() {
job.halign = halign;
job.justify = justify;
let split = GalleyCache::default().layout(&mut fonts, job.clone(), true); let whole = GalleyCache::default().layout(&mut fonts, job.clone(), false);
for (i, row) in whole.rows.iter().enumerate() { let split = GalleyCache::default().layout(&mut fonts, job.clone(), true);
println!(
for (i, row) in whole.rows.iter().enumerate() {
println!(
"Whole row {i}: section_index_at_start={}, first glyph section_index: {:?}", "Whole row {i}: section_index_at_start={}, first glyph section_index: {:?}",
row.row.section_index_at_start, row.row.section_index_at_start,
row.row.glyphs.first().map(|g| g.section_index) row.row.glyphs.first().map(|g| g.section_index)
); );
} }
for (i, row) in split.rows.iter().enumerate() { for (i, row) in split.rows.iter().enumerate() {
println!( println!(
"Split row {i}: section_index_at_start={}, first glyph section_index: {:?}", "Split row {i}: section_index_at_start={}, first glyph section_index: {:?}",
row.row.section_index_at_start, row.row.section_index_at_start,
row.row.glyphs.first().map(|g| g.section_index) row.row.glyphs.first().map(|g| g.section_index)
); );
} }
// Don't compare for equaliity; but format with a specific precision and make sure we hit that. // Don't compare for equaliity; but format with a specific precision and make sure we hit that.
similar_asserts::assert_eq!( similar_asserts::assert_eq!(
format!("{:#.5?}", split), format!("{:#.5?}", split),
format!("{:#.5?}", whole), format!("{:#.5?}", whole),
"pixels_per_point: {pixels_per_point:.2}, input text: '{}'", "pixels_per_point: {pixels_per_point:.2}, input text: '{}'",
job.text job.text
); );
}
}
} }
} }
} }