Truncate the Level of the button To next line

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
pkmittal
Posts: 111
Joined: Thu Feb 08, 2007 11:27 am
Contact:

Truncate the Level of the button To next line

Post by pkmittal » Thu Apr 09, 2015 8:11 am

Hi, If the level of the button is long and I want to truncate it to next line (by increasing the height of the width) then how can we do this in live code?

Klaus
Posts: 14267
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Truncate the Level of the button To next line

Post by Klaus » Thu Apr 09, 2015 11:44 am

Hi pkmittal,

I think you mean the LABEL of a button? 8)

You can do this:
1. With the messagebox (or any other script
set the label of btn 1 to ("This is line 1" & CR & "This is line 2 of the label")

2. In the inspector for the button enter BACKSLASH-N \n to add a new line:
This is line 1\nThis is line 2 of the label

Hope I understood you correctly.


Best

Klaus

pkmittal
Posts: 111
Joined: Thu Feb 08, 2007 11:27 am
Contact:

Re: Truncate the Level of the button To next line

Post by pkmittal » Thu Apr 09, 2015 3:17 pm

Thanks. But I want to do it automatically if the label of the button does not fit in the width of the button then it should show the remaining next in new line..

So depending on width of the button, It should show the truncate the label from one line to another line..

Klaus
Posts: 14267
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Truncate the Level of the button To next line

Post by Klaus » Thu Apr 09, 2015 3:19 pm

Ah, get it now! :D
Sorry, no idea how to do that..

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7403
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Truncate the Level of the button To next line

Post by jacque » Thu Apr 09, 2015 7:52 pm

Try this:

Code: Select all

on setLabel pLbl
  set the label of btn 1 to pLbl
  if the formattedwidth of btn 1 > the width of btn 1 then
    put the number of words in pLbl div 2 into tMiddle
    put word 1 to tMiddle of pLbl & cr & word (tMiddle + 1) to -1 of pLbl into pLbl
  end if
  set the label of btn 1 to pLbl
end setLabel
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: Truncate the Level of the button To next line

Post by dunbarx » Thu Apr 09, 2015 8:14 pm

Hi.

Jacque's trick should work. But what if the label requires three or more lines? It may never, but I bet you would get a kick out of writing a general solution, based on her methods.

Craig Newman

pkmittal
Posts: 111
Joined: Thu Feb 08, 2007 11:27 am
Contact:

Re: Truncate the Level of the button To next line

Post by pkmittal » Mon Apr 13, 2015 1:09 pm

Thanks a lot for your help

Post Reply