More documentation
This commit is contained in:
parent
fa00813c0b
commit
405c77bb47
3 changed files with 25 additions and 5 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
_ => (),
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue