-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Controlled PanZoom component #119
Comments
We probably should have another simpler component that only handles the pan/zoom part and is controlled. |
Note This is a draft We should reuse as much as possible the existing code implemented for the other components, and if needed refactor it to make it more reusable across components. I understand that it might not be easy to navigate the existing code. Please feel completely free to ask questions while implementing this. The current code has to following model for computing transformations. I came up with the terminology now so I haven't really used it in the code. But hope it can be hopeful to have a good mental model:
API I'm proposing: const [transform, setTransform] = useState({scale: 1, translation: [0, 0]});
<PanZoom
// The PanZoom component is basically a div around the target image which style
// can be customized to fit into any particular layout outside of it.
style={{}}
className=""
transform={transform}
resizeStrategy="contain"
onDoubleClick={(event, helpers) => {
// Reset zoom level
setTransform({scale: 1, translation: [0, 0]});
// idea of cool feature:
// helpers.getPosition(event, 'image');
// With image segmentation, zoom on an object automatically
}}
onPanMove={(event, helpers) => {
// Called when moving the mouse during a click -> move -> release action
setTransform(transform => helpers.applyMovement(event, transform));
}}
onMouseWheel={(event, helpers) => {
// If you need it you can get data about where the event happened
const {x, y} = helpers.getPosition(event, 'image');
// User controls when it should `event.preventDefault` to disable regular scrolling
// And if zoom should happen only when `alt` key is pressed for example
const zoomFactor = event.deltaY > 0 ? 1.2 ? 1 / 1.2;
// Get the transform needed
setTransform(transform => helpers.applyZoomTowardsCenter(zoomFactor, transform));
}}
>
<TargetImage src="" />
</PanZoom> It's could maybe be useful if helper methods can return coordinate information in different coordinate systems as defined above: Other feature to consider later and questions:
|
To do this we need:
Ref: zakodium-oss/pixelium#80
The text was updated successfully, but these errors were encountered: