diff --git a/crates/render/src/lib.rs b/crates/render/src/lib.rs index d0b1619..c437827 100644 --- a/crates/render/src/lib.rs +++ b/crates/render/src/lib.rs @@ -125,10 +125,13 @@ fn paint_borders(layout_box: &LayoutBox, list: &mut DisplayList) { fn paint_text(layout_box: &LayoutBox, list: &mut DisplayList) { for line in &layout_box.lines { - // Use per-fragment styling from the TextLine. let color = line.color; let font_size = line.font_size; + // Record index before pushing glyphs so we can insert the background + // before the text in painter's order. + let glyph_idx = list.len(); + list.push(PaintCommand::DrawGlyphs { line: line.clone(), font_size, @@ -150,12 +153,8 @@ fn paint_text(layout_box: &LayoutBox, list: &mut DisplayList) { // Draw inline background if not transparent. if line.background_color.a > 0 && line.width > 0.0 { - // Insert background before the text (painter's order). - // We add it at the end for simplicity; a real implementation - // would insert before the DrawGlyphs. - let bg_idx = list.len() - 1; // Index of the DrawGlyphs we just pushed. list.insert( - bg_idx, + glyph_idx, PaintCommand::FillRect { x: line.x, y: line.y,