Skip to content

Commit

Permalink
FormItem: listen for resize events from content
Browse files Browse the repository at this point in the history
  • Loading branch information
joshtynjala committed May 7, 2024
1 parent 50c6aa5 commit c900e49
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/feathers/controls/FormItem.hx
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ class FormItem extends FeathersControl implements ITextControl implements IFocus

private var _contentMeasurements:Measurements = null;
private var _currentContent:DisplayObject = null;
private var _ignoreContentResize:Bool = false;

private var _content:DisplayObject;

Expand Down Expand Up @@ -205,7 +206,13 @@ class FormItem extends FeathersControl implements ITextControl implements IFocus
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;
}
Expand Down Expand Up @@ -829,9 +836,12 @@ class FormItem extends FeathersControl implements ITextControl implements IFocus
} else {
this._contentMeasurements.restore(this._currentContent);
}
var oldIgnoreContentResize = this._ignoreContentResize;
this._ignoreContentResize = true;
if ((this._currentContent is IValidating)) {
(cast this._currentContent : IValidating).validateNow();
}
this._ignoreContentResize = oldIgnoreContentResize;
}

var newWidth = this.explicitWidth;
Expand Down Expand Up @@ -1068,9 +1078,12 @@ class FormItem extends FeathersControl implements ITextControl implements IFocus
textFieldExplicitWidth -= (this.paddingLeft + this.paddingRight);
if (this.content != null) {
if (this.textPosition == LEFT || this.textPosition == RIGHT) {
var oldIgnoreContentResize = this._ignoreContentResize;
this._ignoreContentResize = true;
if ((this._content is IValidating)) {
(cast this._content : IValidating).validateNow();
}
this._ignoreContentResize = oldIgnoreContentResize;
textFieldExplicitWidth -= (this._content.width + this.gap);
}
}
Expand Down Expand Up @@ -1244,9 +1257,12 @@ class FormItem extends FeathersControl implements ITextControl implements IFocus
(cast this._currentRequiredSkin : IValidating).validateNow();
}

var oldIgnoreContentResize = this._ignoreContentResize;
this._ignoreContentResize = true;
if ((this._currentContent is IValidating)) {
(cast this._currentContent : IValidating).validateNow();
}
this._ignoreContentResize = oldIgnoreContentResize;

var requiredOffset = 0.0;
if (this._currentRequiredSkin != null) {
Expand Down Expand Up @@ -1433,4 +1449,12 @@ class FormItem extends FeathersControl implements ITextControl implements IFocus
}
this._focusManager.focus = newFocus;
}

private function formItem_content_resizeHandler(event:Event):Void {
if (this._ignoreContentResize) {
return;
}
this._contentMeasurements.save(this.content);
this.setInvalid(SIZE);
}
}

0 comments on commit c900e49

Please sign in to comment.