-
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathLayoutGroup.hx
More file actions
987 lines (854 loc) · 29 KB
/
LayoutGroup.hx
File metadata and controls
987 lines (854 loc) · 29 KB
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
/*
Feathers UI
Copyright 2026 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.core.FeathersControl;
import feathers.core.IUIControl;
import feathers.core.IValidating;
import feathers.events.FeathersEvent;
import feathers.layout.AutoSizeMode;
import feathers.layout.ILayout;
import feathers.layout.ILayoutObject;
import feathers.layout.LayoutBoundsResult;
import feathers.layout.Measurements;
import feathers.skins.IProgrammaticSkin;
import feathers.utils.MeasurementsUtil;
import openfl.display.DisplayObject;
import openfl.display.Sprite;
import openfl.errors.RangeError;
import openfl.events.Event;
import openfl.geom.Point;
/**
A generic container that supports layouts and automatically sizes itself
based on its content.
The following example creates a layout group with a horizontal layout and
adds two buttons to it:
```haxe
var group = new LayoutGroup();
var layout = new HorizontalLayout();
layout.gap = 20.0;
layout.padding = 20.0;
group.layout = layout;
this.addChild(group);
var yesButton = new Button();
yesButton.text = "Yes";
group.addChild(yesButton);
var noButton = new Button();
noButton.text = "No";
group.addChild(noButton);
```
@see [Tutorial: How to use the LayoutGroup component](https://feathersui.com/learn/haxe-openfl/layout-group/)
@see `feathers.controls.ScrollContainer` is a layout container that supports scrolling
@since 1.0.0
**/
@defaultXmlProperty("xmlContent")
@:styleContext
class LayoutGroup extends FeathersControl {
/**
A variant used to style the group as a tool bar. Variants allow themes
to provide an assortment of different appearances for the same type of
UI component.
The following example uses this variant:
```haxe
var group = new LayoutGroup();
group.variant = LayoutGroup.VARIANT_TOOL_BAR;
```
@see `feathers.style.IVariantStyleObject.variant`
@see [Feathers UI User Manual: Themes](https://feathersui.com/learn/haxe-openfl/themes/)
@since 1.0.0
**/
public static final VARIANT_TOOL_BAR = "toolBar";
/**
Creates a new `LayoutGroup` object.
@since 1.0.0
**/
public function new() {
initializeLayoutGroupTheme();
super();
this.addEventListener(Event.ADDED_TO_STAGE, layoutGroup_addedToStageHandler);
}
private var items:Array<DisplayObject> = [];
/**
The layout algorithm used to position and size the group's items.
The following example tells the group to use a vertical layout:
```haxe
var layout = new VerticalLayout();
layout.gap = 20.0;
layout.padding = 20.0;
layout.horizontalAlign = CENTER;
group.layout = layout;
```
@since 1.0.0
**/
@:style
public var layout:ILayout = null;
private var _layoutResult:LayoutBoundsResult = new LayoutBoundsResult();
private var _layoutMeasurements:Measurements = new Measurements();
private var _ignoreChildChanges:Bool = false;
private var _ignoreChangesButSetFlags:Bool = false;
private var _ignoreLayoutChanges:Bool = false;
private var _currentBackgroundSkin:DisplayObject = null;
private var _backgroundSkinMeasurements:Measurements = null;
#if flash
private var _ignoreFlashRemovedEvent = false;
#end
/**
The default background skin to display behind all content added to the
group. The background skin is resized to fill the complete width and
height of the group.
The following example passes a bitmap for the layout group to use as a
background skin:
```haxe
group.backgroundSkin = new Bitmap(bitmapData);
```
@default null
@see `LayoutGroup.disabledBackgroundSkin`
@since 1.0.0
**/
@:style
public var backgroundSkin:DisplayObject = null;
/**
The background skin to display behind all content added to the group when
the group is disabled. The background skin is resized to fill the
complete width and height of the group.
The following example gives the group a disabled background skin:
```haxe
group.disabledBackgroundSkin = new Bitmap(bitmapData);
group.enabled = false;
```
@default null
@see `LayoutGroup.backgroundSkin`
@since 1.0.0
**/
@:style
public var disabledBackgroundSkin:DisplayObject = null;
private var _currentMaskSkin:DisplayObject = null;
/**
A skin to mask the content of the layout group. The skin is resized to
the full dimensions of the layout group. It is passed to the `mask`
property.
The following example passes a `RectangleSkin` with a `cornerRadius` for
the layout group's mask skin:
```haxe
var maskSkin = new RectangleSkin();
maskSkin.fill = SolidColor(0xff0000);
maskSkin.cornerRadius = 10.0;
group.maskSkin = maskSkin;
```
@default null
@see [`openfl.display.DisplayObject.mask`](https://api.openfl.org/openfl/display/DisplayObject.html#mask)
@since 1.0.0
**/
@:style
public var maskSkin:DisplayObject = null;
private var _autoSizeMode:AutoSizeMode = CONTENT;
/**
Determines how the layout group will set its own size when its
dimensions (width and height) aren't set explicitly.
In the following example, the layout group will be sized to match the
stage:
```haxe
group.autoSizeMode = STAGE;
```
@see `feathers.layout.AutoSizeMode.STAGE`
@see `feathers.layout.AutoSizeMode.CONTENT`
@since 1.0.0
**/
public var autoSizeMode(get, set):AutoSizeMode;
private function get_autoSizeMode():AutoSizeMode {
return this._autoSizeMode;
}
private function set_autoSizeMode(value:AutoSizeMode):AutoSizeMode {
if (this._autoSizeMode == value) {
return this._autoSizeMode;
}
this._autoSizeMode = value;
this.setInvalid(SIZE);
if (this.stage != null) {
if (this._autoSizeMode == STAGE) {
this.stage.addEventListener(Event.RESIZE, layoutGroup_stage_resizeHandler, false, 0, true);
this.addEventListener(Event.REMOVED_FROM_STAGE, layoutGroup_removedFromStageHandler);
} else {
this.stage.removeEventListener(Event.RESIZE, layoutGroup_stage_resizeHandler);
this.removeEventListener(Event.REMOVED_FROM_STAGE, layoutGroup_removedFromStageHandler);
}
}
return this._autoSizeMode;
}
private var _disabledOverlay:Sprite;
private var _currentLayout:ILayout;
#if (flash && haxe_ver < 4.3) @:getter(numChildren) #else override #end private function get_numChildren():Int {
return this.items.length;
}
private var _numChildren(get, never):Int;
private function get__numChildren():Int {
return super.numChildren;
}
override public function addChildAt(child:DisplayObject, index:Int):DisplayObject {
var oldIndex = this.items.indexOf(child);
if (oldIndex == index) {
return child;
}
// remove from array after calculating private index because when the
// first child is re-added at a higher index, the offset would be wrong
var privateIndex = this.getPrivateIndexForPublicIndex(index);
if (oldIndex >= 0) {
this.items.splice(oldIndex, 1);
}
// insert into the array before adding as a child, so that display list
// APIs work in an Event.ADDED listener
this.items.insert(index, child);
var result = this._addChildAt(child, privateIndex);
// add listeners or access properties after adding a child
// because adding the child may result in better errors (like for null)
child.addEventListener(Event.RESIZE, layoutGroup_child_resizeHandler);
if ((child is ILayoutObject)) {
child.addEventListener(FeathersEvent.LAYOUT_DATA_CHANGE, layoutGroup_child_layoutDataChangeHandler, false, 0, true);
}
#if flash
// in some situations, removal happens automtically without calling our
// overrides, so we need to detect the event that gets dispatched
child.addEventListener(Event.REMOVED, flash_layoutGroup_child_removedHandler);
#end
if (this._ignoreChangesButSetFlags) {
this.setInvalidationFlag(LAYOUT);
} else {
this.setInvalid(LAYOUT);
}
return result;
}
#if flash
override public function addChild(child:DisplayObject):DisplayObject {
return this.addChildAt(child, this.numChildren);
}
#end
private function _addChild(child:DisplayObject):DisplayObject {
return super.addChildAt(child, this._numChildren);
}
private function _addChildAt(child:DisplayObject, index:Int):DisplayObject {
return super.addChildAt(child, index);
}
#if flash
override public function removeChild(child:DisplayObject):DisplayObject {
return this.removeChildInternal(child, true);
}
private function removeChildInternal(child:DisplayObject, removeSuper:Bool):DisplayObject
#else
override public function removeChild(child:DisplayObject):DisplayObject
#end
{
if (child == null || child.parent != this) {
return child;
}
this.items.remove(child);
#if flash
var result = child;
if (removeSuper) {
result = this._removeChild(child);
}
#else
var result = this._removeChild(child);
#end
// remove listeners or access properties after removing a child
// because removing the child may result in better errors (like for null)
child.removeEventListener(Event.RESIZE, layoutGroup_child_resizeHandler);
if ((child is ILayoutObject)) {
child.removeEventListener(FeathersEvent.LAYOUT_DATA_CHANGE, layoutGroup_child_layoutDataChangeHandler);
}
#if flash
child.removeEventListener(Event.REMOVED, flash_layoutGroup_child_removedHandler);
#end
if (this._ignoreChangesButSetFlags) {
this.setInvalidationFlag(LAYOUT);
} else {
this.setInvalid(LAYOUT);
}
return result;
}
private function _removeChild(child:DisplayObject):DisplayObject {
#if flash
var oldIgnoreFlashRemovedEvent = this._ignoreFlashRemovedEvent;
this._ignoreFlashRemovedEvent = true;
var result = super.removeChild(child);
this._ignoreFlashRemovedEvent = oldIgnoreFlashRemovedEvent;
return result;
#else
return super.removeChild(child);
#end
}
override public function removeChildAt(index:Int):DisplayObject {
if (index >= 0 && index < this.items.length) {
return this.removeChild(this.items[index]);
}
return null;
}
private function _removeChildAt(index:Int):DisplayObject {
#if flash
var oldIgnoreFlashRemovedEvent = this._ignoreFlashRemovedEvent;
this._ignoreFlashRemovedEvent = true;
var result = super.removeChildAt(index);
this._ignoreFlashRemovedEvent = oldIgnoreFlashRemovedEvent;
return result;
#else
return super.removeChildAt(index);
#end
}
override public function getChildIndex(child:DisplayObject):Int {
return this.items.indexOf(child);
}
private function _getChildIndex(child:DisplayObject):Int {
return super.getChildIndex(child);
}
override public function getChildByName(name:String):DisplayObject {
for (child in this.items) {
if (child.name == name) {
return child;
}
}
return null;
}
private function _getChildByName(name:String):DisplayObject {
return super.getChildByName(name);
}
override public function removeChildren(beginIndex:Int = 0, endIndex:Int = 0x7FFFFFFF):Void {
if (endIndex == 0x7FFFFFFF) {
endIndex = this.items.length - 1;
if (endIndex < 0) {
return;
}
}
if (beginIndex > this.items.length - 1) {
return;
} else if (endIndex < beginIndex || beginIndex < 0 || endIndex > this.items.length) {
throw new RangeError("The supplied index is out of bounds.");
}
var numRemovals = endIndex - beginIndex;
while (numRemovals >= 0) {
this.removeChildAt(beginIndex);
numRemovals--;
}
}
private function _removeChildren(beginIndex:Int = 0, endIndex:Int = 0x7FFFFFFF):Void {
#if flash
var oldIgnoreFlashRemovedEvent = this._ignoreFlashRemovedEvent;
this._ignoreFlashRemovedEvent = true;
super.removeChildren(beginIndex, endIndex);
this._ignoreFlashRemovedEvent = oldIgnoreFlashRemovedEvent;
#else
super.removeChildren(beginIndex, endIndex);
#end
}
override public function setChildIndex(child:DisplayObject, index:Int):Void {
var oldIndex = this.getChildIndex(child);
if (oldIndex == index) {
// nothing to change
return;
}
this._setChildIndex(child, this.getPrivateIndexForPublicIndex(index));
this.items.remove(child);
this.items.insert(index, child);
if (this._ignoreChangesButSetFlags) {
this.setInvalidationFlag(LAYOUT);
} else {
this.setInvalid(LAYOUT);
}
}
private function _setChildIndex(child:DisplayObject, index:Int):Void {
super.setChildIndex(child, index);
}
override public function getChildAt(index:Int):DisplayObject {
return this.items[index];
}
private function _getChildAt(index:Int):DisplayObject {
return super.getChildAt(index);
}
/**
Readjusts the layout of the group according to its current content.
Call this method when changes to the content cannot be automatically
detected by the container. For instance, Feathers UI components dispatch
`Event.RESIZE` when their `width` and `height` values change, but
standard OpenFL display objects like `Sprite` do not.
@since 1.3.0
**/
public function readjustLayout():Void {
this.setInvalid(LAYOUT);
}
private function initializeLayoutGroupTheme():Void {
#if !feathersui_disable_default_theme
feathers.themes.steel.components.SteelLayoutGroupStyles.initialize();
#end
}
private function getPrivateIndexForPublicIndex(publicIndex:Int):Int {
if (this.items.length > 0) {
return publicIndex + this._getChildIndex(this.items[0]);
} else if (this._numChildren > 0) {
return publicIndex + this._numChildren;
}
return publicIndex;
}
private var _xmlContent:Array<DisplayObject> = null;
@:dox(hide)
@:noCompletion
public var xmlContent(get, set):Array<DisplayObject>;
private function get_xmlContent():Array<DisplayObject> {
return this._xmlContent;
}
private function set_xmlContent(value:Array<DisplayObject>):Array<DisplayObject> {
if (this._xmlContent == value) {
return this._xmlContent;
}
if (this._xmlContent != null) {
for (child in this._xmlContent) {
this.removeChild(child);
}
}
this._xmlContent = value;
if (this._xmlContent != null) {
for (child in this._xmlContent) {
this.addChild(child);
}
}
this.setInvalid(STYLES);
return this._xmlContent;
}
private var _layoutActive = false;
private var _layoutChanged = false;
/**
Collects all children in an array.
@since 1.3.0
**/
public function collectChildren(result:Array<DisplayObject> = null):Array<DisplayObject> {
if (result == null) {
return this.items.copy();
}
for (item in this.items) {
result.push(item);
}
return result;
}
override public function validateNow():Void {
// for the start of validation, we're going to ignore when children
// resize or dispatch changes to layout data. this allows subclasses
// to modify children in draw() before the layout is applied.
var oldIgnoreChildChanges = this._ignoreChangesButSetFlags;
this._ignoreChangesButSetFlags = true;
super.validateNow();
// if super.validateNow() returns without calling update(), the flag
// won't be reset before layout is called, so we need reset manually.
this._ignoreChangesButSetFlags = oldIgnoreChildChanges;
}
override private function update():Void {
// children are allowed to change during update() in a subclass up
// until it calls super.update().
this._ignoreChangesButSetFlags = false;
var layoutInvalid = this.isInvalid(LAYOUT);
var sizeInvalid = this.isInvalid(SIZE);
var stylesInvalid = this.isInvalid(STYLES);
var stateInvalid = this.isInvalid(STATE);
if (stylesInvalid || stateInvalid) {
this.refreshBackgroundSkin();
}
if (stylesInvalid) {
this.refreshMaskSkin();
this.refreshLayout();
}
if (sizeInvalid || layoutInvalid || stylesInvalid || stateInvalid) {
this.refreshViewPortBounds();
// if a layout needs another pass because an assumption has changed,
// allow it to dispatch Event.CHANGE, and run again, but don't let
// it get into an infinite loop.
this.runWithInvalidationFlagsOnly(() -> {
this._layoutActive = true;
var loopCount = 0;
do {
this._layoutChanged = false;
this.handleLayout();
loopCount++;
if (loopCount >= 10) {
this._layoutActive = false;
var className = Type.getClassName(Type.getClass(this));
var layoutClassName = this.layout != null ? Type.getClassName(Type.getClass(this.layout)) : "The layout";
throw new openfl.errors.IllegalOperationError('${className} is stuck in an infinite loop during layout. ${layoutClassName} may be dispatching Event.CHANGE too frequently.');
}
} while (this._layoutChanged);
this._layoutActive = false;
});
this.refreshBackgroundLayout();
this.refreshDisabledOverlay();
this.refreshMaskLayout();
// final invalidation to avoid juggler next frame issues
this.validateChildren();
}
}
private function refreshDisabledOverlay():Void {
if (!this._enabled) {
if (this._disabledOverlay == null) {
this._disabledOverlay = new Sprite();
this._disabledOverlay.graphics.beginFill(0xff00ff, 0.0);
this._disabledOverlay.graphics.drawRect(0.0, 0.0, 1.0, 1.0);
this._disabledOverlay.graphics.endFill();
this._addChild(this._disabledOverlay);
} else {
this._setChildIndex(this._disabledOverlay, this._numChildren - 1);
}
}
if (this._disabledOverlay != null) {
this._disabledOverlay.visible = !this._enabled;
this._disabledOverlay.x = 0.0;
this._disabledOverlay.y = 0.0;
this._disabledOverlay.width = this.actualWidth;
this._disabledOverlay.height = this.actualHeight;
}
}
private function refreshLayout():Void {
var newLayout = this.layout;
if (this._currentLayout == newLayout) {
return;
}
if (this._currentLayout != null) {
this._currentLayout.removeEventListener(Event.CHANGE, layoutGroup_layout_changeHandler);
}
this._currentLayout = newLayout;
if (this._currentLayout != null) {
this._currentLayout.addEventListener(Event.CHANGE, layoutGroup_layout_changeHandler);
}
}
private function refreshBackgroundSkin():Void {
var oldSkin = this._currentBackgroundSkin;
this._currentBackgroundSkin = this.getCurrentBackgroundSkin();
if (this._currentBackgroundSkin == oldSkin) {
return;
}
this.removeCurrentBackgroundSkin(oldSkin);
this.addCurrentBackgroundSkin(this._currentBackgroundSkin);
}
private function getCurrentBackgroundSkin():DisplayObject {
if (!this._enabled && this.disabledBackgroundSkin != null) {
return this.disabledBackgroundSkin;
}
return this.backgroundSkin;
}
private function addCurrentBackgroundSkin(skin:DisplayObject):Void {
if (skin == null) {
this._backgroundSkinMeasurements = null;
return;
}
if ((skin is IUIControl)) {
(cast skin : IUIControl).initializeNow();
}
if (this._backgroundSkinMeasurements == null) {
this._backgroundSkinMeasurements = new Measurements(skin);
} else {
this._backgroundSkinMeasurements.save(skin);
}
if ((skin is IProgrammaticSkin)) {
(cast skin : IProgrammaticSkin).uiContext = this;
}
this._addChildAt(skin, 0);
}
private function removeCurrentBackgroundSkin(skin:DisplayObject):Void {
if (skin == null) {
return;
}
if ((skin is IProgrammaticSkin)) {
(cast skin : IProgrammaticSkin).uiContext = null;
}
// we need to restore these values so that they won't be lost the
// next time that this skin is used for measurement
this._backgroundSkinMeasurements.restore(skin);
if (skin.parent == this) {
this._removeChild(skin);
}
}
private function refreshMaskSkin():Void {
var oldSkin = this._currentMaskSkin;
this._currentMaskSkin = this.getCurrentMaskSkin();
if (this._currentMaskSkin == oldSkin) {
return;
}
this.removeCurrentMaskSkin(oldSkin);
this.addCurrentMaskSkin(this._currentMaskSkin);
}
private function getCurrentMaskSkin():DisplayObject {
return this.maskSkin;
}
private function addCurrentMaskSkin(skin:DisplayObject):Void {
if (skin == null) {
return;
}
if ((skin is IUIControl)) {
(cast skin : IUIControl).initializeNow();
}
if ((skin is IProgrammaticSkin)) {
(cast skin : IProgrammaticSkin).uiContext = this;
}
this._addChild(skin);
this.mask = skin;
}
private function removeCurrentMaskSkin(skin:DisplayObject):Void {
if (skin == null) {
return;
}
if ((skin is IProgrammaticSkin)) {
(cast skin : IProgrammaticSkin).uiContext = null;
}
if (skin.parent == this) {
this._removeChild(skin);
}
this.mask = null;
}
private function refreshViewPortBounds():Void {
var needsWidth = this.explicitWidth == null;
var needsHeight = this.explicitHeight == null;
var needsMinWidth = this.explicitMinWidth == null;
var needsMinHeight = this.explicitMinHeight == null;
var needsMaxWidth = this.explicitMaxWidth == null;
var needsMaxHeight = this.explicitMaxHeight == null;
if (this._currentBackgroundSkin != null) {
MeasurementsUtil.resetFluidlyWithParent(this._backgroundSkinMeasurements, this._currentBackgroundSkin, this);
if ((this._currentBackgroundSkin is IValidating)) {
(cast this._currentBackgroundSkin : IValidating).validateNow();
}
}
var needsToMeasureContent = this._autoSizeMode == CONTENT || this.stage == null;
var stageWidth:Float = 0.0;
var stageHeight:Float = 0.0;
if (!needsToMeasureContent) {
// TODO: see if this can be done without allocations
var topLeft = this.globalToLocal(new Point());
var bottomRight = this.globalToLocal(new Point(this.stage.stageWidth, this.stage.stageHeight));
stageWidth = bottomRight.x - topLeft.x;
stageHeight = bottomRight.y - topLeft.y;
}
if (needsWidth && !needsToMeasureContent) {
this._layoutMeasurements.width = stageWidth;
} else {
this._layoutMeasurements.width = this.explicitWidth;
}
if (needsHeight && !needsToMeasureContent) {
this._layoutMeasurements.height = stageHeight;
} else {
this._layoutMeasurements.height = this.explicitHeight;
}
var viewPortMinWidth = this.explicitMinWidth;
if (needsMinWidth) {
viewPortMinWidth = 0.0;
}
var viewPortMinHeight = this.explicitMinHeight;
if (needsMinHeight) {
viewPortMinHeight = 0.0;
}
var viewPortMaxWidth = this.explicitMaxWidth;
if (needsMaxWidth) {
viewPortMaxWidth = 1.0 / 0.0; // Math.POSITIVE_INFINITY bug workaround for swf
}
var viewPortMaxHeight = this.explicitMaxHeight;
if (needsMaxHeight) {
viewPortMaxHeight = 1.0 / 0.0; // Math.POSITIVE_INFINITY bug workaround for swf
}
if (this._backgroundSkinMeasurements != null) {
// because the layout might need it, we account for the
// dimensions of the background skin when determining the minimum
// dimensions of the view port.
if (this._backgroundSkinMeasurements.width != null) {
if (this._backgroundSkinMeasurements.width > viewPortMinWidth) {
viewPortMinWidth = this._backgroundSkinMeasurements.width;
}
} else if (this._backgroundSkinMeasurements.minWidth != null) {
if (this._backgroundSkinMeasurements.minWidth > viewPortMinWidth) {
viewPortMinWidth = this._backgroundSkinMeasurements.minWidth;
}
}
if (this._backgroundSkinMeasurements.height != null) {
if (this._backgroundSkinMeasurements.height > viewPortMinHeight) {
viewPortMinHeight = this._backgroundSkinMeasurements.height;
}
} else if (this._backgroundSkinMeasurements.minHeight != null) {
if (this._backgroundSkinMeasurements.minHeight > viewPortMinHeight) {
viewPortMinHeight = this._backgroundSkinMeasurements.minHeight;
}
}
}
this._layoutMeasurements.minWidth = viewPortMinWidth;
this._layoutMeasurements.minHeight = viewPortMinHeight;
this._layoutMeasurements.maxWidth = viewPortMaxWidth;
this._layoutMeasurements.maxHeight = viewPortMaxHeight;
}
private function handleLayout():Void {
if (this._currentLayout != null) {
this.handleCustomLayout();
} else {
this.handleManualLayout();
}
this.handleLayoutResult();
}
private function handleCustomLayout():Void {
var oldIgnoreChildChanges = this._ignoreChildChanges;
this._ignoreChildChanges = true;
this._layoutResult.reset();
this._currentLayout.layout(this.items, this._layoutMeasurements, this._layoutResult);
this._ignoreChildChanges = oldIgnoreChildChanges;
}
private function handleManualLayout():Void {
var maxX = this._layoutMeasurements.width;
if (maxX == null) {
maxX = 0.0;
}
var maxY = this._layoutMeasurements.height;
if (maxY == null) {
maxY = 0.0;
}
var oldIgnoreChildChanges = this._ignoreChildChanges;
this._ignoreChildChanges = true;
for (item in this.items) {
if ((item is ILayoutObject) && !(cast item : ILayoutObject).includeInLayout) {
continue;
}
if ((item is IValidating)) {
(cast item : IValidating).validateNow();
}
var itemMaxX = item.x + item.width;
var itemMaxY = item.y + item.height;
if (maxX < itemMaxX) {
maxX = itemMaxX;
}
if (maxY < itemMaxY) {
maxY = itemMaxY;
}
}
this._ignoreChildChanges = oldIgnoreChildChanges;
this._layoutResult.contentX = 0.0;
this._layoutResult.contentY = 0.0;
this._layoutResult.contentWidth = maxX;
this._layoutResult.contentHeight = maxY;
if (this._layoutMeasurements.width != null) {
this._layoutResult.viewPortWidth = this._layoutMeasurements.width;
} else {
if (this._layoutMeasurements.minWidth != null && maxX < this._layoutMeasurements.minWidth) {
maxX = this._layoutMeasurements.minWidth;
} else if (this._layoutMeasurements.maxWidth != null && maxX > this._layoutMeasurements.maxWidth) {
maxX = this._layoutMeasurements.maxWidth;
}
this._layoutResult.viewPortWidth = maxX;
}
if (this._layoutMeasurements.height != null) {
this._layoutResult.viewPortHeight = this._layoutMeasurements.height;
} else {
if (this._layoutMeasurements.minHeight != null && maxY < this._layoutMeasurements.minHeight) {
maxY = this._layoutMeasurements.minHeight;
} else if (this._layoutMeasurements.maxHeight != null && maxY > this._layoutMeasurements.maxHeight) {
maxY = this._layoutMeasurements.maxHeight;
}
this._layoutResult.viewPortHeight = maxY;
}
}
private function handleLayoutResult():Void {
var viewPortWidth = this._layoutResult.viewPortWidth;
var viewPortHeight = this._layoutResult.viewPortHeight;
this.saveMeasurements(viewPortWidth, viewPortHeight, viewPortWidth, viewPortHeight);
}
private function refreshMaskLayout():Void {
if (this._currentMaskSkin == null) {
return;
}
this._currentMaskSkin.x = 0.0;
this._currentMaskSkin.y = 0.0;
this._currentMaskSkin.width = this.actualWidth;
this._currentMaskSkin.height = this.actualHeight;
if ((this._currentMaskSkin is IValidating)) {
(cast this._currentMaskSkin : IValidating).validateNow();
}
}
private function refreshBackgroundLayout():Void {
if (this._currentBackgroundSkin == null) {
return;
}
this._currentBackgroundSkin.x = 0.0;
this._currentBackgroundSkin.y = 0.0;
// don't set the width or height explicitly unless necessary because if
// our explicit dimensions are cleared later, the measurement may not be
// accurate anymore
if (this._currentBackgroundSkin.width != this.actualWidth) {
this._currentBackgroundSkin.width = this.actualWidth;
}
if (this._currentBackgroundSkin.height != this.actualHeight) {
this._currentBackgroundSkin.height = this.actualHeight;
}
if ((this._currentBackgroundSkin is IValidating)) {
(cast this._currentBackgroundSkin : IValidating).validateNow();
}
}
private function validateChildren():Void {
if ((this._currentBackgroundSkin is IValidating)) {
(cast this._currentBackgroundSkin : IValidating).validateNow();
}
for (item in this.items) {
if ((item is IValidating)) {
(cast item : IValidating).validateNow();
}
}
}
private function layoutGroup_addedToStageHandler(event:Event):Void {
if (this._autoSizeMode == STAGE) {
// if we validated before being added to the stage, or if we've
// been removed from stage and added again, we need to be sure
// that the new stage dimensions are accounted for.
this.setInvalid(SIZE);
this.addEventListener(Event.REMOVED_FROM_STAGE, layoutGroup_removedFromStageHandler);
this.stage.addEventListener(Event.RESIZE, layoutGroup_stage_resizeHandler, false, 0, true);
}
}
private function layoutGroup_removedFromStageHandler(event:Event):Void {
this.removeEventListener(Event.REMOVED_FROM_STAGE, layoutGroup_removedFromStageHandler);
this.stage.removeEventListener(Event.RESIZE, layoutGroup_stage_resizeHandler);
}
private function layoutGroup_stage_resizeHandler(event:Event):Void {
this.setInvalid(SIZE);
}
private function layoutGroup_child_resizeHandler(event:Event):Void {
if (this._ignoreChildChanges) {
return;
}
if (this._ignoreChangesButSetFlags) {
this.setInvalidationFlag(LAYOUT);
return;
}
this.setInvalid(LAYOUT);
}
private function layoutGroup_child_layoutDataChangeHandler(event:Event):Void {
if (this._ignoreChildChanges) {
return;
}
if (this._ignoreChangesButSetFlags) {
this.setInvalidationFlag(LAYOUT);
return;
}
this.setInvalid(LAYOUT);
}
private function layoutGroup_layout_changeHandler(event:Event):Void {
if (this._ignoreLayoutChanges) {
return;
}
if (this._layoutActive) {
this._layoutChanged = true;
return;
}
if (this._ignoreChangesButSetFlags) {
this.setInvalidationFlag(LAYOUT);
return;
}
this.setInvalid(LAYOUT);
}
#if flash
private function flash_layoutGroup_child_removedHandler(event:Event):Void {
if (this._ignoreFlashRemovedEvent || event.target != event.currentTarget) {
return;
}
var child = cast(event.currentTarget, DisplayObject);
this.removeChildInternal(child, false);
}
#end
}