Text Fields and Truly Centered Text

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

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

Re: Text Fields and Truly Centered Text

Post by stam » Sat Sep 16, 2023 11:46 pm

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.

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

Re: Text Fields and Truly Centered Text

Post by jacque » Sun Sep 17, 2023 1:16 am

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: Text Fields and Truly Centered Text

Post by richmond62 » Sun Sep 17, 2023 1:54 am

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.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”