Author Topic: [question] right aligned text positioning - from top left or top right corner?  (Read 13146 times)

verion

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 863
    • View Profile
    • new projects
I'm trying to position right aligned text.
But I'm not sure if (right aligned) text position is calculated from top left or top right corner?

Code: [Select]
local manufacturer = fe.add_text( "[Manufacturer]", flx*0.5, fly*0.5, flw*0.3, flh*0.05 );
manufacturer.set_rgb( 59, 45, 3 );
manufacturer.align = Align.Right;

I'm trying to achieve something like this:
« Last Edit: September 13, 2015, 10:49:30 AM by verion »

omegaman

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 880
    • View Profile
On 2D coordinate systems, everything should start from the top left corner 0,0.  So, if you want text on the left side of the page use left alignment and on the right side use right alignment. Look at it this way, right alignment extends the text to the right from a specified coordinate whereas as the left alignment will extend the text toward the left. This is useful if you have text close to margins. And, remember, you can forgo alignment altogether. I usually don't use alignment for text other than the margins.

verion

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 863
    • View Profile
    • new projects
But with right-aligned text the coordinates are fixed to the top-right corner of text block?

omegaman

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 880
    • View Profile
I think we are trying to say the same thing, it's just the way you worded the question "But I'm not sure if (right aligned) text position is calculated from top left or top right corner?." You are placing the text box on an X axis that moves from left to right and a Y axis from top to bottom. And, as you know, the starting position would be 0,0. Its not really the corner of the text box per say, but more like the alignment starts on either the right or the left of the text box where it was placed. To better Illustrate this, make your text box one char in width (flw*0.01 in this scenario) - this is good for determining text placement as well. If left alignment is specified the char will be more left and vise versa for right alignment. And, using no alignment the text will extend left and right depending on the width specified.


This is one of those things where it gets easier the more you play around with it. After doing a few layouts, the coordinates become like second nature. Of course, this is my own understanding and world view of how it works.