Vertical emplacement

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

Post Reply
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Vertical emplacement

Post by dunbarx » Fri May 07, 2021 12:13 am

Wasn't there a property that would "center" text in a field vertically? No fiddling with margins? I think Jacque was involved...

I know I can do this sort of thing with the "formattedHeight".

Craig

SparkOut
Posts: 2839
Joined: Sun Sep 23, 2007 4:58 pm

Re: Vertical emplacement

Post by SparkOut » Fri May 07, 2021 7:40 am

Depending on what you are looking for, iconGravity might be the answer. But you might be asking a different question, as I don't believe this works for fields.

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

Re: Vertical emplacement

Post by Klaus » Fri May 07, 2021 8:26 am

dunbarx wrote:
Fri May 07, 2021 12:13 am
Wasn't there a property that would "center" text in a field vertically?
No, Craig, there wasn't!

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

Re: Vertical emplacement

Post by jacque » Sat May 08, 2021 7:16 pm

I see I have saved three methods to do this but they all do rely on margins. Here's what I've got:

Code: Select all

on centerLine -- calculation to get the vertical center of a line of text in a field
  constant kLeft = <the left of your box>, <kRight = the right of your box>

  put (item 2 of the mouseLoc - the top of fld 1) \
     div the lineHeight of fld 1 into tTop
  set the rect of grc "box" to kLeft,tTop,kRight,tTop+the lineHeight of fld 1
end centerLine

-----------

To center a block of text in a field, regardless of text size, variable styling, etc.:

 put round(the effective textheight of me * .66) into tUnderHang
 set the topmargin of me to (the height of me - (the formattedheight of line 1 to -1 of me) + tUnderHang) div 2


-------------
My forum suggestion:

on mouseUp
 put the effective textheight of me * .33 into tPadding
 put the formattedheight of line 1 to -1 of me into tTotalTextHt
 put ( ( the height of me - tTotalTextHt ) / 2) into tTopMargin
 set topmargin of me to tTopMargin + tPadding
end mouseUp
I'm sorry I didn't save the authors of the other two methods.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Vertical emplacement

Post by dunbarx » Mon May 10, 2021 3:11 pm

Jacque.

Thanks for all that. I used the formattedHeight myself to do the job. I am not sure why I thought there was something similar for vertical to the familiar "center" property for horizontal justification.

Craig

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

Re: Vertical emplacement

Post by jacque » Mon May 10, 2021 5:29 pm

Maybe you saw the docs for the Android native field widget. I was working with it yesterday and noticed it offers 3 different vertical placements.

Unlikely, I know.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Vertical emplacement

Post by dunbarx » Mon May 10, 2021 7:00 pm

Jacque.

What is "android"? Is it some Windows outrage?

Stupid, I know.

But are these "Up", "Center" and "Down"?

Craig

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

Re: Vertical emplacement

Post by jacque » Mon May 10, 2021 7:51 pm

:)
An Android is an intelligent robot...

The native field offers top, middle, and bottom vertical text alignment.
Screen Shot 2021-05-10 at 1.50.33 PM.png
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Vertical emplacement

Post by dunbarx » Mon May 10, 2021 8:00 pm

Jacque.

I begrudgingly admit that the dark side has some cool stuff.

Am I the only one (again) that would love not to have to fiddle with margins and effective/formatted gadgetry to get vertical justification?

Craig

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

Re: Vertical emplacement

Post by stam » Tue May 11, 2021 2:20 pm

Not just the dark side; FileMaker Pro has had this for decades.
However other languages/IDE, for example XOJO do not offer functionality and you have to program it in. I found myself having to do lots of things like that with XOJO which is why i ultimately left it behind for LiveCode which offers many, many conveniences - but this is one convenience that is strangely lacking...
Feature request?

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”