maxiMin (was: here's a challenge)

FlexibleLearning at aol.com FlexibleLearning at aol.com
Fri Aug 29 01:55:01 EDT 2003


In a message dated 28/08/2003 10:19:35 PM GMT Daylight Time, 
use-revolution-request at lists.runrev.com writes:
> Thanks to Dar, Sarah, and Monte for a solution to this.  I was able to use 
a
> combination of your suggestions to make it work.  If anyone is interested,
> here's my final script for this:
> 
> on mouseMove pMouseH, pMouseV
 > -- only if we're timing
>  if the cTiming of this stack and the cShowGuide of this stack then
>   put (pMouseV - the top of fld "myText" + the margins of fld "myText") \
> div (the textHeight of fld "myText") into tLineNum
>   if tLineNum is 0 then
>    put 1 into tLineNum
>   end if
>   if tLineNum >(the height of fld "myText" div the textHeight of fld
> "myText") then
>    put (the height of fld "myText" div the textHeight of fld "myText")
> into tLineNum
>   end if
>   set the top of grc "ReadingGuide" to the top of fld "myText" + \
>     (the margins of fld "myText" div 2) + (the textHeight of fld
> "myText" * (tLineNum-1))
>  end if


Small point: the above needs "the effective textHeight" to avoid an inherited 
empty textHeight and a div.zero error.

A one-liner version is...

set the top of grc "ReadingGuide" to max(the top of fld "myText", min(the 
bottom of fld "myText",item 2 of the mouseLoc))

TIP:
max (a, min (b, var) ) ... is a useful general constraining algorithm for all 
sorts of things where the minimum value is "a" and the maximum value is "b" 
and the changing value is "var". Useful, for example, in a stack resize with 
minWidth and maxWidth, or ensuring an object lies between two values like the 
left of the card and the right of the card. Or when any value has an upper and 
lower limit. Also very powerful when used in conjuction with setProp.

/H

_________________________________________________
Hugh Senior
The Flexible Learning Company
Consultant Programming & Software Solutions
Fax/Voice: +44 (0)1483.27 87 27
Email: mailto:h at flexibleLearning.com
Web: www.flexibleLearning.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.runrev.com/pipermail/use-livecode/attachments/20030829/bdce2837/attachment.html>


More information about the use-livecode mailing list