mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 04:40:03 -04:00
Simplify layout_section
This commit is contained in:
@@ -114,15 +114,21 @@ pub fn layout(fonts: &mut FontsImpl, pixels_per_point: f32, job: Arc<LayoutJob>)
|
|||||||
// For most of this we ignore the y coordinate:
|
// For most of this we ignore the y coordinate:
|
||||||
|
|
||||||
let mut paragraphs = vec![Paragraph::from_section_index(0)];
|
let mut paragraphs = vec![Paragraph::from_section_index(0)];
|
||||||
for (section_index, section) in job.sections.iter().enumerate() {
|
{
|
||||||
layout_section(
|
let mut shape_buffer = fonts.take_shape_buffer();
|
||||||
fonts,
|
for (section_index, section) in job.sections.iter().enumerate() {
|
||||||
pixels_per_point,
|
let mut font = fonts.font(§ion.format.font_id.family);
|
||||||
&job,
|
shape_buffer = layout_section(
|
||||||
section_index as u32,
|
&mut font,
|
||||||
section,
|
shape_buffer,
|
||||||
&mut paragraphs,
|
pixels_per_point,
|
||||||
);
|
&job,
|
||||||
|
section_index as u32,
|
||||||
|
section,
|
||||||
|
&mut paragraphs,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
fonts.return_shape_buffer(shape_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
let point_scale = PointScale::new(pixels_per_point);
|
let point_scale = PointScale::new(pixels_per_point);
|
||||||
@@ -304,22 +310,22 @@ fn layout_shaped_run(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ignores the Y coordinate.
|
// Ignores the Y coordinate.
|
||||||
|
#[must_use]
|
||||||
fn layout_section(
|
fn layout_section(
|
||||||
fonts: &mut FontsImpl,
|
font: &mut Font<'_>,
|
||||||
|
mut shape_buffer: harfrust::UnicodeBuffer,
|
||||||
pixels_per_point: f32,
|
pixels_per_point: f32,
|
||||||
job: &LayoutJob,
|
job: &LayoutJob,
|
||||||
section_index: u32,
|
section_index: u32,
|
||||||
section: &LayoutSection,
|
section: &LayoutSection,
|
||||||
out_paragraphs: &mut Vec<Paragraph>,
|
out_paragraphs: &mut Vec<Paragraph>,
|
||||||
) {
|
) -> harfrust::UnicodeBuffer {
|
||||||
let LayoutSection {
|
let LayoutSection {
|
||||||
leading_space,
|
leading_space,
|
||||||
byte_range,
|
byte_range,
|
||||||
format,
|
format,
|
||||||
} = section;
|
} = section;
|
||||||
|
|
||||||
let mut shape_buffer = fonts.take_shape_buffer();
|
|
||||||
let mut font = fonts.font(&format.font_id.family);
|
|
||||||
let font_size = format.font_id.size;
|
let font_size = format.font_id.size;
|
||||||
let font_metrics = font.styled_metrics(pixels_per_point, font_size, &format.coords);
|
let font_metrics = font.styled_metrics(pixels_per_point, font_size, &format.coords);
|
||||||
let line_height = section
|
let line_height = section
|
||||||
@@ -360,7 +366,7 @@ fn layout_section(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
segment_into_runs(&mut font, segment, &mut runs);
|
segment_into_runs(font, segment, &mut runs);
|
||||||
|
|
||||||
let num_runs = runs.len();
|
let num_runs = runs.len();
|
||||||
for (run_idx, run) in runs.iter().enumerate() {
|
for (run_idx, run) in runs.iter().enumerate() {
|
||||||
@@ -384,7 +390,7 @@ fn layout_section(
|
|||||||
let glyph_buffer = shape_text(font_face, run_text, &format.coords, shape_buffer, flags);
|
let glyph_buffer = shape_text(font_face, run_text, &format.coords, shape_buffer, flags);
|
||||||
|
|
||||||
layout_shaped_run(
|
layout_shaped_run(
|
||||||
&mut font,
|
font,
|
||||||
run,
|
run,
|
||||||
run_text,
|
run_text,
|
||||||
&glyph_buffer,
|
&glyph_buffer,
|
||||||
@@ -397,10 +403,7 @@ fn layout_section(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Drop `font` to release the mutable borrow on `fonts` before recycling the buffer.
|
shape_buffer
|
||||||
#[expect(clippy::drop_non_drop)]
|
|
||||||
drop(font);
|
|
||||||
fonts.return_shape_buffer(shape_buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterator that either splits on `'\n'` or yields the whole string once.
|
/// Iterator that either splits on `'\n'` or yields the whole string once.
|
||||||
|
|||||||
Reference in New Issue
Block a user