Page 2 of 2

Re: Text Fields and Truly Centered Text

Posted: Sat Sep 16, 2023 11:46 pm
by stam
Hi all
richmond62 wrote: Fri Sep 15, 2023 6:11 pm What is all the 'guff' about centered text?
...
142 = (half the height of the field) + (half the size of the text)= (256/2) + (28/2)
jacque wrote: Sat Sep 16, 2023 9:19 pm Turn on fixedLineHeight and set the textHeight to 28. That should be all you need. If you change the text size, you'll need to also adjust the textHeight.
@Jacque, @RIchmond: Can I point out an issue with using textHeight? It changes the size of the cursor which can make it look ridiculous.

To test, I used Richmond's algorithm (which I think is similar to what Jacque is proposing):

Code: Select all

set the fixedLineHeight of field 1 to true 
set the textHeight of field 1 to the height of field 1/2 + the textSize of field 1/2
This does indeed center the text vertically, as desired, but try inserting a cursor and/or selecting text:
Screenshot 2023-09-17 at 01.34.27.png


The method proposed by Bernd that adjusts the topMargin instead (the algorithm is posted above) does not change the cursor size and produces the expected result. This automates what Craig and Klaus were suggesting as a manual adjustment:
Screenshot 2023-09-17 at 01.33.38.png
Everyone will use what they are conformable with, but for me, I cannot have text boxes where the cursor can be several times the size of the text... so I'd go with Bernd's advice.

Re: Text Fields and Truly Centered Text

Posted: Sun Sep 17, 2023 1:16 am
by jacque
True. It wasn't clear to me whether the field was a label or editable. I've saved Bernd's handler for future occasions. His work is always brilliant.

Re: Text Fields and Truly Centered Text

Posted: Sun Sep 17, 2023 1:54 am
by richmond62
Yes, Bernd's way is inevitably better than mine.

But that is because mine was a 2-minute knee-jerk reaction to solve the initial problem without any thought to other consequences.