Center Text From Top To Bottom Of Field.

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Googie85
Posts: 199
Joined: Tue Aug 05, 2014 10:07 am

Center Text From Top To Bottom Of Field.

Post by Googie85 » Wed Dec 28, 2022 4:19 am

Hi Guys!!

I have searched the dictionary and can't seem to find a way to center text in a field, between top and bottom of the field (Vertical).

I would greatly welcome any advice on where I should look for in the dictionary!

Many Thanks,

Googie.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Center Text From Top To Bottom Of Field.

Post by jmburnod » Wed Dec 28, 2022 10:05 am

Hi,
If I understand you correctly you may use textalign property

Code: Select all

set the textalign of fld 1 to center
Best regards
Jean-Marc
https://alternatic.ch

stam
Posts: 2683
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Center Text From Top To Bottom Of Field.

Post by stam » Wed Dec 28, 2022 10:37 am

Isn’t that left-to-right Center alignment?

Not sure there is a built in method for this - other than manipulating textheight or margins… but more than happy to be proven wrong on this!!

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Center Text From Top To Bottom Of Field.

Post by Klaus » Wed Dec 28, 2022 10:51 am

Vertical alignment of text is unfortunately not supported in LC. :cry:
As Stam said, you need to play with the margins etc.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Center Text From Top To Bottom Of Field.

Post by Klaus » Wed Dec 28, 2022 2:05 pm

There is an old enhancement request from 2005 (!), which may show the priority of this feature...
https://quality.livecode.com/show_bug.cgi?id=2707

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9388
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Center Text From Top To Bottom Of Field.

Post by richmond62 » Wed Dec 28, 2022 2:12 pm

Sorry, drunk right now, BUT have a look at the fonty bit of the props palette of a text field as somewhere near the bottom there is something with numbers about row spacing that MIGHT be capable of being leveraged.

After a post-prandial snooze will fire up the Mac Mini and try to come up with some pretty pictures and some code.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9388
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Center Text From Top To Bottom Of Field.

Post by richmond62 » Wed Dec 28, 2022 2:53 pm

There's a lot to be said for gummi-bears: bypassed the snooze . . .

This sort of stuff ONLY works if you ONLY have one line of text:

Code: Select all

on mouseUp
   put the ((height of fld "ff")/2) into HITE
   set the textHeight of fld "ff" to HITE
end mouseUp
-
SShot 2022-12-28 at 15.53.05.png

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9388
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Center Text From Top To Bottom Of Field.

Post by richmond62 » Wed Dec 28, 2022 3:10 pm

Well, here's a thought:
-
SShot 2022-12-28 at 16.10.21.png
-

Code: Select all

on mouseUp
   put the textSize of fld "ff" into TextSZ
   add 4 to TEXTSZ
   put TextSZ
   put the number of lines in fld "ff" into NUML
   put the height of fld "ff" into HITE
   put (HITE/TextSZ) into BZZ
   put (BZZ - NUML) into XXX
   put TextSZ & "," & XXX
   put XXX/2 into XXX2
   repeat XXX2 times
      put cr before fld "ff"
   end repeat
end mouseUp
-
VY-Mavrud-272x450.png

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9388
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Center Text From Top To Bottom Of Field.

Post by richmond62 » Wed Dec 28, 2022 6:36 pm

The main snag about what I outlined is that that is a once-off script to be applied to a static text
in a field.

Alignment as it is generally understood:
-
SShot 2022-12-28 at 19.33.22.png
SShot 2022-12-28 at 19.33.22.png (9.3 KiB) Viewed 10103 times
-
means that as one inserts (types) more text the alignment process is an active thing.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7237
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Center Text From Top To Bottom Of Field.

Post by jacque » Wed Dec 28, 2022 7:15 pm

I'd try getting the formattedHeight of the text, and subtract that from the height of the field, which gives the extra free space available. Divide the free space by 2 and set the top and bottom margins to that number.

Untested, but seems logically sound. If the result is slightly off you may need to account for the text baseline. Adjust the margins by 1/3 of the textheight.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9388
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Center Text From Top To Bottom Of Field.

Post by richmond62 » Sat Dec 31, 2022 3:00 pm

SShot 2022-12-31 at 15.58.41.png
-
Well, its a start.

And, to clarify things, by 'start' I mean that if you add extra text the formatting will go wrong.
Attachments
Cripes.livecode.zip
Stack.
(14.17 KiB) Downloaded 79 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9388
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Center Text From Top To Bottom Of Field.

Post by richmond62 » Sat Dec 31, 2022 4:36 pm

OK, OK, OK: here we are . . .
-
Attachments
Vertical alignment.livecode.zip
Stack.
(14.57 KiB) Downloaded 83 times

Post Reply

Return to “Android Deployment”