-
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathFormItem.hx
More file actions
1573 lines (1343 loc) · 45.3 KB
/
FormItem.hx
File metadata and controls
1573 lines (1343 loc) · 45.3 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
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
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.IFocusManagerAware;
import feathers.core.IFocusObject;
import feathers.core.IMeasureObject;
import feathers.core.ITextControl;
import feathers.core.IUIControl;
import feathers.core.IValidating;
import feathers.events.FeathersEvent;
import feathers.layout.HorizontalAlign;
import feathers.layout.Measurements;
import feathers.layout.RelativePosition;
import feathers.layout.VerticalAlign;
import feathers.skins.IProgrammaticSkin;
import feathers.text.TextFormat;
import feathers.utils.MeasurementsUtil;
import openfl.display.DisplayObject;
import openfl.errors.ArgumentError;
import openfl.events.Event;
import openfl.events.MouseEvent;
import openfl.text.AntiAliasType;
import openfl.text.GridFitType;
import openfl.text.TextField;
#if (openfl >= "9.2.0")
import openfl.text.StyleSheet;
#elseif flash
import flash.text.StyleSheet;
#end
/**
Displays text next to a control in a form.
@see `feathers.controls.Form`
@see [Tutorial: How to use the Form and FormItem components](https://feathersui.com/learn/haxe-openfl/form/)
@since 1.0.0
**/
@defaultXmlProperty("content")
@:styleContext
class FormItem extends FeathersControl implements ITextControl implements IFocusManagerAware {
/**
Creates a new `FormItem` object.
@since 1.0.0
**/
public function new(text:String = "", ?content:DisplayObject, required:Bool = false) {
initializeFormItemTheme();
super();
this.text = text;
this.content = content;
this.required = required;
}
private var textField:TextField;
private var _previousText:String = null;
private var _previousHTMLText:String = null;
private var _previousTextFormat:TextFormat = null;
private var _previousSimpleTextFormat:openfl.text.TextFormat = null;
private var _updatedTextStyles = false;
private var _textMeasuredWidth:Float;
private var _textMeasuredHeight:Float;
private var _wrappedOnMeasure:Bool = false;
private var _text:String;
/**
The text displayed by the form item.
The following example sets the form item's text:
```haxe
formItem.text = "Address";
```
@default ""
@see `FormItem.textFormat`
@since 1.0.0
**/
@:inspectable
public var text(get, set):String;
private function get_text():String {
return this._text;
}
private function set_text(value:String):String {
if (value == null) {
// null gets converted to an empty string
if (this._text.length == 0) {
// already an empty string
return this._text;
}
value = "";
}
if (this._text == value) {
return this._text;
}
this._text = value;
this.setInvalid(DATA);
if (this._customTextColumnWidth != null && (this.textPosition == LEFT || this.textPosition == RIGHT)) {
// ensure that form updates its layout because this change could
// affect other form items too
FeathersEvent.dispatch(this, Event.RESIZE);
}
return this._text;
}
private var _htmlText:String = null;
/**
Text displayed by the label that is parsed as a simple form of HTML.
The following example sets the label's HTML text:
```haxe
label.htmlText = "<b>Hello</b> <i>World</i>";
```
@default null
@see `Label.text`
@see [`openfl.text.TextField.htmlText`](https://api.openfl.org/openfl/text/TextField.html#htmlText)
@since 1.0.0
**/
public var htmlText(get, set):String;
private function get_htmlText():String {
return this._htmlText;
}
private function set_htmlText(value:String):String {
if (this._htmlText == value) {
return this._htmlText;
}
this._htmlText = value;
this.setInvalid(DATA);
return this._htmlText;
}
/**
@see `feathers.core.ITextControl.baseline`
**/
public var baseline(get, never):Float;
private function get_baseline():Float {
if (this.textField == null) {
return 0.0;
}
var textFieldBaseline = 0.0;
// usually, hasText doesn't check the length, but TextField height may
// not be accurate with an empty string
var hasText = this._text != null && this._text.length > 0;
var hasHTMLText = this._htmlText != null && this._htmlText.length > 0;
if (hasText || hasHTMLText) {
textFieldBaseline = this.textField.y + this.textField.getLineMetrics(0).ascent;
} else {
this.textField.text = "\u200b";
textFieldBaseline = this.textField.y + this.textField.getLineMetrics(0).ascent;
this.textField.text = "";
}
var contentBaseline = 0.0;
if ((this._currentContent is ITextControl)) {
contentBaseline = this._currentContent.y + (cast this._currentContent : ITextControl).baseline;
}
return Math.max(textFieldBaseline, contentBaseline);
}
private var _contentMeasurements:Measurements = null;
private var _currentContent:DisplayObject = null;
private var _ignoreContentResize:Bool = false;
private var _content:DisplayObject;
/**
The content displayed by the form item.
The following example sets the form item's content:
```haxe
var nameInput = new TextInput();
nameInput.prompt = "First and last name";
formItem.content = nameInput;
```
@see `FormItem.text`
@since 1.0.0
**/
public var content(get, set):DisplayObject;
private function get_content():DisplayObject {
return this._content;
}
private function set_content(value:DisplayObject):DisplayObject {
if (this._content == value) {
return this._content;
}
if (this._content != null) {
this._content.removeEventListener(Event.RESIZE, formItem_content_resizeHandler);
}
this._content = value;
if (this._content != null) {
this._content.addEventListener(Event.RESIZE, formItem_content_resizeHandler, false, 0, true);
}
this.setInvalid(DATA);
return this._content;
}
private var _selectable:Bool = false;
/**
Indicates if the form item's text may be selected or not.
In the following example, the form item's text is selectable:
```haxe
formItem.selectable = true;
```
@since 1.0.0
**/
public var selectable(get, set):Bool;
private function get_selectable():Bool {
return this._selectable;
}
private function set_selectable(value:Bool):Bool {
if (this._selectable == value) {
return this._selectable;
}
this._selectable = value;
this.setInvalid(SELECTION);
return this._selectable;
}
/**
The start index of the selection.
If `selectable` is `false`, returns `-1`.
@since 1.0.0
**/
public var selectionBeginIndex(get, never):Int;
private function get_selectionBeginIndex():Int {
if (!this._selectable) {
return -1;
}
if (this.textField == null) {
return 0;
}
return this.textField.selectionBeginIndex;
}
/**
The end index of the selection.
If `selectable` is `false`, returns `-1`.
@since 1.0.0
**/
public var selectionEndIndex(get, never):Int;
private function get_selectionEndIndex():Int {
if (!this._selectable) {
return -1;
}
if (this.textField == null) {
return 0;
}
return this.textField.selectionEndIndex;
}
private var _required:Bool = false;
/**
Indicates if the form item is required. This is purely a visual
indicator, and it will not prevent the form from being submitted.
In the following example, the form item is required:
```haxe
formItem.required = true;
```
@see `FormItem.requiredSkin`
@since 1.0.0
**/
public var required(get, set):Bool;
private function get_required():Bool {
return this._required;
}
private function set_required(value:Bool):Bool {
if (this._required == value) {
return this._required;
}
this._required = value;
this.setInvalid(SELECTION);
if (this._customTextColumnWidth != null && (this.textPosition == LEFT || this.textPosition == RIGHT)) {
// ensure that form updates its layout because this change could
// affect other form items too
FeathersEvent.dispatch(this, Event.RESIZE);
}
return this._required;
}
/**
Set to false to prevent `Keyboard.ENTER` from submitting the `Form` that
contains this item.
In the following example, the form item does not submit when pressing
the enter key:
```haxe
formItem.submitOnEnterEnabled = false;
```
@since 1.0.0
**/
public var submitOnEnterEnabled:Bool = true;
private var _currentRequiredSkin:DisplayObject = null;
private var _requiredSkinMeasurements:Measurements = null;
/**
The symbol displayed if the `required` property is `true`.
In the following example, the form item's required skin is set to a bitmap:
```haxe
formItem.requiredSkin = new Bitmap(bitmapData);
```
@see `FormItem.required`
@since 1.0.0
**/
@:style
public var requiredSkin:DisplayObject = null;
/**
The font styles used to render the form item's text.
In the following example, the form item's text formatting is customized:
```haxe
formItem.textFormat = new TextFormat("Helvetica", 20, 0xcc0000);
```
@see `FormItem.text`
@see `FormItem.disabledTextFormat`
@see `FormItem.embedFonts`
@since 1.0.0
**/
@:style
public var textFormat:AbstractTextFormat = null;
#if (openfl >= "9.2.0" || flash)
/**
A custom stylesheet to use with `htmlText`.
If the `styleSheet` style is not `null`, the `textFormat` style will
be ignored.
@see `FormItem.htmlText`
@since 1.0.0
**/
@:style
public var styleSheet:StyleSheet = null;
#end
/**
The font styles used to render the form item's text when the form item
is disabled.
In the following example, the form item's disabled text formatting is
customized:
```haxe
formItem.enabled = false;
formItem.disabledTextFormat = new TextFormat("Helvetica", 20, 0xee0000);
```
@see `FormItem.textFormat`
@since 1.0.0
**/
@:style
public var disabledTextFormat:AbstractTextFormat = null;
/**
Determines if an embedded font is used or not.
In the following example, the form item uses embedded fonts:
```haxe
formItem.embedFonts = true;
```
@see `FormItem.textFormat`
@since 1.0.0
**/
@:style
public var embedFonts:Bool = false;
/**
Configures the `alpha` value of the form item's text.
In the following example, the form item's text alpha is customized:
```haxe
formItem.textAlpha = 0.5;
```
@see `FormItem.textFormat`
@see `FormItem.disabledTextAlpha`
@since 1.4.0
**/
@:style
@:inspectable(minValue = "0.0", maxValue = "1.0", verbose = "1")
public var textAlpha:Float = 1.0;
/**
When `disabledTextAlpha` is not `null`, sets the `alpha` property of the
text to this value when the the `enabled` property is set to `false`.
In the following example, the form item's disabled text alpha is customized:
```haxe
formItem.disabledTextAlpha = 0.5;
```
@see `FormItem.textAlpha`
@since 1.4.0
**/
@:style
@:inspectable(minValue = "0.0", maxValue = "1.0", verbose = "1")
public var disabledTextAlpha:Null<Float> = null;
/**
Determines the type of anti-aliasing used for embedded fonts.
In the following example, the form item uses advanced anti-aliasing:
```haxe
formItem.embedFonts = true;
formItem.antiAliasType = ADVANCED;
```
@see `FormItem.embedFonts`
@see `FormItem.gridFitType`
@since 1.4.0
**/
@:style
public var antiAliasType:AntiAliasType = NORMAL;
/**
Determines the type of anti-aliasing used for embedded fonts.
In the following example, the form item uses sub-pixel grid fitting:
```haxe
formItem.embedFonts = true;
formItem.antiAliasType = ADVANCED;
formItem.gridFitType = SUBPIXEL;
```
@see `FormItem.antiAliasType`
@see `FormItem.embedFonts`
@since 1.4.0
**/
@:style
public var gridFitType:GridFitType = PIXEL;
/**
The minimum space, in pixels, between the form item's top edge and the
form item's content.
In the following example, the form item's top padding is set to 20
pixels:
```haxe
formItem.paddingTop = 20.0;
```
@default 0.0
@since 1.0.0
**/
@:style
public var paddingTop:Float = 0.0;
/**
The minimum space, in pixels, between the form item's right edge and the
form item's content.
In the following example, the form item's right padding is set to 20
pixels:
```haxe
formItem.paddingRight = 20.0;
```
@default 0.0
@since 1.0.0
**/
@:style
public var paddingRight:Float = 0.0;
/**
The minimum space, in pixels, between the form item's bottom edge and
the form item's content.
In the following example, the form item's bottom padding is set to 20
pixels:
```haxe
formItem.paddingBottom = 20.0;
```
@default 0.0
@since 1.0.0
**/
@:style
public var paddingBottom:Float = 0.0;
/**
The minimum space, in pixels, between the form item's left edge and the
form item's content.
In the following example, the form item's left padding is set to 20
pixels:
```haxe
formItem.paddingLeft = 20.0;
```
@default 0.0
@since 1.0.0
**/
@:style
public var paddingLeft:Float = 0.0;
/**
The space, measured in pixels, between the form item's text and its
content. Applies to either horizontal or vertical spacing, depending on
the value of `textPosition`.
The following example creates a gap of 20 pixels between the text and
the content:
```haxe
formItem.text = "Name";
formItem.content = new TextInput();
formItem.gap = 20.0;
```
@since 1.0.0
**/
@:style
public var gap:Float = 0.0;
/**
How the `content` is positioned horizontally (along the x-axis) within
the available space next to the form item's text.
The following example aligns the form item's content to the right:
```haxe
formItem.verticalAlign = RIGHT;
```
@see `feathers.layout.HorizontalAlign.LEFT`
@see `feathers.layout.HorizontalAlign.CENTER`
@see `feathers.layout.HorizontalAlign.RIGHT`
@see `feathers.layout.HorizontalAlign.JUSTIFY`
@since 1.0.0
**/
@:style
public var horizontalAlign:HorizontalAlign = LEFT;
/**
How the `content` is positioned vertically (along the y-axis) within the
available space next to the form item's text.
The following example aligns the form item's content to the bottom:
```haxe
formItem.verticalAlign = BOTTOM;
```
@see `feathers.layout.VerticalAlign.TOP`
@see `feathers.layout.VerticalAlign.MIDDLE`
@see `feathers.layout.VerticalAlign.BOTTOM`
@see `feathers.layout.VerticalAlign.JUSTIFY`
@since 1.0.0
**/
@:style
public var verticalAlign:VerticalAlign = MIDDLE;
/**
Determines if the text is displayed on a single line, or if it wraps.
In the following example, the form item's text wraps:
```haxe
formItem.wordWrap = true;
```
@default false
@since 1.0.0
**/
@:style
public var wordWrap:Bool = false;
private var _customTextColumnWidth:Null<Float> = null;
private var customTextColumnWidth(get, set):Null<Float>;
private function get_customTextColumnWidth():Null<Float> {
return this._customTextColumnWidth;
}
private function set_customTextColumnWidth(value:Null<Float>):Null<Float> {
if (this._customTextColumnWidth == value) {
return this._customTextColumnWidth;
}
this._customTextColumnWidth = value;
this.setInvalid(SIZE);
return this._customTextColumnWidth;
}
private var _currentBackgroundSkin:DisplayObject = null;
private var _backgroundSkinMeasurements:Measurements = null;
/**
The default background skin to display behind the form item's content.
The following example passes a bitmap for the form item to use as a
background skin:
```haxe
formItem.backgroundSkin = new Bitmap(bitmapData);
```
@default null
@see `FormItem.disabledBackgroundSkin`
@since 1.0.0
**/
@:style
public var backgroundSkin:DisplayObject = null;
/**
A background skin to display behind the form item's content when the
form item is disabled.
The following example gives the form item a disabled background skin:
```haxe
formItem.disabledBackgroundSkin = new Bitmap(bitmapData);
formItem.enabled = false;
```
@default null
@see `FormItem.backgroundSkin`
@since 1.0.0
**/
@:style
public var disabledBackgroundSkin:DisplayObject = null;
/**
The location of the form item's text, relative to its content.
The following example positions the text to the left of the text:
```haxe
formItem.text = "Click Me";
formItem.content = new TextInput();
formItem.textPosition = LEFT;
```
@see `FormItem.text`
@since 1.0.0
**/
@:style
public var textPosition:RelativePosition = TOP;
override public function dispose():Void {
if (this._previousTextFormat != null) {
this._previousTextFormat.removeEventListener(Event.CHANGE, formItem_textFormat_changeHandler);
this._previousTextFormat = null;
}
super.dispose();
}
/**
Returns the measured width of the form item's text. Used by `Form` to
position and size all form items correctly.
@since 1.0.0
**/
public function getTextMeasuredWidth():Float {
var result = this._textMeasuredWidth;
if (this._currentRequiredSkin != null) {
result += this.gap + this._currentRequiredSkin.width;
}
return result;
}
/**
Returns the maximum allowed width of the form item's text. Used by
`Form` to position and size all form items correctly.
@since 1.0.0
**/
public function getTextMeasuredMaxWidth():Float {
if (this._explicitWidth != null) {
var textMeasuredWidth = this.getTextMeasuredWidth();
var maxWidth = this._explicitWidth;
if (this._currentContent != null) {
if ((this._currentContent is IMeasureObject)) {
maxWidth -= (cast this._currentContent : IMeasureObject).minWidth;
} else {
maxWidth -= this._currentContent.width;
}
maxWidth -= this.gap;
}
if (maxWidth < 0.0) {
maxWidth = 0.0;
}
if (textMeasuredWidth > maxWidth) {
return maxWidth;
}
}
return 1.0 / 0.0; // Math.POSITIVE_INFINITY bug workaround for swf
}
/**
Sets all four padding properties to the same value.
@see `FormItem.paddingTop`
@see `FormItem.paddingRight`
@see `FormItem.paddingBottom`
@see `FormItem.paddingLeft`
@since 1.0.0
**/
public function setPadding(value:Float):Void {
this.paddingTop = value;
this.paddingRight = value;
this.paddingBottom = value;
this.paddingLeft = value;
}
private function initializeFormItemTheme():Void {
#if !feathersui_disable_default_theme
feathers.themes.steel.components.SteelFormItemStyles.initialize();
#end
}
override private function initialize():Void {
super.initialize();
if (this.textField == null) {
this.textField = new TextField();
this.textField.multiline = true;
this.addChild(this.textField);
}
this.textField.addEventListener(MouseEvent.CLICK, formItem_textField_clickHandler);
}
override private function update():Void {
var dataInvalid = this.isInvalid(DATA);
var selectionInvalid = this.isInvalid(SELECTION);
var sizeInvalid = this.isInvalid(SIZE);
var stateInvalid = this.isInvalid(STATE);
var stylesInvalid = this.isInvalid(STYLES);
this._updatedTextStyles = false;
if (stylesInvalid || stateInvalid) {
this.refreshBackgroundSkin();
}
if (stylesInvalid || selectionInvalid) {
this.refreshRequiredSkin();
}
if (stylesInvalid || stateInvalid) {
this.refreshTextStyles();
}
if (dataInvalid || stylesInvalid || stateInvalid || sizeInvalid) {
this.refreshText(sizeInvalid);
}
if (dataInvalid || stylesInvalid || selectionInvalid) {
this.refreshSelection();
}
if (dataInvalid) {
this.refreshContent();
}
if (dataInvalid || stateInvalid) {
this.refreshEnabled();
}
sizeInvalid = this.measure() || sizeInvalid;
this.layoutContent();
}
private function measure():Bool {
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 (!needsWidth && !needsHeight && !needsMinWidth && !needsMinHeight && !needsMaxWidth && !needsMaxHeight) {
return false;
}
if (this._currentBackgroundSkin != null) {
MeasurementsUtil.resetFluidlyWithParent(this._backgroundSkinMeasurements, this._currentBackgroundSkin, this);
}
var measureSkin:IMeasureObject = null;
if ((this._currentBackgroundSkin is IMeasureObject)) {
measureSkin = cast this._currentBackgroundSkin;
}
if ((this._currentBackgroundSkin is IValidating)) {
(cast this._currentBackgroundSkin : IValidating).validateNow();
}
if ((this._currentRequiredSkin is IValidating)) {
(cast this._currentRequiredSkin : IValidating).validateNow();
}
var measureContent:IMeasureObject = null;
if ((this._currentContent is IMeasureObject)) {
measureContent = cast this._currentContent;
}
var measureRequiredSkin:IMeasureObject = null;
if ((this._currentRequiredSkin is IMeasureObject)) {
measureRequiredSkin = cast this._currentRequiredSkin;
}
if (this._currentContent != null) {
var textWidthOffset = 0.0;
var textHeightOffset = 0.0;
if (this.textPosition == TOP || this.textPosition == BOTTOM) {
textHeightOffset = this._textMeasuredHeight + this.gap;
} else {
if (this._customTextColumnWidth != null) {
textWidthOffset = this._customTextColumnWidth + this.gap;
} else {
textWidthOffset = this._textMeasuredWidth + this.gap;
if (this._currentRequiredSkin != null) {
textWidthOffset += this._currentRequiredSkin.width + this.gap;
}
}
}
var oldIgnoreContentResize = this._ignoreContentResize;
this._ignoreContentResize = true;
if (this.horizontalAlign == JUSTIFY || this.verticalAlign == JUSTIFY) {
var justifyWidth:Null<Float> = null;
var justifyHeight:Null<Float> = null;
var justifyMinWidth:Null<Float> = null;
var justifyMinHeight:Null<Float> = null;
var justifyMaxWidth:Null<Float> = null;
var justifyMaxHeight:Null<Float> = null;
if (this.horizontalAlign == JUSTIFY) {
justifyWidth = this.explicitWidth != null ? this.explicitWidth - textWidthOffset - this.paddingLeft - this.paddingRight : null;
justifyMinWidth = this.explicitMinWidth != null ? this.explicitMinWidth - textWidthOffset - this.paddingLeft - this.paddingRight : null;
justifyMaxWidth = this.explicitMaxWidth != null ? this.explicitMaxWidth - textWidthOffset - this.paddingLeft - this.paddingRight : null;
}
if (this.verticalAlign == JUSTIFY) {
justifyHeight = this.explicitHeight != null ? this.explicitHeight - textHeightOffset - this.paddingTop - this.paddingBottom : null;
justifyMinHeight = this.explicitMinHeight != null ? this.explicitMinHeight - textHeightOffset - this.paddingLeft - this.paddingRight : null;
justifyMaxHeight = this.explicitMaxHeight != null ? this.explicitMaxHeight - textHeightOffset - this.paddingLeft - this.paddingRight : null;
}
MeasurementsUtil.resetFluidlyWithParentValues(this._contentMeasurements, this._currentContent, justifyWidth, justifyHeight, justifyMinWidth,
justifyMinHeight, justifyMaxWidth, justifyMaxHeight);
} else {
this._contentMeasurements.restore(this._currentContent);
}
if ((this._currentContent is IValidating)) {
(cast this._currentContent : IValidating).validateNow();
}
this._ignoreContentResize = oldIgnoreContentResize;
}
var newWidth = this.explicitWidth;
if (needsWidth) {
newWidth = this._textMeasuredWidth;
if (this._customTextColumnWidth != null && (this.textPosition == LEFT || this.textPosition == RIGHT)) {
newWidth = this._customTextColumnWidth;
} else if (measureRequiredSkin != null) {
newWidth += this.gap + measureRequiredSkin.width;
} else if (this._requiredSkinMeasurements != null && this._requiredSkinMeasurements.width != null) {
newWidth += this.gap + this._requiredSkinMeasurements.width;
}
newWidth += this.paddingLeft + this.paddingRight;
if (this._currentContent != null) {
if (this.textPosition == LEFT || this.textPosition == RIGHT) {
newWidth += this.gap + this._currentContent.width;
} else {
newWidth = Math.max(newWidth, this._currentContent.width + this.paddingLeft + this.paddingRight);
}
}
if (this._currentBackgroundSkin != null) {
newWidth = Math.max(this._currentBackgroundSkin.width, newWidth);
}
}
var newHeight = this.explicitHeight;
if (needsHeight) {
newHeight = this._textMeasuredHeight;
if (measureRequiredSkin != null) {
newHeight = Math.max(newHeight, measureRequiredSkin.height);
} else if (this._requiredSkinMeasurements != null && this._requiredSkinMeasurements.height != null) {
newHeight = Math.max(newHeight, this._requiredSkinMeasurements.height);
}
if (this._currentContent != null) {
if (this.textPosition == LEFT || this.textPosition == RIGHT) {
newHeight = Math.max(newHeight, this._currentContent.height);
} else // TOP or BOTTOM
{
newHeight += this.gap + this._currentContent.height;
}
}
newHeight += this.paddingTop + this.paddingBottom;
if (this._currentBackgroundSkin != null) {
newHeight = Math.max(this._currentBackgroundSkin.height, newHeight);
}
}
var newMinWidth = this.explicitMinWidth;
if (needsMinWidth) {
newMinWidth = this._textMeasuredWidth;
if (this._customTextColumnWidth != null && (this.textPosition == LEFT || this.textPosition == RIGHT)) {
newMinWidth = this._customTextColumnWidth;
} else if (measureRequiredSkin != null) {
newMinWidth += this.gap + measureRequiredSkin.width;
} else if (this._requiredSkinMeasurements != null && this._requiredSkinMeasurements.width != null) {
newMinWidth += this.gap + this._requiredSkinMeasurements.width;
}
newMinWidth += this.paddingLeft + this.paddingRight;
if (this._currentContent != null) {
if (this.textPosition == LEFT || this.textPosition == RIGHT) {
if (measureContent != null) {
newMinWidth += measureContent.minWidth;
} else {
newMinWidth += this._currentContent.width;
}
newMinWidth += this.gap;
} else // TOP or BOTTOM
{
if (measureContent != null) {
newMinWidth = Math.max(newMinWidth, measureContent.minWidth + this.paddingLeft + this.paddingRight);
} else {
newMinWidth = Math.max(newMinWidth, this._currentContent.width + this.paddingLeft + this.paddingRight);
}
}