Centering a text in a clip from JS

HowToRecenterTextInClip.wick (2.2 KB)

Hi,
Is it possible to recenter a text in a clip after dynamically changing it via JS?
Please see the attached wick file. Visually, it merely looks like this:
image
It has a clip (myClip) that has a background, defining the background color, and a text (myText).
Initially, the text is well centered: OriginX and OriginY are set to 0 manually.
The text will be changed dynamically from Javascript. Then, if longer or shorter, it will get de-centered.

A sample code is provided in the Code layer.

I thought I would just need to reset originX and originY to 0 to recenter the text.
But from Javascript, .originX and .originY are undefined.
Since I have access to myClip.myText.x, I then thought a workaround could be to reposition it based on the text width:

myClip.myText.x = -myClip.myText.width/2

But .width is also undefined.

Any way to recenter the text?

Thank you.

There isn’t a Wick.Path.prototype.width, but there is a Wick.Path.prototype.bounds:

Thank you for the link.
path.bounds.width correctly returns the width, good to know! :+1:
However, unfortunately, it didn’t help for the text centering, as the attached .wick shows.

CenterTextKO.wick (2.4 KB)

Here is a screenshot:

image

Clicking on the ‘Execute Code’ button will execute the three lines under it, with the following result:

image

The x coordinate has been correctly redefined, as the alert() message shows. But the problem is that the OriginX changed.

Anyway to reset the OriginX to 0?

Otherwise, which other way to recenter the text?

Thank you.

Try using OriginX instead, X and OriginX position stuff is a weird thing.

Thank you for helping. Unfortunately,

bnComponent.OriginX = 0;

didn’t return any error, but hasn’t had any result either.
Maybe this is just not possible…