Skip to content

Commit

Permalink
HDividedBoxLayout, VDividedBoxLayout: smarter detection of the fallba…
Browse files Browse the repository at this point in the history
…ck fluid index
  • Loading branch information
joshtynjala committed Mar 19, 2024
1 parent 9f74a5c commit f5d22e6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
23 changes: 15 additions & 8 deletions src/feathers/layout/HDividedBoxLayout.hx
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,8 @@ class HDividedBoxLayout extends EventDispatcher implements ILayout {
var totalMeasuredWidth = 0.0;
var totalMinWidth = 0.0;
var totalPercentWidth = 0.0;
var fallbackItemIndex = -1;
var fallbackFluidIndex = this._fallbackFluidIndex;
var fallbackFallbackFluidIndex = -1;
var i = 0;
while (i < items.length) {
var item = items[i];
Expand All @@ -422,13 +423,17 @@ class HDividedBoxLayout extends EventDispatcher implements ILayout {
divider = items[i - 1];
}
if ((item is ILayoutObject) && !(cast item : ILayoutObject).includeInLayout) {
if (fallbackFluidIndex == i) {
// no longer valid (probably a bug in HDividedBox)
fallbackFluidIndex = -1;
}
i += 2;
continue;
}
if (divider != null && divider.visible) {
totalMeasuredWidth += divider.width;
}
fallbackItemIndex = i;
fallbackFallbackFluidIndex = i;
var nonDividerIndex = Math.floor(i / 2);
var needsPercentWidth = true;
if (this._customItemWidths != null && nonDividerIndex < this._customItemWidths.length) {
Expand Down Expand Up @@ -539,17 +544,19 @@ class HDividedBoxLayout extends EventDispatcher implements ILayout {
return;
}

var index = this._fallbackFluidIndex;
if (index == -1) {
index = fallbackItemIndex;
// if there is no fallback specified by HDividedBox,
// or we never encountered the one that it specified,
// use the last one that we discovered
if (fallbackFluidIndex == -1 || fallbackFallbackFluidIndex < fallbackFluidIndex) {
fallbackFluidIndex = fallbackFallbackFluidIndex;
}
if (index != -1) {
var fallbackItem = items[index];
if (fallbackFluidIndex != -1) {
var fallbackItem = items[fallbackFluidIndex];
var itemWidth = fallbackItem.width + remainingWidth;
if (itemWidth < 0.0) {
remainingWidth = itemWidth;
itemWidth = 0.0;
customWidthIndices.remove(index);
customWidthIndices.remove(fallbackFluidIndex);
} else {
remainingWidth = 0.0;
}
Expand Down
23 changes: 15 additions & 8 deletions src/feathers/layout/VDividedBoxLayout.hx
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,8 @@ class VDividedBoxLayout extends EventDispatcher implements ILayout {
var totalMeasuredHeight = 0.0;
var totalMinHeight = 0.0;
var totalPercentHeight = 0.0;
var fallbackItemIndex = -1;
var fallbackFluidIndex = this._fallbackFluidIndex;
var fallbackFallbackFluidIndex = -1;
var i = 0;
while (i < items.length) {
var item = items[i];
Expand All @@ -423,10 +424,14 @@ class VDividedBoxLayout extends EventDispatcher implements ILayout {
divider = items[i - 1];
}
if ((item is ILayoutObject) && !(cast item : ILayoutObject).includeInLayout) {
if (fallbackFluidIndex == i) {
// no longer valid (probably a bug in VDividedBox)
fallbackFluidIndex = -1;
}
i += 2;
continue;
}
fallbackItemIndex = i;
fallbackFallbackFluidIndex = i;
if (divider != null && divider.visible) {
totalMeasuredHeight += divider.height;
}
Expand Down Expand Up @@ -540,17 +545,19 @@ class VDividedBoxLayout extends EventDispatcher implements ILayout {
return;
}

var index = this._fallbackFluidIndex;
if (index == -1) {
index = fallbackItemIndex;
// if there is no fallback specified by VDividedBox,
// or we never encountered the one that it specified,
// use the last one that we discovered
if (fallbackFluidIndex == -1 || fallbackFallbackFluidIndex < fallbackFluidIndex) {
fallbackFluidIndex = fallbackFallbackFluidIndex;
}
if (index != -1) {
var fallbackItem = items[index];
if (fallbackFluidIndex != -1) {
var fallbackItem = items[fallbackFluidIndex];
var itemHeight = fallbackItem.height + remainingHeight;
if (itemHeight < 0.0) {
remainingHeight = itemHeight;
itemHeight = 0.0;
customHeightIndices.remove(index);
customHeightIndices.remove(fallbackFluidIndex);
} else {
remainingHeight = 0.0;
}
Expand Down

0 comments on commit f5d22e6

Please sign in to comment.