From fab9c9464bba2a1b9419144afaf0bf9e810e925c Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 4 Oct 2022 21:32:26 -0600 Subject: [PATCH] More improvements for selection --- examples/text/src/main.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/examples/text/src/main.rs b/examples/text/src/main.rs index 08b0d1c3..c2c99bb0 100644 --- a/examples/text/src/main.rs +++ b/examples/text/src/main.rs @@ -521,20 +521,32 @@ fn main() { && mouse_y >= line_y - font_size && mouse_y < line_y - font_size + line_height { + cursor_line = line_i + scroll as usize; + cursor_glyph = line.glyphs.len(); for (glyph_i, glyph) in line.glyphs.iter().enumerate() { if mouse_x >= line_x + glyph.x as i32 && mouse_x <= line_x + (glyph.x + glyph.w) as i32 { - cursor_line = line_i + scroll as usize; cursor_glyph = glyph_i; } } } } else { if cursor_line == line_i + scroll as usize { - if ! line.glyphs.is_empty() { - let glyph_i = cmp::min(cursor_glyph, line.glyphs.len() - 1); - let glyph = &line.glyphs[glyph_i]; + if cursor_glyph >= line.glyphs.len() { + let x = match line.glyphs.last() { + Some(glyph) => glyph.x + glyph.w, + None => 0.0 + }; + window.rect( + line_x + x as i32, + line_y - font_size, + (font_size / 2) as u32, + line_height as u32, + Color::rgba(0xFF, 0xFF, 0xFF, 0x20) + ); + } else { + let glyph = &line.glyphs[cursor_glyph]; window.rect( line_x + glyph.x as i32, line_y - font_size,