Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Animated dynamic textbox with rounded corners

New Here ,
May 14, 2021 May 14, 2021

Copy link to clipboard

Copied

Hi everybody,

i searched for a solution for this for a long time, but could not find any. All the tutorials i found used boxes without rounded corners.

 

I made a textbox with the sourceRectAtTime expression that dynamically fits to my text. This works fine. The box is a shape layer with rounded corners and the expression works on the Size property. Now i want to animate this box scaling up in width. If i use the scale property, the corner roundness gets weird, obviously. I know i could use a duplicate text layer with text animation as reference for the scale (i want to animate the visibile text differently than the box), but this seems a bit convoluted to me, there must be a better solution. Another option would be to subtract from the size with a slider, but then it would not be dynamic anmyore, since the text will sometimes be shorter or longer, so i need to animated my width in percentage value.

 

Does anyone have an idea?

 

Best regards,

Johannes

TOPICS
Expressions

Views

271

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , May 14, 2021 May 14, 2021
Could be as easy as simply adding a value driven by a slider and filtering it through a linear() expression to convert from percentages to absolute pixels based on the input value. Something like this: mSlider=thisComp.layer("XYZ").effect("Scale")("Slider"); mWidth=thisComp.layer("Text").sourceRectAtTime().width; mWidth+linear(mSlider,0,100,0,mWidth); Mylenium

Likes

Translate

Translate
Adobe Community Professional ,
May 14, 2021 May 14, 2021

Copy link to clipboard

Copied

Could be as easy as simply adding a value driven by a slider and filtering it through a linear() expression to convert from percentages to absolute pixels based on the input value. Something like this:

 

 

mSlider=thisComp.layer("XYZ").effect("Scale")("Slider");
mWidth=thisComp.layer("Text").sourceRectAtTime().width;

mWidth+linear(mSlider,0,100,0,mWidth);

 

 

Mylenium

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 14, 2021 May 14, 2021

Copy link to clipboard

Copied

@Mylenium 

I tried that but i can only make the textbox larger. 0 is the original text width.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 14, 2021 May 14, 2021

Copy link to clipboard

Copied

You will have to add some value somewhere, so I'm realyl not clear what you are hoping for. Of course the code can be modified and expanded in whatever ways you fancy. This is just the base line to start from. Anything more will require a better explanation on your part, as it's really difficult to picture in my head what you realyl want/ need. Perhaps a screenshot with comments?

 

Mylenium

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 14, 2021 May 14, 2021

Copy link to clipboard

Copied

I attached a screenshots of what i have so far.

Basically i want to animate the shape layer width from 0 to whatever the text width is. Without doing a text animation. And with keeping the Corner Roundness (thats why i can't animate the scale). And it needs to be dynamic.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 14, 2021 May 14, 2021

Copy link to clipboard

Copied

I'm still confused. The code you have is pretty much already doing what you want. You just need to not redundantly add the source layer width in the last line. This is as dynamic as it gets (in AE). The only further level of automation here would be to add code that replaces the slider animation with something based on time like starting with teh in-point and expanding for a given duration.

 

Mylenium

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 14, 2021 May 14, 2021

Copy link to clipboard

Copied

ah, i am so stupid. Of course i had to delete that unnecessary width.

thank you so much, it works now.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 14, 2021 May 14, 2021

Copy link to clipboard

Copied

LATEST

When you are building this kind of automated system you will save a lot of time if you try and compensate for more than just the size of the text area. All of my text Animation Presets link more than just one text layer property to the shape layer so that everything lines up automatically. I suggest you add a bit to your setup so that it at least compensates for baseline shift, paragraph style, and text layer scale. I have about 30 custom text presets and all of them automatically line things up so I only have to animate the text layer to get everything else to follow. All of the presets that generate backgrounds for text layers use index - 1 instead of layer lathe layer name so all you have to do is put the shape layer below the text layer and animate a couple of sliders.

 

If you add in sourceRectAtTime().top and sourceRectAtTime().top to the calculations for the shape layer rectangle you can compensate for the paragraph styles and baseline shift. You can also compensate for the scale of the text layer and even tie the position of the shape layer and the position of the text together so your text box will always line up perfectly with the text. You can also compensate for the scale of the text layer so anything you do to the text layer's position or scale will be reflected in the text box. My basic automatic text box also utilizes a stroke and fill for the shape layer and a slider for the percentage of roundness.  This is what the expressions look like:

 

//Contents/Rectangle 1/Text BG/Size
src=thisComp.layer(index - 1);
ref = sRc.sourceRectAtTime();
refScale = sRc.scale * .01;
x = ref.width;
y = ref.height;
t = ref.top;
l = ref.left;

[x * refScale[0], y * refScale[1]]

//Contents/Rectangle 1/Text BG/Position
src=thisComp.layer(index - 1);
box = sRc.sourceRectAtTime();
refScale = sRc.scale * .01;
x = box.width / 2;
y = box.height / 2;
t = box.top;
l = box.left;

[(x + l) * refScale[0], (y + t) * refScale[1]]

//Contents/Rectangle 1/Text BG/Roundness
src=thisComp.layer(index - 1);
maxR = sRc.sourceRectAtTime().height / 2;
rndRatio = effect("Roundness")("Slider") * .01;
rVal = maxR * rndRatio;

//Contents/Rectangle 1/Offset Path
src=thisComp.layer(index - 1);
ySize = sRc.sourceRectAtTime().height;
ofst = ySize * effect("Offset")("Slider") * .01;
border = content("Rectangle 1").content("Text BG").roundness;
ofst + border

//Transform/Position
src=thisComp.layer(index - 1);
sRc.position;

 

My most basic animation preset looks like this:

text box.png

I've added a Roundness slider, an Offset slider, and a stroke and fill color Effect Controller to the shape layer for this animation preset. Adding a slider multiplied by .01 and multiplying the width from the text layer's width would give you the ability to animate the Rectangle width from nothing to the width of the text without touching the scale of the layer or the rectangle. If you then compensated the Transform/Rectangle 1/Anchor Point by tying it to the same slider you could have the rectangle justify to the left, right, or center of the text layer and grow from there. You would also have to tie the Total Width slider to the Transform Rectangle 1/Opacity so that the opacity was zero when the Total Width slider was set to zero so the rounded rectangle would not pop on before the reveal started. 

 

If you throw in a valueAtTime and choose the out point of the text layer you can also add a Text Animator to move the text into the frame without fouling up the shape layer's size or position. Once you get used to the workflow it becomes easy to create very usable animation presets that keep things lined up and working easily. You can then use everything you created to generate a MOGRT that you can use in Premiere Pro to speed up your entire workflow.

 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines