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 {
|
MouseEvent::WheelScrolled { delta } => match delta {
|
||||||
ScrollDelta::Lines { x, y } => {
|
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::Captured
|
||||||
},
|
},
|
||||||
_ => Status::Ignored,
|
_ => Status::Ignored,
|
||||||
|
|
|
||||||
|
|
@ -227,7 +227,9 @@ fn main() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
EventOption::Scroll(event) => {
|
EventOption::Scroll(event) => {
|
||||||
buffer.action(TextAction::Scroll(-event.y * 3));
|
buffer.action(TextAction::Scroll {
|
||||||
|
lines: -event.y * 3,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
EventOption::Quit(_) => return,
|
EventOption::Quit(_) => return,
|
||||||
_ => (),
|
_ => (),
|
||||||
|
|
|
||||||
|
|
@ -9,17 +9,28 @@ use crate::{FontLayoutLine, FontMatches, FontShapeLine};
|
||||||
/// An action to perform on a [TextBuffer]
|
/// An action to perform on a [TextBuffer]
|
||||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||||
pub enum TextAction {
|
pub enum TextAction {
|
||||||
|
/// Move cursor left
|
||||||
Left,
|
Left,
|
||||||
|
/// Move cursor right
|
||||||
Right,
|
Right,
|
||||||
|
/// Move cursor up
|
||||||
Up,
|
Up,
|
||||||
|
/// Move cursor down
|
||||||
Down,
|
Down,
|
||||||
|
/// Delete text behind cursor
|
||||||
Backspace,
|
Backspace,
|
||||||
|
/// Delete text in front of cursor
|
||||||
Delete,
|
Delete,
|
||||||
|
/// Scroll up one page
|
||||||
PageUp,
|
PageUp,
|
||||||
|
/// Scroll down one page
|
||||||
PageDown,
|
PageDown,
|
||||||
|
/// Insert character at cursor
|
||||||
Insert(char),
|
Insert(char),
|
||||||
|
/// Mouse click at specified position
|
||||||
Click { x: i32, y: i32 },
|
Click { x: i32, y: i32 },
|
||||||
Scroll(i32),
|
/// Scroll specified number of lines
|
||||||
|
Scroll { lines: i32 },
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Current cursor location
|
/// Current cursor location
|
||||||
|
|
@ -87,7 +98,7 @@ pub struct TextBuffer<'a> {
|
||||||
width: i32,
|
width: i32,
|
||||||
height: i32,
|
height: i32,
|
||||||
scroll: i32,
|
scroll: i32,
|
||||||
pub cursor: TextCursor,
|
cursor: TextCursor,
|
||||||
pub redraw: bool,
|
pub redraw: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -220,6 +231,11 @@ impl<'a> TextBuffer<'a> {
|
||||||
log::debug!("relayout line {}: {:?}", line_i.get(), duration);
|
log::debug!("relayout line {}: {:?}", line_i.get(), duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the current cursor position
|
||||||
|
pub fn cursor(&self) -> TextCursor {
|
||||||
|
self.cursor
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the current [TextMetrics]
|
/// Get the current [TextMetrics]
|
||||||
pub fn metrics(&self) -> TextMetrics {
|
pub fn metrics(&self) -> TextMetrics {
|
||||||
self.metrics
|
self.metrics
|
||||||
|
|
@ -387,7 +403,7 @@ impl<'a> TextBuffer<'a> {
|
||||||
TextAction::Click { x, y } => {
|
TextAction::Click { x, y } => {
|
||||||
self.click(x, y);
|
self.click(x, y);
|
||||||
},
|
},
|
||||||
TextAction::Scroll(lines) => {
|
TextAction::Scroll { lines } => {
|
||||||
self.scroll += lines;
|
self.scroll += lines;
|
||||||
self.redraw = true;
|
self.redraw = true;
|
||||||
self.shape_until_scroll();
|
self.shape_until_scroll();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue