Fit Content from a script

Eric Chatonet eric.chatonet at sosmartsoftware.com
Fri May 27 04:07:09 EDT 2005


Hi Glen,

It was late yesterday when I answer your first question.
So I did it very quickly without any details...

As for your new request, you could try something like:

   set the width of fld "Site" to the width of img "Tower" -- set the  
width first
   set the height of fld "Site" to the formattedHeight of fld "Site"  
-- the formattedHeight depends on the width
   set the left of fld "Site" to the left of img "Tower" -- align by  
left
   set the top of fld "Site" to the bottom of img "Tower" + 1 -- or  
whatever you need

Don't use the rect property but set the height to the formattedHeight  
after having set the width you desire.
Then move the field to the correct location according to the location  
of the image.

BTW with a rect, item 1 to 2 are the topLeft coordinates (x,y) of the  
rect, item 3 to 4 are the bottomRight coordinates of the rect.
So if you put item 4 of any rect into item 2 of this rect, the height  
of the object will be zero!
More: if you set the bottom of any object higher than its top (yes,  
you can), the visible property of this object will be true but you  
will not see it ;-)

Check top, left, right, bottom, top, bottomLeft, topRight, loc, rect,  
height, width, formattedHeight and formattedWidth in the docs...

Best regards from Paris,

Eric Chatonet.

Le 27 mai 05 à 01:07, Glen Bojsza a écrit :

> Thanks, it works but now I am trying to adjust the height as well
> because of how the fld gets set (I thought you could set the rect of a
> fld without its height or width changing?
>
> I have an image and a field.
>
> I want to have the field position below the image via script so:
>
> set the loc of fld "Site" to the loc of image "Tower" -- centers  
> both objects
> put the rect of fld "Site" into tnewPoints
> put item 4 of the rect of the image Tower into item 2 of tnewPoints
> set the rect of fld "Site" to tnewPoints -- this causes the height of
> the fld Site to shrink to 1??
> set the height of the fld "Site" to the formattedheight of fld "Site"
> -- which still isn't perfect in postion
> set the width of fld "Site" to the formattedwidth of fld "Site" --
> this works since the rect info on width hasn't changed
>
> Is there a better way? How can you script  the Distribute command -
> edge to edge (this is in essence of what I am trying to accomplish)
>
>
> On 5/26/05, Jeanne A. E. DeVoto <revolution at jaedworks.com> wrote:
>
>> At 5:42 PM -0400 5/26/05, Glen Bojsza wrote:
>>
>>> I have several fields that get created from a script and I want to
>>> also have the fields size from a script  the same way as "Fit  
>>> Content"
>>> works the size and position menu.
>>>
>>> There is no "Fit Content" command so is there another way to  
>>> script this?
>>>
>>
>> Like this:
>>
>>    set the height of field "Whatever" to the formattedHeight of  
>> field "Whatever"
>>
>> You'll probably want to check whether the field is empty and whether
>> its formattedHeight is larger than the card's height.
>>
>> If the field is a single line and shouldn't wrap, you'll want to set
>> its width. The best way is to set its width to a maximum and then set
>> it to the formattedWidth:
>>
>>    set the width of field "Whatever" to the width of this stack
>>    set the width of field "Whatever" to the formattedWidth of field
>> "Whatever" -- shrinks if necessary
>>
>> This is because the formattedWidth takes word-wrap into account.

----------------------------------------------------------------
So Smart Software

For institutions, companies and associations
Built-to-order applications: management, multimedia, internet, etc.
Windows, Mac OS and Linux... With the French touch

Plugins, tutorials and more on our website
----------------------------------------------------------------
Web site        http://www.sosmartsoftware.com/
Email        eric.chatonet at sosmartsoftware.com/
Phone        33 (0)1 43 31 77 62
Mobile        33 (0)6 20 74 50 86
----------------------------------------------------------------



More information about the use-livecode mailing list