Skip to content

Commit

Permalink
Implement Scroll action in text::editor
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Sep 18, 2023
1 parent 36e867d commit 4e757a2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/src/text/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub enum Action {
Edit(Edit),
Click(Point),
Drag(Point),
Scroll { lines: i32 },
}

impl Action {
Expand Down
6 changes: 6 additions & 0 deletions graphics/src/text/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
12 changes: 12 additions & 0 deletions widget/src/text_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 4e757a2

Please sign in to comment.