Set button width to the width of its label?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

trenatos
Posts: 189
Joined: Wed Jul 03, 2013 6:46 am
Contact:

Set button width to the width of its label?

Post by trenatos »

I'm programmatically creating buttons, but I can't figure out how to set the width of the button to the width of its label programmatically.

How do I get the width of a buttons label?
Marcus
trenatos
Posts: 189
Joined: Wed Jul 03, 2013 6:46 am
Contact:

Re: Set button width to the width of its label?

Post by trenatos »

Hah, I just found it..

set the width of btn "btnName" to the formattedWidth of btn "btnName"
Marcus
bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Set button width to the width of its label?

Post by bogs »

I know, older thread that was answered by the OP no less. But I find myself in a similar situation, with a menu button. Even though the button resizes using the above the way I want it to, the 'menu' below it stays the width of the button. Is there a way to have the button one size, and the menu part a different size?
Image
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Set button width to the width of its label?

Post by dunbarx »

Bogs.

Not positive, but I believe the actual menu portion of these gadgets are drawn by the OS, not by LC, so I am not sure you can do anything about that. You can always roll your own, of course.

Craig
bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Set button width to the width of its label?

Post by bogs »

Thanks Craig, I suspect your right, and I very well may wind up doing exactly that since I've already rolled the entire dialog so far :D Of course, if it isn't and someone knows what I'm missing, I'd rather go that route :D
Image
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Set button width to the width of its label?

Post by Klaus »

bogs wrote: Thu Nov 30, 2017 10:45 pmI suspect your right...
Really? Come on! 8)
bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Set button width to the width of its label?

Post by bogs »

Klaus wrote: Fri Dec 01, 2017 5:05 pm
bogs wrote: Thu Nov 30, 2017 10:45 pmI suspect your right...
Really? Come on! 8)
Thanks Klaus, I suspect your being gently sarcastic :P (j/k, I am sure he is right).

This is what I am playing with, currently re-creating (without looking at the actual code) a dialog from the original Hc -
Image
and here is what I've come up with -
Image
Anyhoo, I think the problem I was trying to solve actually has 2 components. It looks like Hc used the width of the longest item in the menu, instead of what was in the button, like so -
Image
The problem this leaves for me to resolve is the icon spacing from the text in the button. I'm using of course the icon and text align right for the button, if the space is much larger than needed, the icon gets dramatically farther away from the text and makes it look funny -
Image

These are all cosmetic issues, functionally, the dialog already works as I was looking for it to, but of course the devil is in the details :evil:
Image
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Set button width to the width of its label?

Post by Klaus »

bogs wrote: Fri Dec 01, 2017 5:39 pm
Klaus wrote: Fri Dec 01, 2017 5:05 pm
bogs wrote: Thu Nov 30, 2017 10:45 pmI suspect your right...
Really? Come on! 8)
Thanks Klaus, I suspect your being gently sarcastic :P (j/k, I am sure he is right).
I am just making a bit fun of your wimpy language skills! :D
It is spelled, "you are right" or abbreviated "you're right", isn't it?

"I suspect your right" has a complete different meaning, monsieur! 8)
bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Set button width to the width of its label?

Post by bogs »

Klaus wrote: Fri Dec 01, 2017 9:50 pm I am just making a bit fun of your wimpy language skills! :D
I will gladly pay you Tuesday for a hamburger today!

You are indeed correct sir, my language skills are nearly non existent at this point :lol:
Image
mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3582
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Set button width to the width of its label?

Post by mwieder »

It's Wednesday already. Did Klaus get paid?

...and stop calling me Shirley.
bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Set button width to the width of its label?

Post by bogs »

mwieder wrote: Wed Dec 06, 2017 8:51 pm It's Wednesday already. Did Klaus get paid?
No hamburgers were given to said Wimpy, so no payments were made for said hamburgers :P
Image
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Set button width to the width of its label?

Post by Klaus »

No, I did not get paid yet, Ethel! 8)

Took a while until I got the "Wimpy" joke, since there are no Wimpy shops in germany at all and the last one I saw was about 45 years ago in the netherlands, specivo in the city of Arnhem. :D
bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Set button width to the width of its label?

Post by bogs »

Ugh, and here I thought Popeye was universal.
I am wot I am and thats all wot I am, ugh ugh ugh :lol:
Image
bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Set button width to the width of its label?

Post by bogs »

Thats the ticket :D
Image
Post Reply