mirror of
https://github.com/emilk/egui.git
synced 2026-06-26 22:53:14 -04:00
Change parameter order and fix bug in test
This commit is contained in:
committed by
valadaptive
parent
3385ad5bcb
commit
0d628e6db3
@@ -691,8 +691,8 @@ impl FontsView<'_> {
|
||||
let allow_split_paragraphs = true; // Optimization for editing text with many paragraphs.
|
||||
self.galley_cache.layout(
|
||||
self.fonts,
|
||||
job,
|
||||
self.pixels_per_point,
|
||||
job,
|
||||
allow_split_paragraphs,
|
||||
)
|
||||
}
|
||||
@@ -923,7 +923,7 @@ impl GalleyCache {
|
||||
);
|
||||
galley
|
||||
} else {
|
||||
let galley = super::layout(fonts, job, pixels_per_point);
|
||||
let galley = super::layout(fonts, pixels_per_point, job);
|
||||
let galley = Arc::new(galley);
|
||||
entry.insert(CachedGalley {
|
||||
last_used: self.generation,
|
||||
@@ -941,8 +941,8 @@ impl GalleyCache {
|
||||
fn layout(
|
||||
&mut self,
|
||||
fonts: &mut FontsImpl,
|
||||
job: LayoutJob,
|
||||
pixels_per_point: f32,
|
||||
job: LayoutJob,
|
||||
allow_split_paragraphs: bool,
|
||||
) -> Arc<Galley> {
|
||||
self.layout_internal(fonts, job, pixels_per_point, allow_split_paragraphs)
|
||||
@@ -1201,11 +1201,19 @@ mod tests {
|
||||
job.halign = halign;
|
||||
job.justify = justify;
|
||||
|
||||
let whole =
|
||||
GalleyCache::default().layout(&mut fonts, job.clone(), 1., false);
|
||||
let whole = GalleyCache::default().layout(
|
||||
&mut fonts,
|
||||
pixels_per_point,
|
||||
job.clone(),
|
||||
false,
|
||||
);
|
||||
|
||||
let split =
|
||||
GalleyCache::default().layout(&mut fonts, job.clone(), 1., true);
|
||||
let split = GalleyCache::default().layout(
|
||||
&mut fonts,
|
||||
pixels_per_point,
|
||||
job.clone(),
|
||||
true,
|
||||
);
|
||||
|
||||
for (i, row) in whole.rows.iter().enumerate() {
|
||||
println!(
|
||||
@@ -1257,12 +1265,12 @@ mod tests {
|
||||
job.round_output_to_gui = round_output_to_gui;
|
||||
|
||||
let galley_wrapped =
|
||||
layout(&mut fonts, job.clone().into(), pixels_per_point);
|
||||
layout(&mut fonts, pixels_per_point, job.clone().into());
|
||||
|
||||
job.wrap = TextWrapping::no_max_width();
|
||||
|
||||
let text = job.text.clone();
|
||||
let galley_unwrapped = layout(&mut fonts, job.into(), pixels_per_point);
|
||||
let galley_unwrapped = layout(&mut fonts, pixels_per_point, job.into());
|
||||
|
||||
let intrinsic_size = galley_wrapped.intrinsic_size();
|
||||
let unwrapped_size = galley_unwrapped.size();
|
||||
|
||||
@@ -68,7 +68,7 @@ impl Paragraph {
|
||||
///
|
||||
/// In most cases you should use [`crate::FontsView::layout_job`] instead
|
||||
/// since that memoizes the input, making subsequent layouting of the same text much faster.
|
||||
pub fn layout(fonts: &mut FontsImpl, job: Arc<LayoutJob>, pixels_per_point: f32) -> Galley {
|
||||
pub fn layout(fonts: &mut FontsImpl, pixels_per_point: f32, job: Arc<LayoutJob>) -> Galley {
|
||||
profiling::function_scope!();
|
||||
|
||||
if job.wrap.max_rows == 0 {
|
||||
@@ -92,8 +92,8 @@ pub fn layout(fonts: &mut FontsImpl, job: Arc<LayoutJob>, pixels_per_point: f32)
|
||||
for (section_index, section) in job.sections.iter().enumerate() {
|
||||
layout_section(
|
||||
fonts,
|
||||
&job,
|
||||
pixels_per_point,
|
||||
&job,
|
||||
section_index as u32,
|
||||
section,
|
||||
&mut paragraphs,
|
||||
@@ -109,7 +109,7 @@ pub fn layout(fonts: &mut FontsImpl, job: Arc<LayoutJob>, pixels_per_point: f32)
|
||||
if elided {
|
||||
if let Some(last_placed) = rows.last_mut() {
|
||||
let last_row = Arc::make_mut(&mut last_placed.row);
|
||||
replace_last_glyph_with_overflow_character(fonts, &job, last_row, pixels_per_point);
|
||||
replace_last_glyph_with_overflow_character(fonts, pixels_per_point, &job, last_row);
|
||||
if let Some(last) = last_row.glyphs.last() {
|
||||
last_row.size.x = last.max_x();
|
||||
}
|
||||
@@ -140,8 +140,8 @@ pub fn layout(fonts: &mut FontsImpl, job: Arc<LayoutJob>, pixels_per_point: f32)
|
||||
// Ignores the Y coordinate.
|
||||
fn layout_section(
|
||||
fonts: &mut FontsImpl,
|
||||
job: &LayoutJob,
|
||||
pixels_per_point: f32,
|
||||
job: &LayoutJob,
|
||||
section_index: u32,
|
||||
section: &LayoutSection,
|
||||
out_paragraphs: &mut Vec<Paragraph>,
|
||||
@@ -412,9 +412,9 @@ fn line_break(
|
||||
/// Called before we have any Y coordinates.
|
||||
fn replace_last_glyph_with_overflow_character(
|
||||
fonts: &mut FontsImpl,
|
||||
pixels_per_point: f32,
|
||||
job: &LayoutJob,
|
||||
row: &mut Row,
|
||||
pixels_per_point: f32,
|
||||
) {
|
||||
fn row_width(row: &Row) -> f32 {
|
||||
if let (Some(first), Some(last)) = (row.glyphs.first(), row.glyphs.last()) {
|
||||
@@ -1122,6 +1122,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_zero_max_width() {
|
||||
let pixels_per_point = 1.0;
|
||||
let mut fonts = FontsImpl::new(
|
||||
1024,
|
||||
AlphaFromCoverage::default(),
|
||||
@@ -1129,7 +1130,7 @@ mod tests {
|
||||
);
|
||||
let mut layout_job = LayoutJob::single_section("W".into(), TextFormat::default());
|
||||
layout_job.wrap.max_width = 0.0;
|
||||
let galley = layout(&mut fonts, layout_job.into(), 1.0);
|
||||
let galley = layout(&mut fonts, pixels_per_point, layout_job.into());
|
||||
assert_eq!(galley.rows.len(), 1);
|
||||
}
|
||||
|
||||
@@ -1137,6 +1138,8 @@ mod tests {
|
||||
fn test_truncate_with_newline() {
|
||||
// No matter where we wrap, we should be appending the newline character.
|
||||
|
||||
let pixels_per_point = 1.0;
|
||||
|
||||
let mut fonts = FontsImpl::new(
|
||||
1024,
|
||||
AlphaFromCoverage::default(),
|
||||
@@ -1156,7 +1159,7 @@ mod tests {
|
||||
layout_job.wrap.max_rows = 1;
|
||||
layout_job.wrap.break_anywhere = break_anywhere;
|
||||
|
||||
let galley = layout(&mut fonts, layout_job.into(), 1.0);
|
||||
let galley = layout(&mut fonts, pixels_per_point, layout_job.into());
|
||||
|
||||
assert!(galley.elided);
|
||||
assert_eq!(galley.rows.len(), 1);
|
||||
@@ -1175,7 +1178,7 @@ mod tests {
|
||||
layout_job.wrap.max_rows = 1;
|
||||
layout_job.wrap.break_anywhere = false;
|
||||
|
||||
let galley = layout(&mut fonts, layout_job.into(), 1.0);
|
||||
let galley = layout(&mut fonts, pixels_per_point, layout_job.into());
|
||||
|
||||
assert!(galley.elided);
|
||||
assert_eq!(galley.rows.len(), 1);
|
||||
@@ -1186,6 +1189,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_cjk() {
|
||||
let pixels_per_point = 1.0;
|
||||
let mut fonts = FontsImpl::new(
|
||||
1024,
|
||||
AlphaFromCoverage::default(),
|
||||
@@ -1196,7 +1200,7 @@ mod tests {
|
||||
TextFormat::default(),
|
||||
);
|
||||
layout_job.wrap.max_width = 90.0;
|
||||
let galley = layout(&mut fonts, layout_job.into(), 1.0);
|
||||
let galley = layout(&mut fonts, pixels_per_point, layout_job.into());
|
||||
assert_eq!(
|
||||
galley.rows.iter().map(|row| row.text()).collect::<Vec<_>>(),
|
||||
vec!["日本語と", "Englishの混在", "した文章"]
|
||||
@@ -1205,6 +1209,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_pre_cjk() {
|
||||
let pixels_per_point = 1.0;
|
||||
let mut fonts = FontsImpl::new(
|
||||
1024,
|
||||
AlphaFromCoverage::default(),
|
||||
@@ -1215,7 +1220,7 @@ mod tests {
|
||||
TextFormat::default(),
|
||||
);
|
||||
layout_job.wrap.max_width = 110.0;
|
||||
let galley = layout(&mut fonts, layout_job.into(), 1.0);
|
||||
let galley = layout(&mut fonts, pixels_per_point, layout_job.into());
|
||||
assert_eq!(
|
||||
galley.rows.iter().map(|row| row.text()).collect::<Vec<_>>(),
|
||||
vec!["日本語とEnglish", "の混在した文章"]
|
||||
@@ -1224,6 +1229,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_truncate_width() {
|
||||
let pixels_per_point = 1.0;
|
||||
let mut fonts = FontsImpl::new(
|
||||
1024,
|
||||
AlphaFromCoverage::default(),
|
||||
@@ -1234,7 +1240,7 @@ mod tests {
|
||||
layout_job.wrap.max_width = f32::INFINITY;
|
||||
layout_job.wrap.max_rows = 1;
|
||||
layout_job.round_output_to_gui = false;
|
||||
let galley = layout(&mut fonts, layout_job.into(), 1.0);
|
||||
let galley = layout(&mut fonts, pixels_per_point, layout_job.into());
|
||||
assert!(galley.elided);
|
||||
assert_eq!(
|
||||
galley.rows.iter().map(|row| row.text()).collect::<Vec<_>>(),
|
||||
@@ -1247,6 +1253,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_empty_row() {
|
||||
let pixels_per_point = 1.0;
|
||||
let mut fonts = FontsImpl::new(
|
||||
1024,
|
||||
AlphaFromCoverage::default(),
|
||||
@@ -1258,7 +1265,7 @@ mod tests {
|
||||
|
||||
let job = LayoutJob::simple(String::new(), font_id, Color32::WHITE, f32::INFINITY);
|
||||
|
||||
let galley = layout(&mut fonts, job.into(), 1.0);
|
||||
let galley = layout(&mut fonts, pixels_per_point, job.into());
|
||||
|
||||
assert_eq!(galley.rows.len(), 1, "Expected one row");
|
||||
assert_eq!(
|
||||
@@ -1280,6 +1287,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_end_with_newline() {
|
||||
let pixels_per_point = 1.0;
|
||||
let mut fonts = FontsImpl::new(
|
||||
1024,
|
||||
AlphaFromCoverage::default(),
|
||||
@@ -1291,7 +1299,7 @@ mod tests {
|
||||
|
||||
let job = LayoutJob::simple("Hi!\n".to_owned(), font_id, Color32::WHITE, f32::INFINITY);
|
||||
|
||||
let galley = layout(&mut fonts, job.into(), 1.0);
|
||||
let galley = layout(&mut fonts, pixels_per_point, job.into());
|
||||
|
||||
assert_eq!(galley.rows.len(), 2, "Expected two rows");
|
||||
assert_eq!(
|
||||
|
||||
Reference in New Issue
Block a user