View Full Version : constraining <dragstate/> properties
girardjf
02-04-2003, 04:30 PM
Is there a recommended method of constraining the draggable area using <dragstate/>?
I need to constrain the x and y to the length and height of a resource, and i don't see any "max" or "min" attributes in the documentation. Maybe i have to write a custom method? Or do I use the "xdoffset" and "ydoffset" attributes to set the constraints?
if anyone has any info please let me know.
-j
antun
02-04-2003, 04:42 PM
Hey Justin
I've always used a custom method. Have a look at the slider code here:-
http://www.laszlosystems.com/developers/community/forums/showthread.php?s=&threadid=65#post162
It was constrained to stay between the minimum and maximum of its range. Of course this method does not use the <dragstate> at all, but rather uses a delegate.
-Antun
girardjf
02-04-2003, 04:44 PM
Thanks Antun.
-j
If you look at the debugger source code
WEB-INF/lps/components/debugger/debugger.lzx
you will see some code to handle setting limits on
the width and height and x and y values of the debugger
window.
First of all, the setWidth, etc methods are overridden:
<!-- METHODS -->
<method name="setWidth" args="w" >
super.setWidth( Math.max( 340 , Math.min( w , canvas.width) ) );
</method>
<method name="setHeight" args="h" >
super.setHeight( Math.max( 125 , Math.min( h , canvas.height) ) );
if (!_dbg_isLoading) {
this.middle.content.updateDisplay();
}
</method>
<method name="setX" args="x" >
super.setX( Math.max( 0-(this.width-10), Math.min( x , canvas.width - 4) ) );
</method>
<method name="setY" args="y" >
super.setY( Math.max( 0 , Math.min( y , canvas.height - 4) ) );
</method>
And then, the drag state and resize states are
hooked up:
<dragstate name="drag" />
<resizestate name="resize" />
...
...
<view name="top" width="parent.width">
<view name="background" width="parent.width"
onmouseover="grabber.setResourceNumber(2)"
onmouseout="grabber.setResourceNumber(1)"
onmousedown="debug.bringToFront(); parent.parent.drag.apply()"
onmouseup="parent.parent.drag.remove()">
...
...
this is the resizer control in the lower right
<view resource="resizer_rsc" name="resizer" pixellock="true"
y="parent.height - 11"
x="parent.width - 11"
onmouseover="this.setResourceNumber(2);"
onmouseout="this.setResourceNumber(1);"
onmousedown="this.setResourceNumber(2); debug.bringToFront(); debug.resize.apply()"
onmouseup="this.setResourceNumber(1); debug.resize.remove()"
/>
girardjf
02-04-2003, 05:39 PM
Antun,
Thanks again. I'll take a look at the code. However I don't really understand how the <dragstate/> tag is used in conjunction with the class overrides, because it doesn't look like any methods are being called. I guess I'll just take a look at it.
Will there be a simpler method of setting these constraints in the future? This seems awfully complicated for constraining dragging to a specific x and y.
Thanks,
-j
The code I posted is different from the code that Antun posted. The stuff I posted is designed to work with the drag state and resize state. It does not require using delegates or anything.
The drag state automatically calls setX and setY, and the resize state automatically calls setWidth and setHeight, so you just have to override those methods and add in whatever limits you want.
girardjf
02-04-2003, 06:21 PM
Sorry, i didn't even realize someone else posted that reply as I'm so used to having Antun respond. Thanks for the clarification.
In my case all i need to override would be the x and y, constraining the y to a single value and setting a maximum for the x.I assume one of the two parameters for both x and y sets the limit. Just out of cursosity, is the default limit of <dragstate/> the width and height of the canvas?
Thanks again for the clarification. I didn't realize that setX and setY were called by <dragstate/>.
-j
I don't think there are any built in limit params on dragstate or resizestate, at this time. I'll make a wishlist feature request if there isn't one already.
girardjf
02-04-2003, 06:31 PM
That would be great for the a future releas, although this is much less complicated now that i know the full extent of how the overrides were being used.
Thanks again.
-j
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.