mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-24 13:18:11 +08:00
Add 'Zoom with Scroll' input navigation scheme to preferences (#1021)
* Add use_scroll_as_zoom field to preference handler
* Add {Create,Delete}Mapping variants to message
* Revert "Add {Create,Delete}Mapping variants to message"
This reverts commit 0ba74754c9fb0c78d0b590c96e1d4fe2cfdd13e7.
* Revert "Add use_scroll_as_zoom field to preference handler"
This reverts commit d30f7c9edfa6d6e156939ca07f4db81f288975fd.
* Add basic scroll_as_zoom mapping
* Create overengineered mapping patch abstraction
* Add (for now passthrough) input layout manager
* Actually handle ModifyLayout messages (untested)
* Add backend preferences <-> layout manager comms
* Add scroll-as-zoom to actual preferences UI
* Rename LayoutManager -> KeyMapping
* Add Input section to preferences and title case
* Add scrollAsZoom frontend handling code (untested)
* Handle frontend <-> preferences comms
* (broken) Move scrollAsZoom persistence into state
* Fix scrollAsZoom having no effect on node graph
* Remove debugging helpers
* Fix confusion between horizontal and vertical
* Rename feature
* Move new message handler into folder
---------
Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
committed by
Keavon Chambers
co-authored by
Keavon Chambers
parent
c2234ce3fe
commit
7a52e50a94
@@ -1,4 +1,5 @@
|
||||
use crate::consts::{BIG_NUDGE_AMOUNT, NUDGE_AMOUNT};
|
||||
use crate::messages::input_mapper::key_mapping::MappingVariant;
|
||||
use crate::messages::input_mapper::utility_types::input_keyboard::{Key, KeyStates};
|
||||
use crate::messages::input_mapper::utility_types::macros::*;
|
||||
use crate::messages::input_mapper::utility_types::misc::MappingEntry;
|
||||
@@ -8,6 +9,15 @@ use crate::messages::prelude::*;
|
||||
|
||||
use glam::DVec2;
|
||||
|
||||
impl From<MappingVariant> for Mapping {
|
||||
fn from(value: MappingVariant) -> Self {
|
||||
match value {
|
||||
MappingVariant::Default => default_mapping(),
|
||||
MappingVariant::ZoomWithScroll => zoom_with_scroll(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn default_mapping() -> Mapping {
|
||||
use InputMapperMessage::*;
|
||||
use Key::*;
|
||||
@@ -337,3 +347,40 @@ pub fn default_mapping() -> Mapping {
|
||||
pointer_move,
|
||||
}
|
||||
}
|
||||
|
||||
/// Defaults except that scrolling without modifiers is bound to zooming instead of vertical panning
|
||||
pub fn zoom_with_scroll() -> Mapping {
|
||||
// TODO(multisn8): for other keymaps this patterns might be useful
|
||||
use InputMapperMessage::*;
|
||||
|
||||
let mut mapping = default_mapping();
|
||||
|
||||
let remove = [
|
||||
entry!(WheelScroll; modifiers=[Control], action_dispatch=NavigationMessage::WheelCanvasZoom),
|
||||
entry!(WheelScroll; modifiers=[Shift], action_dispatch=NavigationMessage::WheelCanvasTranslate { use_y_as_x: true }),
|
||||
entry!(WheelScroll; action_dispatch=NavigationMessage::WheelCanvasTranslate { use_y_as_x: false }),
|
||||
];
|
||||
let add = [
|
||||
entry!(WheelScroll; modifiers=[Control], action_dispatch=NavigationMessage::WheelCanvasTranslate { use_y_as_x: true }),
|
||||
entry!(WheelScroll; modifiers=[Shift], action_dispatch=NavigationMessage::WheelCanvasTranslate { use_y_as_x: false }),
|
||||
entry!(WheelScroll; action_dispatch=NavigationMessage::WheelCanvasZoom),
|
||||
];
|
||||
|
||||
apply_mapping_patch(&mut mapping, remove, add);
|
||||
|
||||
mapping
|
||||
}
|
||||
|
||||
fn apply_mapping_patch<'a, const N: usize, const M: usize, const X: usize, const Y: usize>(
|
||||
mapping: &mut Mapping,
|
||||
remove: impl IntoIterator<Item = &'a [&'a [MappingEntry; N]; M]>,
|
||||
add: impl IntoIterator<Item = &'a [&'a [MappingEntry; X]; Y]>,
|
||||
) {
|
||||
for entry in remove.into_iter().flat_map(|inner| inner.iter()).flat_map(|inner| inner.iter()) {
|
||||
mapping.remove(entry);
|
||||
}
|
||||
|
||||
for entry in add.into_iter().flat_map(|inner| inner.iter()).flat_map(|inner| inner.iter()) {
|
||||
mapping.add(entry.clone());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user