summaryrefslogtreecommitdiffstats
path: root/widget/src
diff options
context:
space:
mode:
authorLibravatar Radovan Blažek <blazra@gmail.com>2023-11-17 16:52:26 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-02-03 14:14:50 +0100
commit79a348464e562d16e53552117631f591975a2855 (patch)
tree7e00eadcd76d0853e31fdc28ae09c14144411e61 /widget/src
parent358f004fa01d98af8c3ec80ed78d550f6a5f6df0 (diff)
downloadiced-79a348464e562d16e53552117631f591975a2855.tar.gz
iced-79a348464e562d16e53552117631f591975a2855.tar.bz2
iced-79a348464e562d16e53552117631f591975a2855.zip
Improve `TextEditor` slow scrolling behavior with touchpads.
If you scroll by only a fraction of a line, the TextEditor stores this fraction and adds it on the next scroll event.
Diffstat (limited to 'widget/src')
-rw-r--r--widget/src/text_editor.rs31
1 files changed, 17 insertions, 14 deletions
diff --git a/widget/src/text_editor.rs b/widget/src/text_editor.rs
index 354abceb..0d73e41b 100644
--- a/widget/src/text_editor.rs
+++ b/widget/src/text_editor.rs
@@ -289,6 +289,7 @@ struct State<Highlighter: text::Highlighter> {
is_focused: bool,
last_click: Option<mouse::Click>,
drag_click: Option<mouse::click::Kind>,
+ partial_scroll: f32,
highlighter: RefCell<Highlighter>,
highlighter_settings: Highlighter::Settings,
highlighter_format_address: usize,
@@ -310,6 +311,7 @@ where
is_focused: false,
last_click: None,
drag_click: None,
+ partial_scroll: 0.0,
highlighter: RefCell::new(Highlighter::new(
&self.highlighter_settings,
)),
@@ -404,6 +406,11 @@ where
shell.publish(on_edit(action));
}
+ Update::Scroll(mut lines) => {
+ lines += state.partial_scroll;
+ state.partial_scroll = lines.fract();
+ shell.publish(on_edit(Action::Scroll { lines: lines as i32 }))
+ }
Update::Unfocus => {
state.is_focused = false;
state.drag_click = None;
@@ -577,6 +584,7 @@ where
enum Update {
Click(mouse::Click),
+ Scroll(f32),
Unfocus,
Release,
Action(Action),
@@ -630,21 +638,16 @@ impl Update {
mouse::Event::WheelScrolled { delta }
if cursor.is_over(bounds) =>
{
- action(Action::Scroll {
- lines: match delta {
- mouse::ScrollDelta::Lines { y, .. } => {
- if y.abs() > 0.0 {
- (y.signum() * -(y.abs() * 4.0).max(1.0))
- as i32
- } else {
- 0
- }
- }
- mouse::ScrollDelta::Pixels { y, .. } => {
- (-y / 4.0) as i32
+ Some(Update::Scroll(match delta {
+ mouse::ScrollDelta::Lines { y, .. } => {
+ if y.abs() > 0.0 {
+ y.signum() * -(y.abs() * 4.0).max(1.0)
+ } else {
+ 0.0
}
- },
- })
+ }
+ mouse::ScrollDelta::Pixels { y, .. } => -y / 4.0,
+ }))
}
_ => None,
},