Name

dragstate — A standard dragging behavior.

Synopsis

LZX: dragstate
JavaScript: dragstate
Type: Class
Access: public
Topic: Components.States
Declared in: lps/components/utils/states/dragstate.lzx

Description

The dragstate is a class which can be used to make any view draggable. When the dragstate is applied, the view with the dragstate will follow the mouse.

Example 52. Simple use of a dragstate

        <canvas width="200" height="100">
            <view bgcolor="blue" width="20" height="20"
                  onmousedown="dragger.apply()" onmouseup="dragger.remove()">
                <dragstate name="dragger"/>
            </view>
        </canvas>
        

Example 53. Horizontal drag

        <canvas width="200" height="100">
            <view bgcolor="red" width="20" height="20"
                  onmousedown="dragger.apply()" onmouseup="dragger.remove()">
                <dragstate name="dragger" drag_axis="x"/>
            </view>
        </canvas>
        

Example 54. Horizontal drag with simple bounds checking

        <canvas width="200" height="100">
            <view bgcolor="red" width="20" height="20"
                  onmousedown="dragger.apply()" onmouseup="dragger.remove()">
                <dragstate name="dragger" drag_axis="x"
                        drag_min_x="0"  drag_max_x="100"/>
            </view>
        </canvas>
        

Example 55. Drag within bounds of parent view

        <canvas width="500" height="350">
            <view bgcolor="blue" x="100" y="40" width="300" height="200">
                <view bgcolor="red" width="20" height="20"
                      onmousedown="dragger.apply()" onmouseup="dragger.remove()">
                    <dragstate name="dragger" drag_axis="both"
                        drag_min_x="0"
                        drag_max_x="$once{parent.width - this.width}"
                        drag_min_y="0"
                        drag_max_y="$once{parent.height - this.height}"/>
                </view>
            </view>
        </canvas>
        

The above example allows the user to drag the red square within the bounds of the larger blue rectangle. Note that as with all states the dragstate's attributes are evaluated in the context of its parent. So to refer to the blue view's width, the example uses parent.width, and to refer to the red square's width, the example uses this.width.

this state provides standard 'drag' functionality to its immediateparent when applied

Superclass Chain

node (LzNode) » state (LzState) » dragstate

Known Subclasses

Details

Properties (7)

drag_axis
<attribute name="drag_axis" type="string" value="both" />
public var drag_axis : String;
'x', 'y' or 'both' , default: both
drag_max_x
<attribute name="drag_max_x" type="number" value="null" />
public var drag_max_x : Number;
the maximum value for the x attribute. Default : null, no maximum
drag_max_y
<attribute name="drag_max_y" type="number" value="null" />
public var drag_max_y : Number;
the maximum value for the y attribute. Default : null, no maximum
drag_min_x
<attribute name="drag_min_x" type="number" value="null" />
public var drag_min_x : Number;
the minimum value for the x attribute. Default : null, no minimum
drag_min_y
<attribute name="drag_min_y" type="number" value="null" />
public var drag_min_y : Number;
the minimum value for the y attribute. Default : null, no minimum
x
<attribute name="x" value="(this.drag_axis == 'both' || this.drag_axis == 'x') ? __dragstate_getnewpos('x', this.immediateparent.getMouse( 'x' ) + this.__dragstate_xdoffset) : this.x" />
public var x;
y
<attribute name="y" value="(this.drag_axis == 'both' || this.drag_axis == 'y') ? __dragstate_getnewpos('y', this.immediateparent.getMouse( 'y' ) + this.__dragstate_ydoffset) : this.y" />
public var y;

LZX Synopsis

<class name="dragstate" extends=" LzState ">
  <attribute name=" drag_axis " type="string" value="both" />
  <attribute name=" drag_max_x " type="number" value="null" />
  <attribute name=" drag_max_y " type="number" value="null" />
  <attribute name=" drag_min_x " type="number" value="null" />
  <attribute name=" drag_min_y " type="number" value="null" />
  <attribute name=" x " value="(this.drag_axis == 'both' || this.drag_axis == 'x') ? __dragstate_getnewpos('x', this.immediateparent.getMouse( 'x' ) + this.__dragstate_xdoffset) : this.x" />
  <attribute name=" y " value="(this.drag_axis == 'both' || this.drag_axis == 'y') ? __dragstate_getnewpos('y', this.immediateparent.getMouse( 'y' ) + this.__dragstate_ydoffset) : this.y" />
</class>

JavaScript Synopsis

public dragstate extends  LzState  {
  public var drag_axis  : String;
  public var drag_max_x  : Number;
  public var drag_max_y  : Number;
  public var drag_min_x  : Number;
  public var drag_min_y  : Number;
  public var x ;
  public var y ;
}