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

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: Text vertical alignment

Post by bn » Tue Jun 26, 2012 8:23 pm

Hi Marek,

I was only joking when I said: "glad you asked". Although I did not want to let the formula unexplained and it is always a good idea to understand what is going on.

Regarding the datagrid: I only have used it once or twice to test it and I had no real need for it. So I am not in a position to give you advice on that.

It may be a good idea to open a new thread with your datagrid question.

Kind regards
Bernd

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: Text vertical alignment

Post by bn » Tue Jun 26, 2012 8:30 pm

Thanks Mark,

although a little off the track it can be handy in rare circumstances. Like when you want to position a graphic with a gradient as an alternating line background for a list field or table field... But that gets really weird by then.

http://berndniggemann.on-rev.com/altern ... vecode.zip

Kind regards
Bernd

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 » Tue Jul 10, 2012 6:42 pm

Thanks Berndt for sample stack.

Marek

nlexa
Posts: 26
Joined: Fri Aug 05, 2011 2:34 am

Re: Text vertical alignment

Post by nlexa » Thu Sep 26, 2013 1:51 am

Hey Bernd why does

Code: Select all

put the formattedHeight of char 1 to -1 of field 1 into tVariable
give a different result than

Code: Select all

put the formattedHeight of field 1 into tVariable
On a related note, in my own investigations I have found that 6 + 2/3 (6.6666666666666666666) is the magic number.
Subtracting it from a multiple of the text size yields reliable vertical positioning results. I painstakingly measured the pixels and drew graphs to discover this.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: Text vertical alignment

Post by bn » Thu Sep 26, 2013 8:12 am

Hi nlexa,
why does
put the formattedHeight of char 1 to -1 of field 1 into tVariable

give a different result than

put the formattedHeight of field 1 into tVariable
the formattedHeight of char 1 to - 1 of field 1 means just the text whereas
the formattedHeight of field 1 also includes (besides the text) margins, borderwidth and scrollbars.
On a related note, in my own investigations I have found that 6 + 2/3 (6.6666666666666666666) is the magic number.
Subtracting it from a multiple of the text size yields reliable vertical positioning results
could you post a sample script or better a sample stack?

as for the formattedHeight of a field I attach a little stack, attention it could make you dizzy, use at your own risk... :)

MarginsApp.livecode.zip
(3.12 KiB) Downloaded 371 times

Kind regards

Bernd

nlexa
Posts: 26
Joined: Fri Aug 05, 2011 2:34 am

Re: Text vertical alignment

Post by nlexa » Sat Sep 28, 2013 10:41 pm

Nice stack Bernd

Here is an example stack for you.
nlexaExample.zip
(1.28 KiB) Downloaded 393 times
You will notice when you turn off the correction and make the margins 0 that as you decrease the text size it starts disappearing into the top of the field as per normal.

If you use the right ratio (multiplier) applied to the text size and subtract 20/3 (the magic number) and subtract all of this from your margins (which at smaller sizes is addition, minus a minus) you get the text to stay the same distance from the top as it does from the left as dictated by the margin value.

I'm sure the stack and the code will better explain what I'm getting at.

Kind regards

nlexa

nlexa
Posts: 26
Joined: Fri Aug 05, 2011 2:34 am

Perfect Top Margin

Post by nlexa » Tue Oct 01, 2013 11:39 pm

Perfect Top Margin.zip
(2.15 KiB) Downloaded 395 times
Here is an update. Now you can adjust the text height also.
I'm not much of a programmer and more of a graphic designer so trying to get the text to line up correctly was really starting to wind me up :x . I'm sure there are others out there who are as visually pedantic as me so I'm sharing this :idea: .

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: Text vertical alignment

Post by bn » Wed Oct 02, 2013 12:11 pm

Hi nlexa,

thanks for the two stacks, very nifty, now with the seocnd stack I understand better what you are after.

Kind regards
Bernd

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Text vertical alignment

Post by Dixie » Wed Oct 02, 2013 12:57 pm

Ender...

nice solution !

Dixie

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 » Thu Oct 10, 2013 9:26 am

Thanks Dixie.

It wasn't perfect as many pointed it out.
This kinda things can hardly be handled with a single line of code.
Besides, I was a total novice back then; posting a solution was a bold move 8)


Best,

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

macOS Sierra • LiveCode 7 & xCode 8

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: Text vertical alignment

Post by dave.kilroy » Mon Dec 16, 2013 7:13 pm

Thanks Bernd

That slight amount 'off' I was getting was driving me potty (and it would drive my client - who is VERY interested in details - bananas)

Nice work :)
"...this is not the code you are looking for..."

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: Text vertical alignment

Post by bn » Mon Dec 16, 2013 9:50 pm

Dave,

thank you. I am glad it helped.

you said:
(and it would drive my client - who is VERY interested in details - bananas
reminds me of a hilarious (IMHO) reader comment on "The Register" to this article
http://www.theregister.co.uk/2007/08/31 ... a_ripener/

where a company was looking for an
Trainee Assistant Banana Ripener
The reader comment:
Poor industrial relations
I used to have this job! Terrible workplace culture, the forklift operators drove me bananas...
Well I got carried away a bit, I am afraid. :)

Kind regards
Bernd

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: Text vertical alignment

Post by dave.kilroy » Mon Dec 16, 2013 10:41 pm

Um thanks for the story Bernd - I've thought more about bananas in the last five minutes than I ever have before...
"...this is not the code you are looking for..."

Post Reply