Skip to content

Commit

Permalink
improve global keyboard nav
Browse files Browse the repository at this point in the history
  • Loading branch information
flxzt committed Aug 19, 2023
1 parent 4875653 commit ff89fb7
Showing 1 changed file with 34 additions and 10 deletions.
44 changes: 34 additions & 10 deletions crates/rnote-engine/src/pens/penholder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl PenHolder {

if !event_result.handled {
let (propagate, wf) = self.handle_event_global(event, now, engine_view);
event_result.propagate = propagate;
event_result.propagate |= propagate;
widget_flags |= wf;
}

Expand Down Expand Up @@ -271,33 +271,57 @@ impl PenHolder {
} => match keyboard_key {
KeyboardKey::NavUp => {
let y_offset = if modifier_keys.contains(&ModifierKey::KeyboardCtrl) {
engine_view.doc.format.height
-engine_view.camera.size()[1]
} else {
engine_view.doc.format.height * 0.5
-engine_view.camera.size()[1] * 0.5
};
widget_flags |= engine_view.camera.set_offset(
engine_view.camera.offset()
- na::vector![0.0, y_offset / engine_view.camera.total_zoom()],
engine_view.camera.offset() + na::vector![0.0, y_offset],
engine_view.doc,
);

EventPropagation::Stop
}
KeyboardKey::NavDown => {
let y_offset = if modifier_keys.contains(&ModifierKey::KeyboardCtrl) {
engine_view.doc.format.height
engine_view.camera.size()[1]
} else {
engine_view.doc.format.height * 0.5
engine_view.camera.size()[1] * 0.5
};
widget_flags |= engine_view.camera.set_offset(
engine_view.camera.offset()
+ na::vector![0.0, y_offset / engine_view.camera.total_zoom()],
engine_view.camera.offset() + na::vector![0.0, y_offset],
engine_view.doc,
);

EventPropagation::Stop
}
_ => EventPropagation::Stop,
KeyboardKey::NavLeft => {
let x_offset = if modifier_keys.contains(&ModifierKey::KeyboardCtrl) {
-engine_view.camera.size()[0]
} else {
-engine_view.camera.size()[0] * 0.5
};
widget_flags |= engine_view.camera.set_offset(
engine_view.camera.offset() + na::vector![x_offset, 0.0],
engine_view.doc,
);

EventPropagation::Stop
}
KeyboardKey::NavRight => {
let x_offset = if modifier_keys.contains(&ModifierKey::KeyboardCtrl) {
engine_view.camera.size()[0]
} else {
engine_view.camera.size()[0] * 0.5
};
widget_flags |= engine_view.camera.set_offset(
engine_view.camera.offset() + na::vector![x_offset, 0.0],
engine_view.doc,
);

EventPropagation::Stop
}
_ => EventPropagation::Proceed,
},
};

Expand Down

0 comments on commit ff89fb7

Please sign in to comment.