Implement Scroll action in text::editor

This commit is contained in:
Héctor Ramón Jiménez 2023-09-19 01:18:06 +02:00
parent 36e867de69
commit 4e757a26d0
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
3 changed files with 19 additions and 0 deletions

View file

@ -52,6 +52,7 @@ pub enum Action {
Edit(Edit),
Click(Point),
Drag(Point),
Scroll { lines: i32 },
}
impl Action {

View file

@ -446,6 +446,12 @@ impl editor::Editor for Editor {
}
}
}
Action::Scroll { lines } => {
editor.action(
font_system.raw(),
cosmic_text::Action::Scroll { lines },
);
}
}
self.0 = Some(Arc::new(internal));

View file

@ -521,6 +521,18 @@ impl Update {
}
_ => None,
},
mouse::Event::WheelScrolled { delta } => {
action(Action::Scroll {
lines: match delta {
mouse::ScrollDelta::Lines { y, .. } => {
-y as i32 * 4
}
mouse::ScrollDelta::Pixels { y, .. } => {
-y.signum() as i32
}
},
})
}
_ => None,
},
Event::Keyboard(event) => match event {