From 89c5aeb01d1fd01236fbbf8ccbf54d577757c1bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hilmar=20G=C3=BAstafsson?= Date: Fri, 17 Jul 2020 09:59:11 +0200 Subject: [PATCH] draw: render cursor correctly in position 0 --- src/draw.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/draw.rs b/src/draw.rs index 5e19d27..56d2d2f 100644 --- a/src/draw.rs +++ b/src/draw.rs @@ -150,13 +150,17 @@ impl<'a> Font<'a> { off = glyph.origin.1 } } + + let height = buf.get_bounds().3; for (i, glyph) in glyphs.iter().enumerate() { - glyph.draw(buf, (x_off, -off), bg, c); - x_off += glyph.dimensions.0 as i32 + glyph.origin.0; - if i + 1 == cursor { - let height = buf.get_bounds().3; + if i == cursor { self.draw_cursor(buf, c, x_off as u32, height)?; } + glyph.draw(buf, (x_off, -off), bg, c); + x_off += glyph.dimensions.0 as i32 + glyph.origin.0; + } + if cursor == glyphs.len() { + self.draw_cursor(buf, c, x_off as u32, height)?; } Ok((x_off as u32, self.size as u32))