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

Dynamically update attributes #241

Open
outOFFspace opened this issue Aug 1, 2024 · 2 comments
Open

Dynamically update attributes #241

outOFFspace opened this issue Aug 1, 2024 · 2 comments

Comments

@outOFFspace
Copy link

outOFFspace commented Aug 1, 2024

How do we change the attributes of objects dynamically?
For example, I want to change the scaleX, scaleY:

<div class="flex gap-2">
<UInput v-model.number="selectedObject.scaleX" :min="0.5" inputClass="bg-[#2e3447] ps-16 text-[#bbbfd9] ring-none!important ring-transparent focus:ring-none">
<template #leading>
<span class="text-gray-500 dark:text-gray-400 text-xs">ScaleX:</span>
</template>
</UInput>
<UInput v-model.number="selectedObject.scaleY" :min="0.5" inputClass="bg-[#2e3447] ps-16 text-[#bbbfd9] ring-none!important ring-transparent focus:ring-none">
<template #leading>
<span class="text-gray-500 dark:text-gray-400 text-xs">ScaleY:</span>
</template>
</UInput>
</div>

Then I have a watcher:

watch: {
selectedObject: {
deep: true,
async handler(newAttrs: any) {
await nextTick();
if (newAttrs) {
const stage = this.$refs.stage.getStage();
const node = stage.findOne('.' + newAttrs.name);
if (node) {
node.setAttrs(newAttrs);
node.draw();
node.getLayer().batchDraw(); // Redraw the layer
}
}
}
}
},

But a component is redrawing only after I transform it manually.

I've tried to change the item config as well:

<v-stage
                  ref="stage"
                  :config="configStage"
                  @mousedown="handleStageMouseDown"
                  @touchstart="handleStageMouseDown">
                <v-layer ref="layer">
                  <component :key="item.config.name" :is="item.type" :config="item.config" v-for="item in canvas"/>
                  <v-transformer ref="transformer" />
                </v-layer>
              </v-stage>

But it only updates when the item is not transformed. So It might be the issue with the transformer.

@outOFFspace
Copy link
Author

outOFFspace commented Aug 1, 2024

The same issue is with rotation.
this.$refs.transformer.getNode().forceUpdate() helps only for width, and height changes.

@lavrton
Copy link
Member

lavrton commented Aug 4, 2024

Can you please make a small online demo of what you are trying? With codesandbox or something similar.

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

2 participants