-
Notifications
You must be signed in to change notification settings - Fork 385
/
Drawers.as
3858 lines (3631 loc) · 103 KB
/
Drawers.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Feathers
Copyright 2012-2015 Bowler Hat LLC. All Rights Reserved.
This program is free software. You can redistribute and/or modify it in
accordance with the terms of the accompanying license agreement.
*/
package feathers.controls
{
import feathers.controls.supportClasses.BaseScreenNavigator;
import feathers.core.FeathersControl;
import feathers.core.IValidating;
import feathers.events.ExclusiveTouch;
import feathers.events.FeathersEventType;
import feathers.skins.IStyleProvider;
import feathers.system.DeviceCapabilities;
import feathers.utils.display.getDisplayObjectDepthFromStage;
import feathers.utils.math.roundToNearest;
import flash.events.KeyboardEvent;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.ui.Keyboard;
import flash.utils.getTimer;
import starling.animation.Transitions;
import starling.animation.Tween;
import starling.core.Starling;
import starling.display.DisplayObject;
import starling.display.DisplayObjectContainer;
import starling.display.Sprite;
import starling.display.Stage;
import starling.events.Event;
import starling.events.EventDispatcher;
import starling.events.ResizeEvent;
import starling.events.Touch;
import starling.events.TouchEvent;
import starling.events.TouchPhase;
/**
* Dispatched when the user starts dragging the content to open or close a
* drawer.
*
* <p>The properties of the event object have the following values:</p>
* <table class="innertable">
* <tr><th>Property</th><th>Value</th></tr>
* <tr><td><code>bubbles</code></td><td>false</td></tr>
* <tr><td><code>currentTarget</code></td><td>The Object that defines the
* event listener that handles the event. For example, if you use
* <code>myButton.addEventListener()</code> to register an event listener,
* myButton is the value of the <code>currentTarget</code>.</td></tr>
* <tr><td><code>data</code></td><td>null</td></tr>
* <tr><td><code>target</code></td><td>The Object that dispatched the event;
* it is not always the Object listening for the event. Use the
* <code>currentTarget</code> property to always access the Object
* listening for the event.</td></tr>
* </table>
*
* @eventType feathers.events.FeathersEventType.BEGIN_INTERACTION
* @see #event:endInteraction feathers.events.FeathersEventType.END_INTERACTION
*/
[Event(name="beginInteraction",type="starling.events.Event")]
/**
* Dispatched when the user stops dragging the content to open or close a
* drawer. The drawer may continue opening or closing after this event is
* dispatched if the user interaction has also triggered an animation.
*
* <p>The properties of the event object have the following values:</p>
* <table class="innertable">
* <tr><th>Property</th><th>Value</th></tr>
* <tr><td><code>bubbles</code></td><td>false</td></tr>
* <tr><td><code>currentTarget</code></td><td>The Object that defines the
* event listener that handles the event. For example, if you use
* <code>myButton.addEventListener()</code> to register an event listener,
* myButton is the value of the <code>currentTarget</code>.</td></tr>
* <tr><td><code>data</code></td><td>null</td></tr>
* <tr><td><code>target</code></td><td>The Object that dispatched the event;
* it is not always the Object listening for the event. Use the
* <code>currentTarget</code> property to always access the Object
* listening for the event.</td></tr>
* </table>
*
* @eventType feathers.events.FeathersEventType.END_INTERACTION
* @see #event:beginInteraction feathers.events.FeathersEventType.BEGIN_INTERACTION
*/
[Event(name="endInteraction",type="starling.events.Event")]
/**
* Dispatched when a drawer has completed opening. The <code>data</code>
* property of the event indicates which drawer is open.
*
* <p>The properties of the event object have the following values:</p>
* <table class="innertable">
* <tr><th>Property</th><th>Value</th></tr>
* <tr><td><code>bubbles</code></td><td>false</td></tr>
* <tr><td><code>currentTarget</code></td><td>The Object that defines the
* event listener that handles the event. For example, if you use
* <code>myButton.addEventListener()</code> to register an event listener,
* myButton is the value of the <code>currentTarget</code>.</td></tr>
* <tr><td><code>data</code></td><td>The drawer that was opened.</td></tr>
* <tr><td><code>target</code></td><td>The Object that dispatched the event;
* it is not always the Object listening for the event. Use the
* <code>currentTarget</code> property to always access the Object
* listening for the event.</td></tr>
* </table>
*
* @eventType starling.events.Event.OPEN
* @see #event:close starling.events.Event.CLOSE
*/
[Event(name="open",type="starling.events.Event")]
/**
* Dispatched when a drawer has completed closing. The <code>data</code>
* property of the event indicates which drawer was closed.
*
* <p>The properties of the event object have the following values:</p>
* <table class="innertable">
* <tr><th>Property</th><th>Value</th></tr>
* <tr><td><code>bubbles</code></td><td>false</td></tr>
* <tr><td><code>currentTarget</code></td><td>The Object that defines the
* event listener that handles the event. For example, if you use
* <code>myButton.addEventListener()</code> to register an event listener,
* myButton is the value of the <code>currentTarget</code>.</td></tr>
* <tr><td><code>data</code></td><td>The drawer that was closed.</td></tr>
* <tr><td><code>target</code></td><td>The Object that dispatched the event;
* it is not always the Object listening for the event. Use the
* <code>currentTarget</code> property to always access the Object
* listening for the event.</td></tr>
* </table>
*
* @eventType starling.events.Event.CLOSE
* @see #event:open starling.events.Event.OPEN
*/
[Event(name="close",type="starling.events.Event")]
/**
* A container that displays primary content in the center surrounded by
* optional "drawers" that can open and close on the edges. Useful for
* mobile-style app menus that slide open from the side of the screen.
*
* <p>Additionally, each drawer may be individually "docked" in an
* always-open state, making this a useful application-level layout
* container even if the drawers never need to be hidden. Docking behavior
* may be limited to either portrait or landscape, or a drawer may be docked
* in both orientations. By default, a drawer is not docked.</p>
*
* <p>The following example creates an app with a slide out menu to the
* left of the main content:</p>
*
* <listing version="3.0">
* var navigator:StackScreenNavigator = new StackScreenNavigator();
* var list:List = new List();
* // the navigator's screens, the list's data provider, and additional
* // properties should be set here.
*
* var drawers:Drawers = new Drawers();
* drawers.content = navigator;
* drawers.leftDrawer = menu;
* drawers.leftDrawerToggleEventType = Event.OPEN;
* this.addChild( drawers );</listing>
*
* <p>In the example above, a screen in the <code>StackScreenNavigator</code>
* component dispatches an event of type <code>Event.OPEN</code> when it
* wants to display the slide out the <code>List</code> that is used as
* the left drawer.</p>
*
* @see ../../../help/drawers.html How to use the Feathers Drawers component
*/
public class Drawers extends FeathersControl
{
/**
* The default <code>IStyleProvider</code> for all <code>Drawers</code>
* components.
*
* @default null
* @see feathers.core.FeathersControl#styleProvider
*/
public static var globalStyleProvider:IStyleProvider;
/**
* The drawer will be docked in portrait orientation, but it must be
* opened and closed explicitly in landscape orientation.
*
* @see #topDrawerDockMode
* @see #rightDrawerDockMode
* @see #bottomDrawerDockMode
* @see #leftDrawerDockMode
* @see #isTopDrawerDocked
* @see #isRightDrawerDocked
* @see #isBottomDrawerDocked
* @see #isLeftDrawerDocked
*/
public static const DOCK_MODE_PORTRAIT:String = "portrait";
/**
* The drawer will be docked in landscape orientation, but it must be
* opened and closed explicitly in portrait orientation.
*
* @see #topDrawerDockMode
* @see #rightDrawerDockMode
* @see #bottomDrawerDockMode
* @see #leftDrawerDockMode
* @see #isTopDrawerDocked
* @see #isRightDrawerDocked
* @see #isBottomDrawerDocked
* @see #isLeftDrawerDocked
*/
public static const DOCK_MODE_LANDSCAPE:String = "landscape";
/**
* The drawer will be docked in all orientations.
*
* @see #topDrawerDockMode
* @see #rightDrawerDockMode
* @see #bottomDrawerDockMode
* @see #leftDrawerDockMode
* @see #isTopDrawerDocked
* @see #isRightDrawerDocked
* @see #isBottomDrawerDocked
* @see #isLeftDrawerDocked
*/
public static const DOCK_MODE_BOTH:String = "both";
/**
* The drawer won't be docked in any orientation. It must be opened and
* closed explicitly in all orientations.
*
* @see #topDrawerDockMode
* @see #rightDrawerDockMode
* @see #bottomDrawerDockMode
* @see #leftDrawerDockMode
* @see #isTopDrawerDocked
* @see #isRightDrawerDocked
* @see #isBottomDrawerDocked
* @see #isLeftDrawerDocked
*/
public static const DOCK_MODE_NONE:String = "none";
/**
* The drawers container will auto size itself to fill the entire stage.
*
* @see #autoSizeMode
*/
public static const AUTO_SIZE_MODE_STAGE:String = "stage";
/**
* The drawers container will auto size itself to fit its content.
*
* @see #autoSizeMode
*/
public static const AUTO_SIZE_MODE_CONTENT:String = "content";
/**
* A drawer will open by dragging the content starting from a certain
* physical distance (in inches) from the nearest edge of the content.
* To customize this distance, use the <code>openGestureDragContentEdgeDistance</code>
* property.
*
* @see #openGesture
* @see openGestureEdgeSize
*/
public static const OPEN_GESTURE_DRAG_CONTENT_EDGE:String = "dragContentEdge";
/**
* A drawer will open by dragging the content from any location in the
* appropriate direction.
*
* @see #openGesture
*/
public static const OPEN_GESTURE_DRAG_CONTENT:String = "dragContent";
/**
* The drawers container will only open using the toggle event types
* dispatched by the content. No gesture can be used to open a drawer.
*
* @see #openGesture
* @see #topDrawerToggleEventType
* @see #rightDrawerToggleEventType
* @see #bottomDrawerToggleEventType
* @see #leftDrawerToggleEventType
*/
public static const OPEN_GESTURE_NONE:String = "none";
/**
* The field used to access the "content event dispatcher" of a
* <code>ScreenNavigator</code> component, which happens to be the
* currently active screen.
*
* @see #contentEventDispatcherField
* @see feathers.controls.ScreenNavigator
*/
protected static const SCREEN_NAVIGATOR_CONTENT_EVENT_DISPATCHER_FIELD:String = "activeScreen";
/**
* @private
* The current velocity is given high importance.
*/
private static const CURRENT_VELOCITY_WEIGHT:Number = 2.33;
/**
* @private
* Older saved velocities are given less importance.
*/
private static const VELOCITY_WEIGHTS:Vector.<Number> = new <Number>[1, 1.33, 1.66, 2];
/**
* @private
*/
private static const MAXIMUM_SAVED_VELOCITY_COUNT:int = 4;
/**
* @private
*/
private static const HELPER_POINT:Point = new Point();
/**
* Constructor.
*/
public function Drawers(content:DisplayObject = null)
{
super();
this.content = content;
this.addEventListener(Event.ADDED_TO_STAGE, drawers_addedToStageHandler);
this.addEventListener(Event.REMOVED_FROM_STAGE, drawers_removedFromStageHandler);
this.addEventListener(TouchEvent.TOUCH, drawers_touchHandler);
}
/**
* The event dispatcher that controls opening and closing drawers with
* events. Often, the event dispatcher is the content itself, but you
* may specify a <code>contentEventDispatcherField</code> to access a
* property of the content instead, or you may specify a
* <code>contentEventDispatcherFunction</code> to run some more complex
* code to access the event dispatcher.
*
* @see #contentEventDispatcherField
* @see #contentEventDispatcherFunction
*/
protected var contentEventDispatcher:EventDispatcher;
/**
* @private
*/
override protected function get defaultStyleProvider():IStyleProvider
{
return Drawers.globalStyleProvider;
}
/**
* @private
*/
protected var _content:DisplayObject;
/**
* The primary content displayed in the center of the container.
*
* <p>If the primary content is a container where you'd prefer to listen
* to events from its children, you may need to use properties like
* <code>contentEventDispatcherField</code>, <code>contentEventDispatcherFunction</code>,
* and <code>contentEventDispatcherChangeEventType</code> to ensure that
* open and close events for drawers are correctly mapped to the correct
* event dispatcher. If the content is dispatching the events, then those
* properties should be set to <code>null</code>.</p>
*
* <p>In the following example, a <code>ScreenNavigator</code> is added
* as the content:</p>
*
* <listing version="3.0">
* var navigator:ScreenNavigator = new ScreenNavigator();
* // additional code to add the screens can go here
* drawers.content = navigator;</listing>
*
* @default null
*
* @see #contentEventDispatcherField
* @see #contentEventDispatcherFunction
* @see #contentEventDispatcherChangeEventType
*/
public function get content():DisplayObject
{
return this._content
}
/**
* @private
*/
public function set content(value:DisplayObject):void
{
if(this._content == value)
{
return;
}
if(this._content)
{
if(this._contentEventDispatcherChangeEventType)
{
this._content.removeEventListener(this._contentEventDispatcherChangeEventType, content_eventDispatcherChangeHandler);
}
this._content.removeEventListener(FeathersEventType.RESIZE, content_resizeHandler);
if(this._content.parent == this)
{
this.removeChild(this._content, false);
}
}
this._content = value;
if(this._content)
{
if(this._content is BaseScreenNavigator)
{
this.contentEventDispatcherField = SCREEN_NAVIGATOR_CONTENT_EVENT_DISPATCHER_FIELD;
this.contentEventDispatcherChangeEventType = Event.CHANGE;
}
if(this._contentEventDispatcherChangeEventType)
{
this._content.addEventListener(this._contentEventDispatcherChangeEventType, content_eventDispatcherChangeHandler);
}
if(this._autoSizeMode == AUTO_SIZE_MODE_CONTENT || !this.stage)
{
this._content.addEventListener(FeathersEventType.RESIZE, content_resizeHandler);
}
//the content should appear under the overlay skin, if it exists
if(this._overlaySkin)
{
this.addChildAt(this._content, this.getChildIndex(this._overlaySkin));
}
else
{
this.addChild(this._content);
}
}
this.invalidate(INVALIDATION_FLAG_DATA);
}
/**
* @private
*/
protected var _overlaySkinOriginalAlpha:Number = 1;
/**
* @private
*/
protected var _overlaySkin:DisplayObject;
/**
* An optional display object that appears above the content when a
* drawer is open.
*
* <p>In the following example, a <code>Quad</code> is added as the
* overlay skin:</p>
*
* <listing version="3.0">
* var skin:Quad = new Quad( 10, 10, 0x000000 );
* skin.alpha = 0.75;
* drawers.overlaySkin = skin;</listing>
*
* @default null
*/
public function get overlaySkin():DisplayObject
{
return this._overlaySkin
}
/**
* @private
*/
public function set overlaySkin(value:DisplayObject):void
{
if(this._overlaySkin == value)
{
return;
}
if(this._overlaySkin && this._overlaySkin.parent == this)
{
this.removeChild(this._overlaySkin, false);
}
this._overlaySkin = value;
if(this._overlaySkin)
{
this._overlaySkinOriginalAlpha = this._overlaySkin.alpha;
this._overlaySkin.visible = this.isTopDrawerOpen || this.isRightDrawerOpen || this.isBottomDrawerOpen || this.isLeftDrawerOpen;
this.addChild(this._overlaySkin);
}
this.invalidate(INVALIDATION_FLAG_DATA);
}
/**
* @private
*/
protected var _topDrawer:DisplayObject;
/**
* The drawer that appears above the primary content.
*
* <p>In the following example, a <code>List</code> is added as the
* top drawer:</p>
*
* <listing version="3.0">
* var list:List = new List();
* // set data provider and other properties here
* drawers.topDrawer = list;</listing>
*
* @default null
*
* @see #topDrawerDockMode
* @see #topDrawerToggleEventType
*/
public function get topDrawer():DisplayObject
{
return this._topDrawer
}
/**
* @private
*/
public function set topDrawer(value:DisplayObject):void
{
if(this._topDrawer == value)
{
return;
}
if(this._topDrawer && this._topDrawer.parent == this)
{
this.removeChild(this._topDrawer, false);
}
this._topDrawer = value;
if(this._topDrawer)
{
this._topDrawer.visible = false;
this._topDrawer.addEventListener(FeathersEventType.RESIZE, drawer_resizeHandler);
this.addChildAt(this._topDrawer, 0);
}
this.invalidate(INVALIDATION_FLAG_DATA);
}
/**
* @private
*/
protected var _topDrawerDockMode:String = DOCK_MODE_NONE;
[Inspectable(type="String",enumeration="portrait,landscape,both,none")]
/**
* Determines if the top drawer is docked in all, some, or no stage
* orientations. The current stage orientation is determined by
* calculating the aspect ratio of the stage.
*
* <p>In the following example, the top drawer is docked in the
* landscape stage orientation:</p>
*
* <listing version="3.0">
* drawers.topDrawerDockMode = Drawers.DOCK_MODE_LANDSCAPE;</listing>
*
* @default Drawers.DOCK_MODE_NONE
*
* @see #DOCK_MODE_PORTRAIT
* @see #DOCK_MODE_LANDSCAPE
* @see #DOCK_MODE_NONE
* @see #DOCK_MODE_BOTH
* @see #topDrawer
*/
public function get topDrawerDockMode():String
{
return this._topDrawerDockMode;
}
/**
* @private
*/
public function set topDrawerDockMode(value:String):void
{
if(this._topDrawerDockMode == value)
{
return;
}
this._topDrawerDockMode = value;
this.invalidate(INVALIDATION_FLAG_LAYOUT);
}
/**
* @private
*/
protected var _topDrawerToggleEventType:String;
/**
* When this event is dispatched by the content event dispatcher, the
* top drawer will toggle open and closed.
*
* <p>In the following example, the top drawer is toggled when the
* content dispatches an event of type <code>Event.OPEN</code>:</p>
*
* <listing version="3.0">
* drawers.topDrawerToggleEventType = Event.OPEN;</listing>
*
* @default null
*
* @see #content
* @see #topDrawer
*/
public function get topDrawerToggleEventType():String
{
return this._topDrawerToggleEventType;
}
/**
* @private
*/
public function set topDrawerToggleEventType(value:String):void
{
if(this._topDrawerToggleEventType == value)
{
return;
}
if(this.contentEventDispatcher && this._topDrawerToggleEventType)
{
this.contentEventDispatcher.removeEventListener(this._topDrawerToggleEventType, content_topDrawerToggleEventTypeHandler);
}
this._topDrawerToggleEventType = value;
if(this.contentEventDispatcher && this._topDrawerToggleEventType)
{
this.contentEventDispatcher.addEventListener(this._topDrawerToggleEventType, content_topDrawerToggleEventTypeHandler);
}
}
/**
* @private
*/
protected var _isTopDrawerOpen:Boolean = false;
/**
* Indicates if the top drawer is currently open. If you want to check
* if the top drawer is docked, check <code>isTopDrawerDocked</code>
* instead.
*
* <p>To animate the top drawer open or closed, call
* <code>toggleTopDrawer()</code>. Setting <code>isTopDrawerOpen</code>
* will open or close the top drawer without animation.</p>
*
* <p>In the following example, we check if the top drawer is open:</p>
*
* <listing version="3.0">
* if( drawers.isTopDrawerOpen )
* {
* // do something
* }</listing>
*
* @default false
*
* @see #isTopDrawerDocked
* @see #topDrawer
* @see #toggleTopDrawer()
*/
public function get isTopDrawerOpen():Boolean
{
return this._topDrawer && this._isTopDrawerOpen;
}
/**
* @private
*/
public function set isTopDrawerOpen(value:Boolean):void
{
if(this.isTopDrawerDocked || this._isTopDrawerOpen == value)
{
return;
}
this._isTopDrawerOpen = value;
this.invalidate(INVALIDATION_FLAG_SELECTED);
}
/**
* Indicates if the top drawer is currently docked. Docking behavior of
* the top drawer is controlled with the <code>topDrawerDockMode</code>
* property. To check if the top drawer is open, but not docked, use
* the <code>isTopDrawerOpen</code> property.
*
* @see #topDrawer
* @see #topDrawerDockMode
* @see #isTopDrawerOpen
*/
public function get isTopDrawerDocked():Boolean
{
if(!this._topDrawer)
{
return false;
}
if(this._topDrawerDockMode == DOCK_MODE_BOTH)
{
return true;
}
if(this._topDrawerDockMode == DOCK_MODE_NONE)
{
return false;
}
var stage:Stage = this.stage;
if(!stage)
{
//fall back to the current stage, but it may be wrong...
stage = Starling.current.stage;
}
if(stage.stageWidth > stage.stageHeight)
{
return this._topDrawerDockMode == DOCK_MODE_LANDSCAPE;
}
return this._topDrawerDockMode == DOCK_MODE_PORTRAIT;
}
/**
* @private
*/
protected var _rightDrawer:DisplayObject;
/**
* The drawer that appears to the right of the primary content.
*
* <p>In the following example, a <code>List</code> is added as the
* right drawer:</p>
*
* <listing version="3.0">
* var list:List = new List();
* // set data provider and other properties here
* drawers.rightDrawer = list;</listing>
*
* @default null
*
* @see #rightDrawerDockMode
* @see #rightDrawerToggleEventType
*/
public function get rightDrawer():DisplayObject
{
return this._rightDrawer
}
/**
* @private
*/
public function set rightDrawer(value:DisplayObject):void
{
if(this._rightDrawer == value)
{
return;
}
if(this._rightDrawer && this._rightDrawer.parent == this)
{
this.removeChild(this._rightDrawer, false);
}
this._rightDrawer = value;
if(this._rightDrawer)
{
this._rightDrawer.visible = false;
this._rightDrawer.addEventListener(FeathersEventType.RESIZE, drawer_resizeHandler);
this.addChildAt(this._rightDrawer, 0);
}
this.invalidate(INVALIDATION_FLAG_DATA);
}
/**
* @private
*/
protected var _rightDrawerDockMode:String = DOCK_MODE_NONE;
[Inspectable(type="String",enumeration="portrait,landscape,both,none")]
/**
* Determines if the right drawer is docked in all, some, or no stage
* orientations. The current stage orientation is determined by
* calculating the aspect ratio of the stage.
*
* <p>In the following example, the right drawer is docked in the
* landscape stage orientation:</p>
*
* <listing version="3.0">
* drawers.rightDrawerDockMode = Drawers.DOCK_MODE_LANDSCAPE;</listing>
*
* @default Drawers.DOCK_MODE_NONE
*
* @see #DOCK_MODE_PORTRAIT
* @see #DOCK_MODE_LANDSCAPE
* @see #DOCK_MODE_NONE
* @see #DOCK_MODE_BOTH
* @see #rightDrawer
*/
public function get rightDrawerDockMode():String
{
return this._rightDrawerDockMode;
}
/**
* @private
*/
public function set rightDrawerDockMode(value:String):void
{
if(this._rightDrawerDockMode == value)
{
return;
}
this._rightDrawerDockMode = value;
this.invalidate(INVALIDATION_FLAG_LAYOUT);
}
/**
* @private
*/
protected var _rightDrawerToggleEventType:String;
/**
* When this event is dispatched by the content event dispatcher, the
* right drawer will toggle open and closed.
*
* <p>In the following example, the right drawer is toggled when the
* content dispatches an event of type <code>Event.OPEN</code>:</p>
*
* <listing version="3.0">
* drawers.rightDrawerToggleEventType = Event.OPEN;</listing>
*
* @default null
*
* @see #content
* @see #rightDrawer
*/
public function get rightDrawerToggleEventType():String
{
return this._rightDrawerToggleEventType;
}
/**
* @private
*/
public function set rightDrawerToggleEventType(value:String):void
{
if(this._rightDrawerToggleEventType == value)
{
return;
}
if(this.contentEventDispatcher && this._rightDrawerToggleEventType)
{
this.contentEventDispatcher.removeEventListener(this._rightDrawerToggleEventType, content_rightDrawerToggleEventTypeHandler);
}
this._rightDrawerToggleEventType = value;
if(this.contentEventDispatcher && this._rightDrawerToggleEventType)
{
this.contentEventDispatcher.addEventListener(this._rightDrawerToggleEventType, content_rightDrawerToggleEventTypeHandler);
}
}
/**
* @private
*/
protected var _isRightDrawerOpen:Boolean = false;
/**
* Indicates if the right drawer is currently open. If you want to check
* if the right drawer is docked, check <code>isRightDrawerDocked</code>
* instead.
*
* <p>To animate the right drawer open or closed, call
* <code>toggleRightDrawer()</code>. Setting <code>isRightDrawerOpen</code>
* will open or close the right drawer without animation.</p>
*
* <p>In the following example, we check if the right drawer is open:</p>
*
* <listing version="3.0">
* if( drawers.isRightDrawerOpen )
* {
* // do something
* }</listing>
*
* @default false
*
* @see #rightDrawer
* @see #rightDrawerDockMode
* @see #toggleRightDrawer()
*/
public function get isRightDrawerOpen():Boolean
{
return this._rightDrawer && this._isRightDrawerOpen;
}
/**
* @private
*/
public function set isRightDrawerOpen(value:Boolean):void
{
if(this.isRightDrawerDocked || this._isRightDrawerOpen == value)
{
return;
}
this._isRightDrawerOpen = value;
this.invalidate(INVALIDATION_FLAG_SELECTED);
}
/**
* Indicates if the right drawer is currently docked. Docking behavior of
* the right drawer is controlled with the <code>rightDrawerDockMode</code>
* property. To check if the right drawer is open, but not docked, use
* the <code>isRightDrawerOpen</code> property.
*
* @see #rightDrawer
* @see #rightDrawerDockMode
* @see #isRightDrawerOpen
*/
public function get isRightDrawerDocked():Boolean
{
if(!this._rightDrawer)
{
return false;
}
if(this._rightDrawerDockMode == DOCK_MODE_BOTH)
{
return true;
}
if(this._rightDrawerDockMode == DOCK_MODE_NONE)
{
return false;
}
var stage:Stage = this.stage;
if(!stage)
{
//fall back to the current stage, but it may be wrong...
stage = Starling.current.stage;
}
if(stage.stageWidth > stage.stageHeight)
{
return this._rightDrawerDockMode == DOCK_MODE_LANDSCAPE;
}
return this._rightDrawerDockMode == DOCK_MODE_PORTRAIT;
}
/**
* @private
*/
protected var _bottomDrawer:DisplayObject;
/**
* The drawer that appears below the primary content.
*
* <p>In the following example, a <code>List</code> is added as the
* bottom drawer:</p>
*
* <listing version="3.0">
* var list:List = new List();
* // set data provider and other properties here
* drawers.bottomDrawer = list;</listing>
*
* @default null
*
* @see #bottomDrawerDockMode
* @see #bottomDrawerToggleEventType
*/
public function get bottomDrawer():DisplayObject
{
return this._bottomDrawer
}
/**
* @private
*/
public function set bottomDrawer(value:DisplayObject):void
{
if(this._bottomDrawer == value)
{
return;
}
if(this._bottomDrawer && this._bottomDrawer.parent == this)
{
this.removeChild(this._bottomDrawer, false);
}
this._bottomDrawer = value;
if(this._bottomDrawer)
{
this._bottomDrawer.visible = false;
this._bottomDrawer.addEventListener(FeathersEventType.RESIZE, drawer_resizeHandler);
this.addChildAt(this._bottomDrawer, 0);
}
this.invalidate(INVALIDATION_FLAG_DATA);
}
/**
* @private
*/
protected var _bottomDrawerDockMode:String = DOCK_MODE_NONE;
[Inspectable(type="String",enumeration="portrait,landscape,both,none")]
/**
* Determines if the bottom drawer is docked in all, some, or no stage
* orientations. The current stage orientation is determined by
* calculating the aspect ratio of the stage.
*
* <p>In the following example, the bottom drawer is docked in the
* landscape stage orientation:</p>
*
* <listing version="3.0">
* drawers.bottomDrawerDockMode = Drawers.DOCK_MODE_LANDSCAPE;</listing>
*
* @default Drawers.DOCK_MODE_NONE
*
* @see #DOCK_MODE_PORTRAIT
* @see #DOCK_MODE_LANDSCAPE
* @see #DOCK_MODE_NONE
* @see #DOCK_MODE_BOTH
* @see #bottomDrawer
*/