enso/app/gui2/mock/providers.ts
Kaz Wesley 614a5a610b
Zoom steps (#9327)
When zooming with Ctrl+wheel, used fixed-factor steps instead of scroll wheel rate information.

Fixes #9177.

Important Notes
  - Wheel events are distinguished from trackpad gestures, so that OS X pinch-zoom still works nicely.
  - When zooming with the mouse wheel, scale factor is rounded (geometrically) to the nearest power of √2, and then stepped up or down by the same factor; this ensures that round values like 100% are never skipped over.
  - Added directed-clamping logic, so that if the zoom is moved outside the clamping range of a zoom-method, it can be stepped back into range without jumping.
2024-03-08 13:33:54 -05:00

59 lines
1.6 KiB
TypeScript

import type { GraphSelection } from '@/providers/graphSelection'
import type { GraphNavigator } from '../src/providers/graphNavigator'
import { Rect } from '../src/util/data/rect'
import { Vec2 } from '../src/util/data/vec2'
export const graphNavigator: GraphNavigator = {
events: {} as any,
clientToScenePos: () => Vec2.Zero,
clientToSceneRect: () => Rect.Zero,
panAndZoomTo: () => {},
panTo: () => {},
stepZoom: () => {},
transform: '',
prescaledTransform: '',
translate: Vec2.Zero,
targetScale: 1,
scale: 1,
sceneMousePos: Vec2.Zero,
viewBox: '',
viewport: Rect.Zero,
}
export function graphNavigatorWith(modifications?: Partial<GraphNavigator>): GraphNavigator {
return Object.assign({}, graphNavigator, modifications)
}
export const graphSelection: GraphSelection = {
events: {} as any,
anchor: undefined,
deselectAll: () => {},
handleSelectionOf: () => {},
setSelection: () => {},
hoveredNode: undefined,
hoveredPort: undefined,
isSelected: () => false,
isChanging: false,
mouseHandler: () => false,
selectAll: () => {},
selected: new Set(),
}
export function graphSelectionWith(modifications?: Partial<GraphSelection>): GraphSelection {
return Object.assign({}, graphSelection, modifications)
}
export const all = {
'graph navigator': graphNavigator,
'graph selection': graphSelection,
}
export function allWith(
modifications: Partial<{ [K in keyof typeof all]: Partial<(typeof all)[K]> }>,
): typeof all {
return {
'graph navigator': graphNavigatorWith(modifications['graph navigator']),
'graph selection': graphSelectionWith(modifications['graph selection']),
}
}