Page 1 of 1

Center Text From Top To Bottom Of Field.

Posted: Wed Dec 28, 2022 4:19 am
by Googie85
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.

Re: Center Text From Top To Bottom Of Field.

Posted: Wed Dec 28, 2022 10:05 am
by jmburnod
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

Re: Center Text From Top To Bottom Of Field.

Posted: Wed Dec 28, 2022 10:37 am
by stam
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!!

Re: Center Text From Top To Bottom Of Field.

Posted: Wed Dec 28, 2022 10:51 am
by Klaus
Vertical alignment of text is unfortunately not supported in LC. :cry:
As Stam said, you need to play with the margins etc.

Re: Center Text From Top To Bottom Of Field.

Posted: Wed Dec 28, 2022 2:05 pm
by Klaus
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

Re: Center Text From Top To Bottom Of Field.

Posted: Wed Dec 28, 2022 2:12 pm
by richmond62
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.

Re: Center Text From Top To Bottom Of Field.

Posted: Wed Dec 28, 2022 2:53 pm
by richmond62
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

Re: Center Text From Top To Bottom Of Field.

Posted: Wed Dec 28, 2022 3:10 pm
by richmond62
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

Re: Center Text From Top To Bottom Of Field.

Posted: Wed Dec 28, 2022 6:36 pm
by richmond62
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 12938 times
-
means that as one inserts (types) more text the alignment process is an active thing.

Re: Center Text From Top To Bottom Of Field.

Posted: Wed Dec 28, 2022 7:15 pm
by jacque
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.

Re: Center Text From Top To Bottom Of Field.

Posted: Sat Dec 31, 2022 3:00 pm
by richmond62
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.

Re: Center Text From Top To Bottom Of Field.

Posted: Sat Dec 31, 2022 4:36 pm
by richmond62
OK, OK, OK: here we are . . .
-