66use php \gui \framework \behaviour \custom \AbstractBehaviour ;
77use php \gui \UXDialog ;
88use php \gui \UXNode ;
9+ use php \gui \UXWindow ;
910use php \util \SharedValue ;
1011use script \TimerScript ;
1112
@@ -31,45 +32,49 @@ class DraggingFormBehaviour extends AbstractBehaviour
3132 */
3233 protected function applyImpl ($ target )
3334 {
35+ if ($ target instanceof UXWindow) {
36+ $ target = $ target ->layout ;
37+ }
38+
3439 if ($ target instanceof UXNode) {
3540 $ pos = new SharedValue (null );
3641
37- $ target ->on ('mouseDown ' , function (UXMouseEvent $ e ) use ($ pos ) {
42+ $ target ->on ('mouseDown ' , function (UXMouseEvent $ e ) use ($ pos, $ target ) {
3843 if (!$ this ->enabled ) {
3944 return ;
4045 }
4146
4247 if ($ e ->button == 'PRIMARY ' ) {
4348 if ($ this ->opacityEnabled ) {
4449 if ($ this ->animated ) {
45- Animation::fadeTo ($ this -> _target ->form , 300 , $ this ->opacity );
50+ Animation::fadeTo ($ target ->form , 300 , $ this ->opacity );
4651 } else {
47- $ this -> _target ->form ->opacity = $ this ->opacity ;
52+ $ target ->form ->opacity = $ this ->opacity ;
4853 }
4954 }
5055
51- $ pos ->set ([$ e ->screenX - $ this -> _target -> form ->x , $ e ->screenY - $ this -> _target ->form ->y ]);
56+ $ pos ->set ([$ e ->screenX - $ target -> form ->x , $ e ->screenY - $ target ->form ->y ]);
5257 }
5358 }, __CLASS__ );
5459
55- $ move = function (UXMouseEvent $ e )use ($ pos ) {
60+ $ move = function (UXMouseEvent $ e )use ($ pos, $ target ) {
5661 if ($ pos ->get ()) {
57- $ this -> _target ->form ->x = $ e ->screenX - $ pos ->get ()[0 ];
58- $ this -> _target ->form ->y = $ e ->screenY - $ pos ->get ()[1 ];
62+ $ target ->form ->x = $ e ->screenX - $ pos ->get ()[0 ];
63+ $ target ->form ->y = $ e ->screenY - $ pos ->get ()[1 ];
5964 }
6065 };
6166
6267 $ target ->on ('mouseDrag ' , $ move , __CLASS__ );
6368
64- $ target ->on ('mouseUp ' , function (UXMouseEvent $ e ) use ($ pos ) {
69+ $ target ->on ('mouseUp ' , function (UXMouseEvent $ e ) use ($ pos, $ target ) {
6570 if ($ e ->button == 'PRIMARY ' ) {
6671 $ pos ->remove ();
6772
6873 if ($ this ->opacityEnabled ) {
6974 if ($ this ->animated ) {
70- Animation::fadeTo ($ this -> _target ->form , 300 , 1 );
75+ Animation::fadeTo ($ target ->form , 300 , 1 );
7176 } else {
72- $ this -> _target ->form ->opacity = 1 ;
77+ $ target ->form ->opacity = 1 ;
7378 }
7479 }
7580 }
0 commit comments