More documentation

This commit is contained in:
Jeremy Soller 2022-10-19 08:34:34 -06:00
parent fa00813c0b
commit 405c77bb47
No known key found for this signature in database
GPG key ID: 87F211AF2BE4C2FE
3 changed files with 25 additions and 5 deletions

View file

@ -249,7 +249,9 @@ where
},
MouseEvent::WheelScrolled { delta } => match delta {
ScrollDelta::Lines { x, y } => {
buffer.action(TextAction::Scroll((-y * 6.0) as i32));
buffer.action(TextAction::Scroll {
lines: (-y * 6.0) as i32,
});
Status::Captured
},
_ => Status::Ignored,

View file

@ -227,7 +227,9 @@ fn main() {
);
}
EventOption::Scroll(event) => {
buffer.action(TextAction::Scroll(-event.y * 3));
buffer.action(TextAction::Scroll {
lines: -event.y * 3,
});
}
EventOption::Quit(_) => return,
_ => (),

View file

@ -9,17 +9,28 @@ use crate::{FontLayoutLine, FontMatches, FontShapeLine};
/// An action to perform on a [TextBuffer]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum TextAction {
/// Move cursor left
Left,
/// Move cursor right
Right,
/// Move cursor up
Up,
/// Move cursor down
Down,
/// Delete text behind cursor
Backspace,
/// Delete text in front of cursor
Delete,
/// Scroll up one page
PageUp,
/// Scroll down one page
PageDown,
/// Insert character at cursor
Insert(char),
/// Mouse click at specified position
Click { x: i32, y: i32 },
Scroll(i32),
/// Scroll specified number of lines
Scroll { lines: i32 },
}
/// Current cursor location
@ -87,7 +98,7 @@ pub struct TextBuffer<'a> {
width: i32,
height: i32,
scroll: i32,
pub cursor: TextCursor,
cursor: TextCursor,
pub redraw: bool,
}
@ -220,6 +231,11 @@ impl<'a> TextBuffer<'a> {
log::debug!("relayout line {}: {:?}", line_i.get(), duration);
}
/// Get the current cursor position
pub fn cursor(&self) -> TextCursor {
self.cursor
}
/// Get the current [TextMetrics]
pub fn metrics(&self) -> TextMetrics {
self.metrics
@ -387,7 +403,7 @@ impl<'a> TextBuffer<'a> {
TextAction::Click { x, y } => {
self.click(x, y);
},
TextAction::Scroll(lines) => {
TextAction::Scroll { lines } => {
self.scroll += lines;
self.redraw = true;
self.shape_until_scroll();