Centering dynamic text

What is the best way to center dynamic text to fit appropriately regardless of (reasonable) content change.

For Example:

name variable = John:
Hello John
Welcome to John’s page

name variable = Alexandra
Hello Alexandra
Welcome to Alexandra’s page

To build on this, is there a way to resize text to fit if variable length exceeds a certain number.
Ex: If variable length > 8: FONTsize = 14
If variable length = 9-14 FONTsize =12
If variable length >13 FONTsize = 10

Thanks!

Hi jwarzy72,

Sounds like an interesting setup! Unfortunately, Axure RP doesn’t currently have an action in the case editor that would allow you to change the font size on target text. That said, you can make the widget that will display text a dynamic panel with different states, and each of those states has a different font size set on it. This way, if your conditional logic detects that the variable length is >8, it could change the panel to the state that has the 14 size font. If variable length was between 9 and 14 characters, it would change to the state with 12 pt font, and so on so forth.

I’ve attached a sample file that switches the font to 14 pt for anything less than 8 characters and decreases to 8 pt for anything longer than 8. Hopefully this helps!
Font Size Change.rp (102 KB)

1 Like

Thanks Alyssa,

Very helpful, although I am more interested in finding a practical way to center the variable text within a static sentence.

For example:

  1. Welcome to our page, John. Thanks for stopping by.
  2. Welcome to our page, Alexandra. Thanks for stopping by

A way to account for the static text before and after, and to account for the variable text (name), and center all of that as one object.

Thanks,
John

Hi John,
Please check the screenshot and rp file. Just use rich text instead of set text on widget.



I hope it will be useful for you.
Thanks,
Vikram
Font Size Change_updated.rp (101 KB)

1 Like

Exactly what I was looking for - thank you both!

Hi Alyssa,

I tried to apply this method to my demo when you increase the amount using the slider I want to keep the amount centered but I seem to have trouble with it not moving. Perhaps there is a more simple way to keep the text aligned centered?Slider.rp (66.8 KB)

Hi Richtux,

From looking at your file, it looks like you’re very close! To keep the text centered as the slider moves, you can increase the width of the text widgets displaying the number amounts (in “State1” and “State2” of the “euros” dynamic panel) and then set their text align options to align “center”. Then, since the euros dynamic panel is already set to “Fit to Content”, you can move the panel itself over to the desired location in the center.

Here’s an edited version of your file where I increased the widths of the text widgets to 150px and then re-centered the euros dynamic panel. Feel free to take a look and let me know if you have any questions!

Slider_edited.rp (70.0 KB)