Formattedheight of a button unexpected behaviour

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
Havanna
Posts: 53
Joined: Wed May 14, 2014 3:00 pm

Formattedheight of a button unexpected behaviour

Post by Havanna » Fri Oct 03, 2014 9:49 pm

I have a button whose label is set via script.
Sometimes there is more than one line of text to place.

Like with fields I've tried to set the height to the formattedheigth:

on mouseUp
set the label of button "B" to "first Line" & cr & "Next Line"
set the height of button "B" to the formattedheight of button "B"
end mouseUp

in button "B"

but that just changes the label, no effect on hte height.
Where is my mistake?

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

Re: Formattedheight of a button unexpected behaviour

Post by dunbarx » Fri Oct 03, 2014 11:14 pm

I wonder if buttons respond to this sort of thing. They are not mentioned in the dictionary. Certainly fields and certain other controls do. Setting neither the label nor the text of a button to several lines of text will cause setting the formattedText to change anything.

Craig Newman

Havanna
Posts: 53
Joined: Wed May 14, 2014 3:00 pm

Re: Formattedheight of a button unexpected behaviour

Post by Havanna » Fri Oct 03, 2014 11:41 pm

That's what stumped me.
The dictionary entry for formattedheight doesn't mention buttons, but the property is listed when I select Object -> Button

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

Re: Formattedheight of a button unexpected behaviour

Post by SparkOut » Fri Oct 03, 2014 11:48 pm

To have a formattedHeight property, the text must belong to a field, I believe. It may be a bug, or a limitation of the field type of the button label being just "label" type. A workaround would be to have a hidden field on the card and:

Code: Select all

on mouseUp
   set the label of button "B" to "first Line" & cr & "Next Line" 
   put the label of button "B" into field "hiddenField"
   set the height of button "B" to the formattedHeight of field "hiddenField"
end mouseUp

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

Re: Formattedheight of a button unexpected behaviour

Post by SparkOut » Sat Oct 04, 2014 12:03 am

OK, I was wrong. This works for me :

Code: Select all

on mouseUp
   set the label of button "B" to "first Line" & cr & "Next Line"
   set the height of button "B" to the formattedHeight of button "B" 
end mouseUp

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

Re: Formattedheight of a button unexpected behaviour

Post by dunbarx » Sat Oct 04, 2014 4:01 am

Sparkout.

Isn't that the same code that the OP posted?

Craig

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

Re: Formattedheight of a button unexpected behaviour

Post by SparkOut » Sat Oct 04, 2014 7:55 am

Yes... So for the OP something is not working as it should, but LC does seem to have a formattedHeight property for buttons.

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

Re: Formattedheight of a button unexpected behaviour

Post by SparkOut » Sat Oct 04, 2014 10:33 am

And now this is getting weirder. Trying again this morning has more issues. Same problem as the OP - to begin with. Testing with the hiddenField workaround changed the height of the button but not to the correct size. Yesterday I know I looked at the text formatting properties of the button to see if there was anything there that would be a factor, but didn't change anything. Then I went back to test with the original code and it worked. If I now put a specific text font and size into the settings, the hidden field method now will resize to the correct size for some fonts and not for others. I haven't hit on a combination to guarantee a correct resize, and I still can't get the plain formattedHeight property of the button to come out right.
Bizarre

Post Reply