Text vertical alignment

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

snm
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 253
Joined: Fri Dec 09, 2011 11:17 am

Text vertical alignment

Post by snm »

I can find only horizontal alignment of text in fields or buttons properties. Is it possible to vertically align it in LC?

snm
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Text vertical alignment

Post by dunbarx »

I am missing this. What is horizontal alignment in a text field? I know there is "left", "right" and "center" alignment.

But these are all, essentially, "vertical"

Craig Newman
snm
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 253
Joined: Fri Dec 09, 2011 11:17 am

Re: Text vertical alignment

Post by snm »

Vertical allignment means top, buttom, center
Regards snm
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Text vertical alignment

Post by dunbarx »

Hmmm.

If I set the alignment of a field to "left", I see this as a 'vertical" thing. The several lines are aligned in this way. But that may be just (mis)interpretation.

What is meant by aligning them horizontally, then? Lines are already essentially horizontal entities. How do you modify this? You don't mean adjust the line spacing (the textHeight), do you?

Craig Newman
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Text vertical alignment

Post by Klaus »

Hi snm,
snm wrote:Vertical allignment means top, buttom, center
Regards snm
sorry, no vertical alignment in LiveCode fields!


Best

Klaus
gpb01
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 281
Joined: Sat Jun 04, 2011 5:41 pm

Re: Text vertical alignment

Post by gpb01 »

snm wrote:Vertical allignment means top, buttom, center
Regards snm
Not in this way, but for text fields ...
... under "Align" you have "Margins" ... try to play with this value ;)

Guglielmo
endernafi
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 296
Joined: Wed May 02, 2012 12:23 pm
Contact:

Re: Text vertical alignment

Post by endernafi »

How about doing the vertical alignment dynamically, i.e. by script:
It's a simple script and of course can be developed further.

Code: Select all

  set the topMargin of field theField to \
            (round(((the height of field theField - the formattedHeight of field theField)/2)) + the topMargin of field theField)
~... together, we're smarter ...~
__________________________________________

macOS Sierra • LiveCode 7 & xCode 8
Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Text vertical alignment

Post by Mark »

Actually, Guglielmo's answer is the correct answer.

"endernafi's" answer makes no sense.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
endernafi
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 296
Joined: Wed May 02, 2012 12:23 pm
Contact:

Re: Text vertical alignment

Post by endernafi »

I have a piece of code which produces text fields as a list.
The number of these fields is totally random and there are hundreds of them.
In these circumstances how should I play the Margins value manually?

And that piece of code worked like a charm, just this morning, it made a lot of sense for me.
Maybe it's not suitable for every occasion but with a little tweaking it should work.
Simple and easy.
And that snippet plays with Margin values, too, actually.


Best Regards,

Ender Nafi
~... together, we're smarter ...~
__________________________________________

macOS Sierra • LiveCode 7 & xCode 8
Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Text vertical alignment

Post by Mark »

Dear Ender,

You can set the margins by script. Setting the topMargin to a value derived from itself, as you do in the code you posted, doesn't make sense without lots of explanations.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
endernafi
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 296
Joined: Wed May 02, 2012 12:23 pm
Contact:

Re: Text vertical alignment

Post by endernafi »

I couldn't get the reason behind, but anyways, you're the guru :oops:
It worked as of now for me, thus I did want to share.

Best,
~... together, we're smarter ...~
__________________________________________

macOS Sierra • LiveCode 7 & xCode 8
Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Text vertical alignment

Post by Mark »

Hi,

Surely, I appreciate that you share some code and I believe you when you say it works for you. Probably you set the topMargin twice or you can assume a constant value for the value when the script runs for the first time or something else.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7423
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Text vertical alignment

Post by jacque »

Ender's script makes sense to me.

Subtract the formattedheight of the field from its height --> the available empty vertical space
Divide by 2 --> equalize the amount of space at top and bottom
Add the original topmargin --> retain original top margin

I might leave off the last part, but it still works. It does assume the field height is more than the height of its contents.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Text vertical alignment

Post by Mark »

Exactly, Jacque, that's the kind of explanation I meant. I think that your last remark about the assumption is particularly important.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7423
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Text vertical alignment

Post by jacque »

I can't think of any other way to calculate the vertical space. Seems like a functional script to me, and I don't think Ender needs to to feel bad about it. You mentioned a script should set the top margin, and that's what his script does.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
Post Reply