Handle scroll in TextBuffer
This commit is contained in:
parent
c114fe19f3
commit
3e04ffdfa4
4 changed files with 129 additions and 61 deletions
|
|
@ -108,12 +108,13 @@ impl Application for Window {
|
|||
default_text.to_string()
|
||||
};
|
||||
|
||||
let line_x = 8;
|
||||
let buffer = Arc::new(RwLock::new(TextBuffer::new(
|
||||
unsafe { FONT_MATCHES.as_ref().unwrap() },
|
||||
&text,
|
||||
font_sizes[font_size_i].0,
|
||||
600 - line_x * 2,
|
||||
font_sizes[font_size_i].1,
|
||||
0,
|
||||
0
|
||||
)));
|
||||
|
||||
let window = Window {
|
||||
|
|
|
|||
|
|
@ -56,11 +56,7 @@ where
|
|||
{
|
||||
let mut buffer = self.buffer.write().unwrap();
|
||||
|
||||
let font_size = buffer.font_size();
|
||||
let line_height = font_size + 8;
|
||||
|
||||
buffer.set_line_width(size.width as i32);
|
||||
buffer.shape_until(size.height as i32 / line_height);
|
||||
buffer.set_size(size.width as i32, size.height as i32);
|
||||
}
|
||||
layout::Node::new(size)
|
||||
}
|
||||
|
|
@ -78,7 +74,6 @@ where
|
|||
let buffer = self.buffer.read().unwrap();
|
||||
let font_size = buffer.font_size();
|
||||
let line_height = font_size + 8; /*TODO: store somewhere else */
|
||||
let scroll = 0;
|
||||
|
||||
let instant = Instant::now();
|
||||
|
||||
|
|
@ -99,7 +94,7 @@ where
|
|||
for (line_i, line) in buffer
|
||||
.layout_lines()
|
||||
.iter()
|
||||
.skip(scroll as usize)
|
||||
.skip(buffer.scroll as usize)
|
||||
.enumerate()
|
||||
{
|
||||
if line_y >= (layout.bounds().y + layout.bounds().height) as i32 {
|
||||
|
|
@ -111,7 +106,7 @@ where
|
|||
start_line_opt = Some(end_line);
|
||||
}
|
||||
|
||||
if buffer.cursor.line == line_i + scroll as usize {
|
||||
if buffer.cursor.line == line_i + buffer.scroll as usize {
|
||||
if buffer.cursor.glyph >= line.glyphs.len() {
|
||||
let x = match line.glyphs.last() {
|
||||
Some(glyph) => glyph.x + glyph.w,
|
||||
|
|
@ -248,6 +243,14 @@ where
|
|||
buffer.action(TextAction::Delete);
|
||||
Status::Captured
|
||||
},
|
||||
KeyCode::PageUp => {
|
||||
buffer.action(TextAction::PageUp);
|
||||
Status::Captured
|
||||
},
|
||||
KeyCode::PageDown => {
|
||||
buffer.action(TextAction::PageDown);
|
||||
Status::Captured
|
||||
},
|
||||
_ => Status::Ignored,
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue