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: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

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

Set button width to the width of its label?

Post by trenatos » Fri Apr 24, 2015 2:02 pm

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
Location: Virginia, USA
Contact:

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

Post by trenatos » Fri Apr 24, 2015 2:04 pm

Hah, I just found it..

set the width of btn "btnName" to the formattedWidth of btn "btnName"
Marcus

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

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

Post by bogs » Thu Nov 30, 2017 9:53 pm

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?
ImageImage

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

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

Post by dunbarx » Thu Nov 30, 2017 10:07 pm

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: 745
Joined: Sat Feb 25, 2017 10:45 pm

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

Post by bogs » Thu Nov 30, 2017 10:45 pm

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
ImageImage

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

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

Post by Klaus » Fri Dec 01, 2017 5:05 pm

bogs wrote:
Thu Nov 30, 2017 10:45 pm
I suspect your right...
Really? Come on! 8)

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

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

Post by bogs » Fri Dec 01, 2017 5:39 pm

Klaus wrote:
Fri Dec 01, 2017 5:05 pm
bogs wrote:
Thu Nov 30, 2017 10:45 pm
I 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:
ImageImage

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

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

Post by Klaus » Fri Dec 01, 2017 9:50 pm

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 pm
I 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: 745
Joined: Sat Feb 25, 2017 10:45 pm

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

Post by bogs » Fri Dec 01, 2017 10:33 pm

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:
ImageImage

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2595
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

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

Post by mwieder » Wed Dec 06, 2017 8:51 pm

It's Wednesday already. Did Klaus get paid?

...and stop calling me Shirley.

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

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

Post by bogs » Wed Dec 06, 2017 9:07 pm

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
ImageImage

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

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

Post by Klaus » Wed Dec 06, 2017 9:51 pm

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: 745
Joined: Sat Feb 25, 2017 10:45 pm

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

Post by bogs » Thu Dec 07, 2017 2:34 am

Ugh, and here I thought Popeye was universal.
I am wot I am and thats all wot I am, ugh ugh ugh :lol:
ImageImage

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2595
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

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

Post by mwieder » Thu Dec 07, 2017 2:59 am


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

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

Post by bogs » Thu Dec 07, 2017 4:18 am

Thats the ticket :D
ImageImage

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”