TextHeight problem

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10309
Joined: Wed May 06, 2009 2:28 pm

TextHeight problem

Post by dunbarx » Wed Oct 30, 2024 7:33 pm

From msg I can set the textHeight of a certain field to, say, 13, and from msg I always get "13" back when querying its textHeight. Great, eh?

In a large project, I have a test mouseDown handler in that field, and I placed this in a line in it:

Code: Select all

answer the textHeight of me
Which all of a sudden comes up empty.

This was in a utility where the user can click on any line in that field, and a tool would pop up at the clickV, pertinent to the line of interest. Today, LC has forgotten the textHeight of the field IN THE HANDLER, whereas if I go back to msg, any old time at an all, "13" comes up as expected.

The utility always appears at the top of the field, not at the line of interest, because the calculation that locates it is using empty as the value of the textHeight, and not 13. Great, eh?

Before I just assume it is, again, just me, and replace the textHeight reference with 13 (which means I cannot change the font size without modifying that explicit value) can anyone make sense of this?

Craig

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

Re: TextHeight problem

Post by SparkOut » Wed Oct 30, 2024 9:57 pm

Is it a locked field?

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4168
Joined: Sun Jan 07, 2007 9:12 pm

Re: TextHeight problem

Post by bn » Wed Oct 30, 2024 10:00 pm

Hi Craig,

Just a hunch: have you tried

Code: Select all

answer the effective textHeight of me
?

Otherwise without a sample stack it is hard to come up with anything.

Kind regards
Bernd

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10309
Joined: Wed May 06, 2009 2:28 pm

Re: TextHeight problem

Post by dunbarx » Thu Oct 31, 2024 12:20 am

Sparkout. Locked. (Must be to send mouseUp).

Bernd. Never occurred to me that anything other than the good ol' textHeight would do. It used to.

The following line of code will locate a button at (roughly) the same vertical position as any line clicked on a locked field:

Code: Select all

set the top of btn 1 to the top of me + (word 2 of the clickLIne + 1) * the textHeight of me
But if the textHeight is empty, so is the effectiveness of that line of code.

So I made a new stack here at home, and set the textHeight of a field (have to, because a new field has that property set to empty right out of the box. It initially inherits that property, I think, of the card or stack). The handler works just fine, so it is something in my project stack. But it is a new problem that just came up today, since the gadget in question has worked in that stack fine for years.

Just me.

Craig

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4168
Joined: Sun Jan 07, 2007 9:12 pm

Re: TextHeight problem

Post by bn » Thu Oct 31, 2024 12:38 pm

Craig,

You could also do:

Code: Select all

set the top of button 1 to item 2 of the formattedrect of line (word 2 of the clickLIne) of me
Kind regards
Bernd

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10309
Joined: Wed May 06, 2009 2:28 pm

Re: TextHeight problem

Post by dunbarx » Thu Oct 31, 2024 1:46 pm

Bernd.

That is adorable. It does, however, ignore the fact that LC is playing with me again.

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10309
Joined: Wed May 06, 2009 2:28 pm

Re: TextHeight problem

Post by dunbarx » Thu Oct 31, 2024 2:04 pm

Well, well.

First thing I did today back in the office, just for laughs. I restored, in the line that once used "the textHeight" to determine where to place my tool, and for which I had to instead use an explicit value, back to "the textHeight".

Just for laughs, you know. And now it works. Works just like it always did for years. Same LC session, by the way.

Not that I do not trust LC to be ghost-free, especially on halloween, but I think I will use Bernd's very cute alternate method with the "formattedRect". I bet that property is not haunted. :roll:

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10309
Joined: Wed May 06, 2009 2:28 pm

Re: TextHeight problem

Post by dunbarx » Thu Oct 31, 2024 2:18 pm

Bernd.

My tool is required to be placed vertically one line below the line clicked on. The variable "tVert" contains that value. For just a second, I was annoyed to think that I had to add the textHeight to your method, and that does not do away with that haunted property.

But the next second I realized that I only needed to:

Code: Select all

put item 2 of the formattedRect of line (word 2 of the clickLine + 1) of me into tVert
So thanks for thinking out of the box.

Craig

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4168
Joined: Sun Jan 07, 2007 9:12 pm

Re: TextHeight problem

Post by bn » Thu Oct 31, 2024 2:32 pm

Craig,

You could also use

Code: Select all

set the top of button 1 to the item 4 of the formattedrect of line (word 2 of the clickLIne) of me
to place the button below the clickline. Note "item 4".

Kind regards
Bernd

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10309
Joined: Wed May 06, 2009 2:28 pm

Re: TextHeight problem

Post by dunbarx » Thu Oct 31, 2024 3:20 pm

Bernd.

Yep, even simpler.

Craig

Post Reply