Add scroll bar
This commit is contained in:
parent
eef1f2407b
commit
bc97a1323a
1 changed files with 26 additions and 0 deletions
|
|
@ -6,6 +6,7 @@ use std::{
|
||||||
time::Instant,
|
time::Instant,
|
||||||
};
|
};
|
||||||
use text::{
|
use text::{
|
||||||
|
FontLineIndex,
|
||||||
FontSystem,
|
FontSystem,
|
||||||
TextAction,
|
TextAction,
|
||||||
TextCursor,
|
TextCursor,
|
||||||
|
|
@ -185,11 +186,18 @@ fn main() {
|
||||||
window.set(bg_color);
|
window.set(bg_color);
|
||||||
|
|
||||||
let mut line_y = line_height;
|
let mut line_y = line_height;
|
||||||
|
let mut start_line_opt = None;
|
||||||
|
let mut end_line = FontLineIndex::new(0);
|
||||||
for (line_i, line) in buffer.layout_lines().iter().skip(scroll as usize).enumerate() {
|
for (line_i, line) in buffer.layout_lines().iter().skip(scroll as usize).enumerate() {
|
||||||
if line_y >= window.height() as i32 {
|
if line_y >= window.height() as i32 {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
end_line = line.line_i;
|
||||||
|
if start_line_opt == None {
|
||||||
|
start_line_opt = Some(end_line);
|
||||||
|
}
|
||||||
|
|
||||||
if buffer.cursor.line == line_i + scroll as usize {
|
if buffer.cursor.line == line_i + scroll as usize {
|
||||||
if buffer.cursor.glyph >= line.glyphs.len() {
|
if buffer.cursor.glyph >= line.glyphs.len() {
|
||||||
let x = match line.glyphs.last() {
|
let x = match line.glyphs.last() {
|
||||||
|
|
@ -225,6 +233,24 @@ fn main() {
|
||||||
line_y += line_height;
|
line_y += line_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw scrollbar
|
||||||
|
{
|
||||||
|
let start_line = start_line_opt.unwrap_or(end_line);
|
||||||
|
let lines = buffer.text_lines().len();
|
||||||
|
println!("{},{}/{}", start_line.get(), end_line.get(), lines);
|
||||||
|
let start_y = (start_line.get() * window.height() as usize) / lines;
|
||||||
|
let end_y = (end_line.get() * 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)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
window.sync();
|
window.sync();
|
||||||
|
|
||||||
buffer.redraw = false;
|
buffer.redraw = false;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue