Setting the WIDTH of a button to accommodate its text

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
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9417
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Setting the WIDTH of a button to accommodate its text

Post by richmond62 » Wed Nov 15, 2023 11:13 am

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

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

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

Post by Klaus » Wed Nov 15, 2023 11:30 am

Hi richmind,

Code: Select all

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

Klaus

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9417
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

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

Post by richmond62 » Wed Nov 15, 2023 12:03 pm

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.

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

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

Post by Klaus » Wed Nov 15, 2023 12:12 pm

Then you are licked! :-D

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9417
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

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

Post by richmond62 » Wed Nov 15, 2023 12:33 pm

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.
Attachments
Lick Me Too.livecode.zip
Stack
(1.72 KiB) Downloaded 44 times

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

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

Post by Klaus » Wed Nov 15, 2023 1:10 pm

Yeah, that's what I wanted to see! :-)

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9417
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

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

Post by richmond62 » Wed Nov 15, 2023 4:30 pm

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 6778 times
-
Screenshot 2023-11-15 at 17.35.08.jpg

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9417
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

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

Post by richmond62 » Wed Nov 15, 2023 4:54 pm

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 6772 times
-

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

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9417
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

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

Post by richmond62 » Wed Nov 15, 2023 5:15 pm

Sugar:
-
Screenshot 2023-11-15 at 18.14.30.png

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”