Contracting text to a fixed width
hibis.jmr
hibis.jmr at free.fr
Thu Feb 22 03:24:03 EST 2007
Terry,
thinking different :
on contractTextOfField FieldToContract
if there is a fld "SoOn" then delete fld "SoOn"
if the formattedwidth of fld FieldToContract>the width of fld
FieldToContract then
lock screen
clone field FieldToContract
set the name of the last field to "SoOn"
put "..." into field "SoOn"
set the borderWidth of fld "SoOn" to 0
set the width of fld "SoOn" to the formattedwidth of fld "SoOn"-the
borderWidth of fld FieldToContract
set the height of fld "SoOn" to the height of fld "SoOn" -2*the
borderWidth of fld FieldToContract
set the opaque of fld "SoOn" to true
set the topRight of fld "SoOn" to the Right of fld
FieldToContract-the borderWidth of fld FieldToContract,the top of fld
FieldToContract+the borderWidth of fld FieldToContract
end if
end contractTextOfField
Jean-Marc
Le 22 févr. 2007, à 06:18, Terry Judd a écrit :
> I'm looking for a way to contract unwrapped lines of text to a fixed
> width -
> primarily for use in a table where the width of columns is
> variable/adjustable and often narrower than the text each 'cell'
> contains. I
> reckon a trailing ellipsis added to the contracted text would look
> satisfactory and managed to come up with the following routine that
> uses an
> intermediate field...
>
> function contractTextToWidth theText,theWidth
> lock screen
> put "..." into fld "CTTW"
> put the formattedWidth of char 1 to 3 of fld "CTTW" into tWidthA
> -- tWidthA = width of trailing ellipsis
> repeat with i = length(theText) down to 1
> put theText into fld "CTTW"
> put the formattedWidth of char 1 to i of fld "CTTW" into tWidthB
> -- tWidthB = width of remaining string
> if tWidthA+tWidthB <= theWidth then
> return theText&"..."
> exit repeat
> end if
> delete last char of theText
> end repeat
> unlock screen
> end contractTextToWidth
>
> ... But I'm thinking there's probably a better way (particularly when
> lots
> of cells are involved - I might end up with a couple of hundred). Any
> ideas?
>
> Terry...
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
More information about the use-livecode
mailing list