From 69dfc9fe84e9c2214e01fbf5b0b89157c2291b82 Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Thu, 2 May 2024 22:59:34 -0400 Subject: [PATCH] Fix text legibility by rounding vertex positions (#151) Co-authored-by: Madeline Sparkles --- crates/yakui-core/src/paint/paint_dom.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/yakui-core/src/paint/paint_dom.rs b/crates/yakui-core/src/paint/paint_dom.rs index 1338657a..5a82b913 100644 --- a/crates/yakui-core/src/paint/paint_dom.rs +++ b/crates/yakui-core/src/paint/paint_dom.rs @@ -7,10 +7,11 @@ use crate::dom::Dom; use crate::geometry::Rect; use crate::id::{ManagedTextureId, WidgetId}; use crate::layout::LayoutDom; +use crate::paint::{PaintCall, Pipeline}; use crate::widget::PaintContext; use super::layers::PaintLayers; -use super::primitives::{PaintCall, PaintMesh, Vertex}; +use super::primitives::{PaintMesh, Vertex}; use super::texture::{Texture, TextureChange}; /// Contains all information about how to paint the current set of widgets. @@ -202,7 +203,18 @@ impl PaintDom { let vertices = mesh.vertices.into_iter().map(|mut vertex| { let mut pos = vertex.position * self.scale_factor; pos += self.unscaled_viewport.pos(); + + // Currently, we only round the vertices of geometry fed to the text + // pipeline because rounding all geometry causes hairline cracks in + // some geometry, like rounded rectangles. + // + // See: https://github.com/SecondHalfGames/yakui/issues/153 + if mesh.pipeline == Pipeline::Text { + pos = pos.round(); + } + pos /= self.surface_size; + vertex.position = pos; vertex });