From 16f0eb9efe2b1b2457237d175d54dd9b2e3b8065 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 27 Oct 2022 09:18:27 -0600 Subject: [PATCH] Re-add scrollbar to orbclient editor --- examples/editor-orbclient/src/main.rs | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/examples/editor-orbclient/src/main.rs b/examples/editor-orbclient/src/main.rs index 12c8a8a..78f1324 100644 --- a/examples/editor-orbclient/src/main.rs +++ b/examples/editor-orbclient/src/main.rs @@ -242,46 +242,31 @@ fn main() { window.rect(line_x + x, y, w, h, orbclient::Color { data: color.0 }) }); - /*TODO - let mut line_y = font_size; let mut start_line_opt = None; - let mut end_line = TextLineIndex::new(0); - for (line_i, line) in buffer - .layout_lines() - .iter() - .skip(buffer.scroll() as usize) - .take(buffer.lines() as usize) - .enumerate() - { - if line_y >= window.height() as i32 { - break; - } - - end_line = line.line_i; + let mut end_line = 0; + for run in buffer.layout_runs() { + end_line = run.line_i; if start_line_opt == None { start_line_opt = Some(end_line); } - - line_y += line_height; } // Draw scrollbar { let start_line = start_line_opt.unwrap_or(end_line); let lines = buffer.text_lines().len(); - let start_y = (start_line.get() * window.height() as usize) / lines; - let end_y = (end_line.get() * window.height() as usize) / lines; + let start_y = (start_line * window.height() as usize) / lines; + let end_y = (end_line * window.height() as usize) / lines; if end_y > start_y { window.rect( window.width() as i32 - line_x as i32, start_y as i32, line_x as u32, (end_y - start_y) as u32, - Color::rgba(0xFF, 0xFF, 0xFF, 0x40), + orbclient::Color::rgba(0xFF, 0xFF, 0xFF, 0x40), ); } } - */ window.sync();