Skip to content

Commit

Permalink
Button, ToggleButton, ItemRenderer: respect includeInLayout == false …
Browse files Browse the repository at this point in the history
…on current icon
  • Loading branch information
joshtynjala committed Aug 14, 2024
1 parent 6d56f24 commit c6a2cc6
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 29 deletions.
29 changes: 20 additions & 9 deletions src/feathers/controls/Button.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package feathers.controls;

import feathers.layout.ILayoutObject;
import feathers.core.IFocusObject;
import feathers.core.IHTMLTextControl;
import feathers.core.IMeasureObject;
Expand Down Expand Up @@ -216,7 +217,8 @@ class Button extends BasicButton implements ITextControl implements IHTMLTextCon
// this is a little strange, but measure the baseline as if
// there were text so that instances of the same component have
// the same baseline, even if some have text and others do not.
if (this._currentIcon != null) {
if (this._currentIcon != null
&& (!(this._currentIcon is ILayoutObject) || (cast this._currentIcon : ILayoutObject).includeInLayout)) {
textFieldY = this._currentIcon.y + (this._currentIcon.height - this._textMeasuredHeight) / 2.0;
} else if (this._currentBackgroundSkin != null) {
textFieldY = (this._currentBackgroundSkin.height - this._textMeasuredHeight) / 2.0;
Expand Down Expand Up @@ -892,7 +894,8 @@ class Button extends BasicButton implements ITextControl implements IHTMLTextCon
if (adjustedGap == (1.0 / 0.0)) {
adjustedGap = this.minGap;
}
if (this._currentIcon != null) {
if (this._currentIcon != null
&& (!(this._currentIcon is ILayoutObject) || (cast this._currentIcon : ILayoutObject).includeInLayout)) {
if (this.iconPosition == LEFT || this.iconPosition == RIGHT) {
if ((this._currentIcon is IValidating)) {
(cast this._currentIcon : IValidating).validateNow();
Expand All @@ -917,7 +920,8 @@ class Button extends BasicButton implements ITextControl implements IHTMLTextCon
var hasText = this.showText && this._text != null;
var hasHTMLText = this.showText && this._htmlText != null && this._htmlText.length > 0;
var contentWidth = (hasText || hasHTMLText) ? this._textMeasuredWidth : 0.0;
if (this._currentIcon != null) {
if (this._currentIcon != null
&& (!(this._currentIcon is ILayoutObject) || (cast this._currentIcon : ILayoutObject).includeInLayout)) {
if (this.iconPosition == LEFT || this.iconPosition == RIGHT) {
if (hasText || hasHTMLText) {
contentWidth += adjustedGap;
Expand All @@ -940,7 +944,8 @@ class Button extends BasicButton implements ITextControl implements IHTMLTextCon
var hasText = this.showText && this._text != null;
var hasHTMLText = this.showText && this._htmlText != null && this._htmlText.length > 0;
var contentHeight = (hasText || hasHTMLText) ? this._textMeasuredHeight : 0.0;
if (this._currentIcon != null) {
if (this._currentIcon != null
&& (!(this._currentIcon is ILayoutObject) || (cast this._currentIcon : ILayoutObject).includeInLayout)) {
if (this.iconPosition == TOP || this.iconPosition == BOTTOM) {
if (hasText || hasHTMLText) {
contentHeight += adjustedGap;
Expand All @@ -962,7 +967,8 @@ class Button extends BasicButton implements ITextControl implements IHTMLTextCon
var hasText = this.showText && this._text != null;
var hasHTMLText = this.showText && this._htmlText != null && this._htmlText.length > 0;
var contentMinWidth = (hasText || hasHTMLText) ? this._textMeasuredWidth : 0.0;
if (this._currentIcon != null) {
if (this._currentIcon != null
&& (!(this._currentIcon is ILayoutObject) || (cast this._currentIcon : ILayoutObject).includeInLayout)) {
if (this.iconPosition == LEFT || this.iconPosition == RIGHT) {
if (hasText || hasHTMLText) {
contentMinWidth += adjustedGap;
Expand All @@ -984,7 +990,8 @@ class Button extends BasicButton implements ITextControl implements IHTMLTextCon
var hasText = this.showText && this._text != null;
var hasHTMLText = this.showText && this._htmlText != null && this._htmlText.length > 0;
var contentMinHeight = (hasText || hasHTMLText) ? this._textMeasuredHeight : 0.0;
if (this._currentIcon != null) {
if (this._currentIcon != null
&& (!(this._currentIcon is ILayoutObject) || (cast this._currentIcon : ILayoutObject).includeInLayout)) {
if (this.iconPosition == TOP || this.iconPosition == BOTTOM) {
if (hasText || hasHTMLText) {
contentMinHeight += adjustedGap;
Expand Down Expand Up @@ -1110,7 +1117,9 @@ class Button extends BasicButton implements ITextControl implements IHTMLTextCon

var hasText = this.showText && this._text != null;
var hasHTMLText = this.showText && this._htmlText != null && this._htmlText.length > 0;
var iconIsInLayout = this._currentIcon != null && this.iconPosition != MANUAL;
var iconIsInLayout = this._currentIcon != null
&& (!(this._currentIcon is ILayoutObject) || (cast this._currentIcon : ILayoutObject).includeInLayout)
&& this.iconPosition != MANUAL;
if ((hasText || hasHTMLText) && iconIsInLayout) {
this.positionSingleChild(this.textField);
this.positionTextAndIcon();
Expand All @@ -1119,7 +1128,8 @@ class Button extends BasicButton implements ITextControl implements IHTMLTextCon
} else if (iconIsInLayout) {
this.positionSingleChild(this._currentIcon);
}
if (this._currentIcon != null) {
if (this._currentIcon != null
&& (!(this._currentIcon is ILayoutObject) || (cast this._currentIcon : ILayoutObject).includeInLayout)) {
if (this.iconPosition == MANUAL) {
this._currentIcon.x = this.paddingLeft;
this._currentIcon.y = this.paddingTop;
Expand Down Expand Up @@ -1168,7 +1178,8 @@ class Button extends BasicButton implements ITextControl implements IHTMLTextCon
}
calculatedWidth -= (this.paddingLeft + this.paddingRight);
calculatedHeight -= (this.paddingTop + this.paddingBottom);
if (this._currentIcon != null) {
if (this._currentIcon != null
&& (!(this._currentIcon is ILayoutObject) || (cast this._currentIcon : ILayoutObject).includeInLayout)) {
var adjustedGap = this.gap;
if (adjustedGap == (1.0 / 0.0)) {
adjustedGap = this.minGap;
Expand Down
29 changes: 20 additions & 9 deletions src/feathers/controls/ToggleButton.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package feathers.controls;

import feathers.layout.ILayoutObject;
import feathers.core.IFocusObject;
import feathers.core.IHTMLTextControl;
import feathers.core.IMeasureObject;
Expand Down Expand Up @@ -177,7 +178,8 @@ class ToggleButton extends BasicToggleButton implements ITextControl implements
// this is a little strange, but measure the baseline as if
// there were text so that instances of the same component have
// the same baseline, even if some have text and others do not.
if (this._currentIcon != null) {
if (this._currentIcon != null
&& (!(this._currentIcon is ILayoutObject) || (cast this._currentIcon : ILayoutObject).includeInLayout)) {
textFieldY = this._currentIcon.y + (this._currentIcon.height - this._textMeasuredHeight) / 2.0;
} else if (this._currentBackgroundSkin != null) {
textFieldY = (this._currentBackgroundSkin.height - this._textMeasuredHeight) / 2.0;
Expand Down Expand Up @@ -971,7 +973,8 @@ class ToggleButton extends BasicToggleButton implements ITextControl implements
if (adjustedGap == (1.0 / 0.0)) {
adjustedGap = this.minGap;
}
if (this._currentIcon != null) {
if (this._currentIcon != null
&& (!(this._currentIcon is ILayoutObject) || (cast this._currentIcon : ILayoutObject).includeInLayout)) {
if (this.iconPosition == LEFT || this.iconPosition == RIGHT) {
if ((this._currentIcon is IValidating)) {
(cast this._currentIcon : IValidating).validateNow();
Expand All @@ -996,7 +999,8 @@ class ToggleButton extends BasicToggleButton implements ITextControl implements
var hasText = this.showText && this._text != null;
var hasHTMLText = this.showText && this._htmlText != null && this._htmlText.length > 0;
var contentWidth = (hasText || hasHTMLText) ? this._textMeasuredWidth : 0.0;
if (this._currentIcon != null) {
if (this._currentIcon != null
&& (!(this._currentIcon is ILayoutObject) || (cast this._currentIcon : ILayoutObject).includeInLayout)) {
if (this.iconPosition == LEFT || this.iconPosition == RIGHT) {
if (hasText || hasHTMLText) {
contentWidth += adjustedGap;
Expand All @@ -1019,7 +1023,8 @@ class ToggleButton extends BasicToggleButton implements ITextControl implements
var hasText = this.showText && this._text != null;
var hasHTMLText = this.showText && this._htmlText != null && this._htmlText.length > 0;
var contentHeight = (hasText || hasHTMLText) ? this._textMeasuredHeight : 0.0;
if (this._currentIcon != null) {
if (this._currentIcon != null
&& (!(this._currentIcon is ILayoutObject) || (cast this._currentIcon : ILayoutObject).includeInLayout)) {
if (this.iconPosition == TOP || this.iconPosition == BOTTOM) {
if (hasText || hasHTMLText) {
contentHeight += adjustedGap;
Expand All @@ -1041,7 +1046,8 @@ class ToggleButton extends BasicToggleButton implements ITextControl implements
var hasText = this.showText && this._text != null;
var hasHTMLText = this.showText && this._htmlText != null && this._htmlText.length > 0;
var contentMinWidth = (hasText || hasHTMLText) ? this._textMeasuredWidth : 0.0;
if (this._currentIcon != null) {
if (this._currentIcon != null
&& (!(this._currentIcon is ILayoutObject) || (cast this._currentIcon : ILayoutObject).includeInLayout)) {
if (this.iconPosition == LEFT || this.iconPosition == RIGHT) {
if (hasText || hasHTMLText) {
contentMinWidth += adjustedGap;
Expand All @@ -1063,7 +1069,8 @@ class ToggleButton extends BasicToggleButton implements ITextControl implements
var hasText = this.showText && this._text != null;
var hasHTMLText = this.showText && this._htmlText != null && this._htmlText.length > 0;
var contentMinHeight = (hasText || hasHTMLText) ? this._textMeasuredHeight : 0.0;
if (this._currentIcon != null) {
if (this._currentIcon != null
&& (!(this._currentIcon is ILayoutObject) || (cast this._currentIcon : ILayoutObject).includeInLayout)) {
if (this.iconPosition == TOP || this.iconPosition == BOTTOM) {
if (hasText || hasHTMLText) {
contentMinHeight += adjustedGap;
Expand Down Expand Up @@ -1192,7 +1199,9 @@ class ToggleButton extends BasicToggleButton implements ITextControl implements

var hasText = this.showText && this._text != null;
var hasHTMLText = this.showText && this._htmlText != null && this._htmlText.length > 0;
var iconIsInLayout = this._currentIcon != null && this.iconPosition != MANUAL;
var iconIsInLayout = this._currentIcon != null
&& (!(this._currentIcon is ILayoutObject) || (cast this._currentIcon : ILayoutObject).includeInLayout)
&& this.iconPosition != MANUAL;
if ((hasText || hasHTMLText) && iconIsInLayout) {
this.positionSingleChild(this.textField);
this.positionTextAndIcon();
Expand All @@ -1202,7 +1211,8 @@ class ToggleButton extends BasicToggleButton implements ITextControl implements
this.positionSingleChild(this._currentIcon);
}

if (this._currentIcon != null) {
if (this._currentIcon != null
&& (!(this._currentIcon is ILayoutObject) || (cast this._currentIcon : ILayoutObject).includeInLayout)) {
if (this.iconPosition == MANUAL) {
this._currentIcon.x = this.paddingLeft;
this._currentIcon.y = this.paddingTop;
Expand Down Expand Up @@ -1251,7 +1261,8 @@ class ToggleButton extends BasicToggleButton implements ITextControl implements
}
calculatedWidth -= (this.paddingLeft + this.paddingRight);
calculatedHeight -= (this.paddingTop + this.paddingBottom);
if (this._currentIcon != null) {
if (this._currentIcon != null
&& (!(this._currentIcon is ILayoutObject) || (cast this._currentIcon : ILayoutObject).includeInLayout)) {
var adjustedGap = this.gap;
// Math.POSITIVE_INFINITY bug workaround for swf
if (adjustedGap == (1.0 / 0.0)) {
Expand Down
36 changes: 25 additions & 11 deletions src/feathers/controls/dataRenderers/ItemRenderer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@ class ItemRenderer extends ToggleButton implements IFocusContainer implements IL
// this is a little strange, but measure the baseline as if
// there were text so that instances of the same component have
// the same baseline, even if some have text and others do not.
if (this._currentIcon != null) {
if (this._currentIcon != null
&& (!(this._currentIcon is ILayoutObject) || (cast this._currentIcon : ILayoutObject).includeInLayout)) {
textFieldY = this._currentIcon.y + (this._currentIcon.height - this._textMeasuredHeight) / 2.0;
} else if (this._currentBackgroundSkin != null) {
textFieldY = (this._currentBackgroundSkin.height - this._textMeasuredHeight) / 2.0;
Expand Down Expand Up @@ -730,7 +731,8 @@ class ItemRenderer extends ToggleButton implements IFocusContainer implements IL
if (adjustedGap == (1.0 / 0.0)) {
adjustedGap = this.minGap;
}
if (this._currentIcon != null) {
if (this._currentIcon != null
&& (!(this._currentIcon is ILayoutObject) || (cast this._currentIcon : ILayoutObject).includeInLayout)) {
if (this.iconPosition == LEFT || this.iconPosition == RIGHT) {
calculatedWidth -= (this._currentIcon.width + adjustedGap);
}
Expand Down Expand Up @@ -827,7 +829,8 @@ class ItemRenderer extends ToggleButton implements IFocusContainer implements IL
}
contentWidth += this._currentAccessoryView.width;
}
if (this._currentIcon != null) {
if (this._currentIcon != null
&& (!(this._currentIcon is ILayoutObject) || (cast this._currentIcon : ILayoutObject).includeInLayout)) {
if (this.iconPosition == LEFT || this.iconPosition == RIGHT) {
if (hasText || hasHTMLText || hasSecondaryText || hasSecondaryHTMLText || this.hasAccessoryViewInLayout()) {
contentWidth += adjustedGap;
Expand Down Expand Up @@ -867,7 +870,8 @@ class ItemRenderer extends ToggleButton implements IFocusContainer implements IL
this._ignoreAccessoryResizes = oldIgnoreAccessoryResizes;
contentHeight = Math.max(contentHeight, this._currentAccessoryView.height);
}
if (this._currentIcon != null) {
if (this._currentIcon != null
&& (!(this._currentIcon is ILayoutObject) || (cast this._currentIcon : ILayoutObject).includeInLayout)) {
if (this.iconPosition == TOP || this.iconPosition == BOTTOM) {
if (hasText || hasHTMLText || hasSecondaryText || hasSecondaryHTMLText) {
contentHeight += adjustedGap;
Expand Down Expand Up @@ -906,7 +910,8 @@ class ItemRenderer extends ToggleButton implements IFocusContainer implements IL
}
contentMinWidth += this._currentAccessoryView.width;
}
if (this._currentIcon != null) {
if (this._currentIcon != null
&& (!(this._currentIcon is ILayoutObject) || (cast this._currentIcon : ILayoutObject).includeInLayout)) {
if (this.iconPosition == LEFT || this.iconPosition == RIGHT) {
if (hasText || hasHTMLText || hasSecondaryText || hasSecondaryHTMLText || this.hasAccessoryViewInLayout()) {
contentMinWidth += adjustedGap;
Expand Down Expand Up @@ -945,7 +950,8 @@ class ItemRenderer extends ToggleButton implements IFocusContainer implements IL
this._ignoreAccessoryResizes = oldIgnoreAccessoryResizes;
contentMinHeight = Math.max(contentMinHeight, this._currentAccessoryView.height);
}
if (this._currentIcon != null) {
if (this._currentIcon != null
&& (!(this._currentIcon is ILayoutObject) || (cast this._currentIcon : ILayoutObject).includeInLayout)) {
if (this.iconPosition == TOP || this.iconPosition == BOTTOM) {
if (hasText || hasHTMLText || hasSecondaryText || hasSecondaryHTMLText) {
contentMinHeight += adjustedGap;
Expand Down Expand Up @@ -1005,7 +1011,8 @@ class ItemRenderer extends ToggleButton implements IFocusContainer implements IL
totalContentWidth = Math.max(totalContentWidth, this._secondaryTextMeasuredWidth);
totalContentHeight += (this._secondaryTextMeasuredHeight + adjustedGap);
}
if (this._currentIcon != null) {
if (this._currentIcon != null
&& (!(this._currentIcon is ILayoutObject) || (cast this._currentIcon : ILayoutObject).includeInLayout)) {
if (this.iconPosition == LEFT || this.iconPosition == RIGHT) {
totalContentWidth += adjustedGap + this._currentIcon.width;
}
Expand All @@ -1017,10 +1024,12 @@ class ItemRenderer extends ToggleButton implements IFocusContainer implements IL
var flexGapVertical = flexGap
&& (hasText || hasHTMLText || hasSecondaryText || hasSecondaryHTMLText)
&& this._currentIcon != null
&& (!(this._currentIcon is ILayoutObject) || (cast this._currentIcon : ILayoutObject).includeInLayout)
&& (this.iconPosition == TOP || this.iconPosition == BOTTOM);
var flexGapHorizontal = flexGap
&& (hasText || hasHTMLText || hasSecondaryText || hasSecondaryHTMLText)
&& this._currentIcon != null
&& (!(this._currentIcon is ILayoutObject) || (cast this._currentIcon : ILayoutObject).includeInLayout)
&& (this.iconPosition == LEFT || this.iconPosition == RIGHT);

if (this.hasAccessoryViewInLayout()) {
Expand All @@ -1039,7 +1048,8 @@ class ItemRenderer extends ToggleButton implements IFocusContainer implements IL
}
availableContentWidth -= (this._currentAccessoryView.width + adjustedGap);
}
if (this._currentIcon != null) {
if (this._currentIcon != null
&& (!(this._currentIcon is ILayoutObject) || (cast this._currentIcon : ILayoutObject).includeInLayout)) {
if (this.iconPosition == TOP || iconPosition == BOTTOM) {
switch (this.horizontalAlign) {
case LEFT:
Expand Down Expand Up @@ -1097,7 +1107,8 @@ class ItemRenderer extends ToggleButton implements IFocusContainer implements IL
}
}

if (this._currentIcon != null) {
if (this._currentIcon != null
&& (!(this._currentIcon is ILayoutObject) || (cast this._currentIcon : ILayoutObject).includeInLayout)) {
if (this.iconPosition == LEFT) {
this._currentIcon.x = currentX;
currentX += adjustedGap + this._currentIcon.width;
Expand All @@ -1110,7 +1121,9 @@ class ItemRenderer extends ToggleButton implements IFocusContainer implements IL
var totalTextWidth = 0.0;
var totalTextHeight = 0.0;
var availableTextWidth = availableContentWidth;
if (this._currentIcon != null && (this.iconPosition == LEFT || this.iconPosition == RIGHT)) {
if (this._currentIcon != null
&& (!(this._currentIcon is ILayoutObject) || (cast this._currentIcon : ILayoutObject).includeInLayout)
&& (this.iconPosition == LEFT || this.iconPosition == RIGHT)) {
availableTextWidth -= (adjustedGap + this._currentIcon.width);
}
if (hasText || hasHTMLText) {
Expand Down Expand Up @@ -1156,7 +1169,8 @@ class ItemRenderer extends ToggleButton implements IFocusContainer implements IL
currentX += totalTextWidth + adjustedGap;
}

if (this._currentIcon != null) {
if (this._currentIcon != null
&& (!(this._currentIcon is ILayoutObject) || (cast this._currentIcon : ILayoutObject).includeInLayout)) {
if (this.iconPosition == RIGHT) {
if (flexGapHorizontal) {
this._currentIcon.x = Math.max(currentX, this.paddingLeft + availableContentWidth - this._currentIcon.width);
Expand Down

0 comments on commit c6a2cc6

Please sign in to comment.