View Only
  • 1.  Align Text Vertically Redux

    Posted 11-18-2017 03:30
    So I've searched on the forums, and found some interesting things about aligning text vertically. Unfortunately, the only answer that had people happy included a link to an older post that, for whatever reason, doesn't work for me.
    This would be for a single text field. It potentially has multiple lines, but I'm only interested in one liners at the moment.
    So we can put the text field into a group, which makes it much simpler - I just want to center that text field vertically relative to the group.
    Here's the issue - the bounding box for the text is bigger vertically than the text. If the bottom of the text was actually the bottom of the text, then it wouldn't be such a problem, but the bottom of the text accounts for descenders, so the bottom of the bounding box sits below zero, while the text itself sits roughly right at zero. There is also empty space above, possibly to account for some unicode characters, I don't know.
    But the bounding box is not truly a box bounding the rendered text.
    In any event, though some finagling with visual logic, I was able to, more or less, center the text. The equation involved both BoundingBox height and top. Unfortunately, there is no documentation on the scripting side for IBoundingBox. I can tell you that "top" is NOT a property of it.
    So? I can do it in visual logic, so what's the problem? The problem is if I have twenty lines, I can create a text field with an on-set-text script, and then duplicate it 19 times. If I use visual logic, I have to redo the logic for every single line.
    So questions - are there any API help files that actually have descriptions filled in? Two, can we ever expect that we can get the same functionality in our scripts that we get in visual logic? There's a TON of things in visual logic that aren't available in scripting, it seems. Will Xpression ever offer vertical centering for text?

  • 2.  RE: Align Text Vertically Redux

    Posted 11-18-2017 05:33
    Not sure why the bounding box is not in the api help file.. In any event, here are the properties you can get from it:
    .MinX, .MaxX, .MinY, .MaxY, .MinZ, .MaxZ, .Width, .Height. Depth


  • 3.  RE: Align Text Vertically Redux

    Posted 10-31-2022 22:41
    I'm so glad I found this message - its 2022 and BoundingBox properties are still not in the API docs

    #XPression ​​​

    Ronen Lasry

  • 4.  RE: Align Text Vertically Redux

    Ross Staff
    Posted 11-21-2017 10:01
    Personnaly, I'll do a VL...

    Text.boundingbox.height > Math Block Divide (/2) > Offset (to adjust Y pos) > Text.Position.Y

    That's all... Is that you need ?

  • 5.  RE: Align Text Vertically Redux

    Posted 11-21-2017 19:55
    I think the problem I was talking about got lost in a lot of my blah-blah-blahing...

    The [I]baseline[/I] of the text starts at zero. That means that, if I type ALL CAPS, the the bottom of those letters are at Y=0.0. However, the bounding box contains empty space both above and below to account for both ascenders and descenders.... so the bounding box extends BELOW Y=0.0, so when you take the simple approach by offsetting by 1/2 the bounding box, ALL CAPS TEXT will still not be centered vertically (it will be below, because the bounding box height is actually larger than the text height).

    IOW, the bounding box includes what the text [I]might [/I] contain, not what it actually contains, and because of that it can't be used (by itself) to center text.

    Neither can BoundingBox.Top (even if it's available - it is in visual logic, but not scripting) because [I]that[/I] value includes ascender padding. The vast majority of stats are typically displayed upper-case, and rarely with ascenders - really never, unless you're in a language other than English, perhaps.

    Also, the problem with VL is that it doesn't replicate itself for each of 10 lines of stats, if you catch my meaning, while an OnSetText script will be copied when you duplicate the text object. Oh - another drawback to replicating the VL 10 times is that it all gets evaluated every frame, while OnSetText doesn't.

    EDIT: Here is an example.

    So it's possible, using visual logic (assuming ascender and descender padding are the same), but it uses "BoundingBox.Top," which is not available through scripting.

    EDIT 2: Just to point out another problem, here, is centering vertically, by itself, is only part of a larger problem. Usually that text is on some field with a background, perhaps a border or something, so you want to center the whole group.... but group does not actually provide a bounding box for what it contains. That's a bug, IMO.