Page 1 of 1

Setting the WIDTH of a button to accommodate its text

Posted: Wed Nov 15, 2023 11:13 am
by richmond62
I should like to have a button where an end-user can set its label: now, obviously, if that label is longer than the width of the button the whole thing will look daft:
-
Screenshot 2023-11-15 at 12.11.31.png
-
So, I should like to know, how, when my theoretical end-user sets a label for a button the button can widen (or narrow) to accommodate that label programmatically.
-
Screenshot 2023-11-15 at 12.11.55.png

Re: Setting the WIDTH of a button to accommodate its text

Posted: Wed Nov 15, 2023 11:30 am
by Klaus
Hi richmind,

Code: Select all

set the width of btn 1 to the formattedwidth of btn 1
Best

Klaus

Re: Setting the WIDTH of a button to accommodate its text

Posted: Wed Nov 15, 2023 12:03 pm
by richmond62
Thanks.

The ONLY problem is that I am messing around with a rectangular graphic as a fake button: and I don't suppose that has a formattedWidth.

Re: Setting the WIDTH of a button to accommodate its text

Posted: Wed Nov 15, 2023 12:12 pm
by Klaus
Then you are licked! :-D

Re: Setting the WIDTH of a button to accommodate its text

Posted: Wed Nov 15, 2023 12:33 pm
by richmond62
No: I am not!

Code: Select all

on resizeControl
   set the height of img "aqua" to the height of me
   set the backGroundPattern of me to the id of img "aqua"
   set the loc of img "aqua" to the loc of me
   set the loc btn "bHOLDER" to the loc of me
   set the textSize of me to ((the height of me)/2)
   set the textSize of btn "bHOLDER" to ((the height of me)/2)
   set the label of btn "bHOLDER" to the short name of me
   set the width of btn "bHOLDER" to the formattedWidth of btn "bHOLDER"
   set the height of btn "bHOLDER" to the formattedHeight of btn "bHOLDER"
   set the width of me to ((the formattedWidth of btn "bHOLDER") + 20)
   set the loc btn "bHOLDER" to the loc of me
end resizeControl
The image 'aqua' and the button 'bHOLDER' are invisible.

Re: Setting the WIDTH of a button to accommodate its text

Posted: Wed Nov 15, 2023 1:10 pm
by Klaus
Yeah, that's what I wanted to see! :-)

Re: Setting the WIDTH of a button to accommodate its text

Posted: Wed Nov 15, 2023 4:30 pm
by richmond62
This whole experiment came about when I realised that for some bloody bad reason there seems to be no way to set rounding of a button's corners:
-
lickMe3.jpg
-
As soon as a button is made larger than the size at which it comes off the Tools palette its corners go square.
-
Screenshot 2023-11-15 at 17.31.42.png
Screenshot 2023-11-15 at 17.31.42.png (102.88 KiB) Viewed 8750 times
-
Screenshot 2023-11-15 at 17.35.08.jpg

Re: Setting the WIDTH of a button to accommodate its text

Posted: Wed Nov 15, 2023 4:54 pm
by richmond62
While one CAN set the style of a button to 'rounded corners' the cornerRadius cannot be adjusted:
-
Screenshot 2023-11-15 at 17.52.20.png
Screenshot 2023-11-15 at 17.52.20.png (52.84 KiB) Viewed 8744 times
-

https://forums.livecode.com/viewtopic.php?t=18944

Re: Setting the WIDTH of a button to accommodate its text

Posted: Wed Nov 15, 2023 5:15 pm
by richmond62
Sugar:
-
Screenshot 2023-11-15 at 18.14.30.png