1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-27 07:03:14 -04:00

Better naming + bug fix (wrong unit)

This commit is contained in:
Emil Ernerfeldt
2025-09-08 14:28:16 +02:00
parent 237d217fbb
commit 4e15f5306f
2 changed files with 13 additions and 11 deletions

View File

@@ -127,7 +127,7 @@ pub struct GlyphAllocation {
pub(crate) id: ab_glyph::GlyphId,
/// Unit: screen pixels.
pub advance_width: f32,
pub advance_width_px: f32,
/// UV rectangle for drawing.
pub uv_rect: UvRect,
@@ -427,7 +427,7 @@ impl FontImpl {
let allocation = GlyphAllocation {
id: glyph_id,
advance_width: glyph_info.advance_width_unscaled.0 * metrics.px_scale_factor,
advance_width_px: glyph_info.advance_width_unscaled.0 * metrics.px_scale_factor,
uv_rect,
};
entry.insert(allocation);
@@ -530,6 +530,8 @@ pub struct ScaledMetrics {
pub pixels_per_point: f32,
/// Scale factor, relative to the font's units per em (so, probably much less than 1).
///
/// Translates "unscaled" units to physical (screen) pixels.
pub px_scale_factor: f32,
/// Vertical offset, in UI points (not screen-space).

View File

@@ -49,7 +49,7 @@ impl PointScale {
#[derive(Clone)]
struct Paragraph {
/// Start of the next glyph to be added. In screen-space / physical pixels.
pub cursor_x: f32,
pub cursor_x_px: f32,
/// This is included in case there are no glyphs
pub section_index_at_start: u32,
@@ -63,7 +63,7 @@ struct Paragraph {
impl Paragraph {
pub fn from_section_index(section_index_at_start: u32) -> Self {
Self {
cursor_x: 0.0,
cursor_x_px: 0.0,
section_index_at_start,
glyphs: vec![],
empty_paragraph_height: 0.0,
@@ -172,7 +172,7 @@ fn layout_section(
paragraph.empty_paragraph_height = line_height; // TODO(emilk): replace this hack with actually including `\n` in the glyphs?
}
paragraph.cursor_x += leading_space * pixels_per_point;
paragraph.cursor_x_px += leading_space * pixels_per_point;
let mut last_glyph_id = None;
@@ -204,12 +204,12 @@ fn layout_section(
if let (Some(font_impl), Some(last_glyph_id), Some(glyph_id)) =
(&font_impl, last_glyph_id, glyph_info.id)
{
paragraph.cursor_x += font_impl.pair_kerning_screen_space(
paragraph.cursor_x_px += font_impl.pair_kerning_screen_space(
&font_impl_metrics,
last_glyph_id,
glyph_id,
);
paragraph.cursor_x += extra_letter_spacing * pixels_per_point;
paragraph.cursor_x_px += extra_letter_spacing * pixels_per_point;
}
let (glyph_alloc, physical_x) = match font_impl.as_mut() {
@@ -218,7 +218,7 @@ fn layout_section(
&font_impl_metrics,
glyph_info,
chr,
paragraph.cursor_x,
paragraph.cursor_x_px,
),
None => Default::default(),
};
@@ -226,7 +226,7 @@ fn layout_section(
paragraph.glyphs.push(Glyph {
chr,
pos: pos2(physical_x as f32 / pixels_per_point, f32::NAN),
advance_width: glyph_alloc.advance_width / pixels_per_point,
advance_width: glyph_alloc.advance_width_px / pixels_per_point,
line_height,
font_impl_height: font_impl_metrics.row_height,
font_impl_ascent: font_impl_metrics.ascent,
@@ -236,7 +236,7 @@ fn layout_section(
section_index,
});
paragraph.cursor_x += glyph_alloc.advance_width;
paragraph.cursor_x_px += glyph_alloc.advance_width_px;
last_glyph_id = Some(glyph_alloc.id);
}
}
@@ -528,7 +528,7 @@ fn replace_last_glyph_with_overflow_character(
row.glyphs.push(Glyph {
chr: overflow_character,
pos: pos2(physical_x as f32 / pixels_per_point, f32::NAN),
advance_width: replacement_glyph_alloc.advance_width,
advance_width: replacement_glyph_alloc.advance_width_px / pixels_per_point,
line_height,
font_impl_height: font_impl_metrics.row_height,
font_impl_ascent: font_impl_metrics.ascent,