Skip to content
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

[Feature][Transformer] Ability to hook into transformer operations #64

Open
Thanzex opened this issue May 22, 2022 · 2 comments
Open

[Feature][Transformer] Ability to hook into transformer operations #64

Thanzex opened this issue May 22, 2022 · 2 comments

Comments

@Thanzex
Copy link

Thanzex commented May 22, 2022

Hi again!
I will refer to movement/scale/rotation/skew as operations for brevity.

As of right now, the Transformer handles all inputs and operations by itself, but it would be nice to be able to handle some more interesting cases. Here are the main options i'm missing, forgive me if they are already present and I simply did not find them.

  1. Getting the group transformations.
    As far as I can tell right now Transformer handles all the input and directly applies the operation to the group members, it would be useful to have a way to get the applied transformations.
  2. Setting the group transformations.
    Since Transformer applies its changes directly to the target objects, it does not expose a way to easily set any parameter from the outside.
    This could be very useful in cases in which thanks to (1) we save somewhere the operations we performed to a group and then retrieve and set those same operations to a new Transformer, without having wokny wireframes.
  3. Being able to hook inside the transform process.

It would be very useful to have a callback after the changes are computed but before the actual transform is performed, to be able to handle some more interesting logic.

Some use cases that would be enabled are:

  • Being able to add some constraints to the operations, for example forcing the group to be inside some bounds.
  • Being able to smooth out the interaction, say with a library like React Spring.
  • Being able to have movement and scaling snapping, as right now only rotation and skew are enabled.

Ideally, one such callback would take as input the delta of the current frame and the delta since the beginning of the event and be able to make any change to the operation.
Please excuse the very crude example.

interface IScale {
    x: number
    y: number
}

interface IDelta {
    x: number
    y: number
    scale: IScale
    angle: number
}

interface IChangeCallback {
    operation: string
    frame: IDelta
    total: IDelta
}

type IChangeCallbackFunc = (IChangeCallback) => IChangeCallback;

Let me know what you think about it

@ShukantPal
Copy link
Owner

Hi @Thanzex, I would suggest you override prependTransform:

private prependTransform(delta: Matrix, skipUpdate = false): void

It emits a transformchange event already but if you want to change the applied transform itself, you would need to override it. Let me know if you need additional consulting services.

@rougsig
Copy link
Contributor

rougsig commented Sep 19, 2023

But prependTransform it private

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants