diff --git a/egui/src/introspection.rs b/egui/src/introspection.rs index 5f06f183..d1da680b 100644 --- a/egui/src/introspection.rs +++ b/egui/src/introspection.rs @@ -136,6 +136,7 @@ impl Widget for &mut epaint::TessellationOptions { aa_size: _, anti_alias, coarse_tessellation_culling, + round_text_to_pixels, debug_paint_clip_rects, debug_paint_text_rects, debug_ignore_clip_rects, @@ -147,6 +148,9 @@ impl Widget for &mut epaint::TessellationOptions { coarse_tessellation_culling, "Do coarse culling in the tessellator", ); + ui.checkbox(round_text_to_pixels, "Align text positions to pixel grid") + .on_hover_text("Most text already is, so don't expect to see a large change."); + ui.checkbox(debug_ignore_clip_rects, "Ignore clip rectangles"); ui.checkbox(debug_paint_clip_rects, "Paint clip rectangles"); ui.checkbox(debug_paint_text_rects, "Paint text bounds"); diff --git a/epaint/src/tessellator.rs b/epaint/src/tessellator.rs index da06d879..207896de 100644 --- a/epaint/src/tessellator.rs +++ b/epaint/src/tessellator.rs @@ -274,6 +274,10 @@ pub struct TessellationOptions { /// This likely makes pub coarse_tessellation_culling: bool, + /// If `true` (default) align text to mesh grid. + /// This makes the text sharper on most platforms. + pub round_text_to_pixels: bool, + /// Output the clip rectangles to be painted. pub debug_paint_clip_rects: bool, @@ -291,6 +295,7 @@ impl Default for TessellationOptions { aa_size: 1.0, anti_alias: true, coarse_tessellation_culling: true, + round_text_to_pixels: true, debug_paint_text_rects: false, debug_paint_clip_rects: false, debug_ignore_clip_rects: false, @@ -311,7 +316,11 @@ impl TessellationOptions { impl TessellationOptions { #[inline(always)] pub fn round_to_pixel(&self, point: f32) -> f32 { - (point * self.pixels_per_point).round() / self.pixels_per_point + if self.round_text_to_pixels { + (point * self.pixels_per_point).round() / self.pixels_per_point + } else { + point + } } }