Skip to content

Commit

Permalink
Fixed upstream issue randrew/layout#15
Browse files Browse the repository at this point in the history
  • Loading branch information
codecat committed Aug 11, 2024
1 parent 48f6c91 commit 8144c97
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
25 changes: 25 additions & 0 deletions Nimble.Layout.Tests/TestCases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -693,5 +693,30 @@ public void AnchorRightMargin2()

Assert.AreEqual(new(40, 40, 50, 50), child.Rect);
}

[TestMethod]
public void IssueUpstream15()
{
var root = new LayoutItem {
Size = new(1, 100),
};

var row = new LayoutItem {
Contain = ContainFlags.Row,
};
root.AddChild(row);

var child = new LayoutItem {
Size = new(1, 50),
Margins = new(0, 0, 0, 10),
};
row.AddChild(child);

root.Run();

Assert.AreEqual(new(0, 0, 1, 100), root.Rect);
Assert.AreEqual(new(0, 20, 1, 60), row.Rect);
Assert.AreEqual(new(0, 20, 1, 50), child.Rect);
}
}
}
4 changes: 2 additions & 2 deletions Nimble.Layout/LayoutItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ private void ArrangeOverlay(int dim)

switch (b_flags & BehaveFlags.HFill) {
case BehaveFlags.HCenter:
child.m_computedRect[dim] += (space - child.m_computedRect[2 + dim]) / 2 - child.Margins[wdim];
child.m_computedRect[dim] += (space - child.m_computedRect[2 + dim] - child.Margins[wdim]) / 2;
break;

case BehaveFlags.Right:
Expand Down Expand Up @@ -538,7 +538,7 @@ private static void ArrangeOverlaySqueezedRange(int dim, LayoutItem? startItem,
switch (b_flags & BehaveFlags.HFill) {
case BehaveFlags.HCenter:
item.m_computedRect[2 + dim] = Math.Min(item.m_computedRect[2 + dim], min_size);
item.m_computedRect[dim] += (space - item.m_computedRect[2 + dim]) / 2 - item.Margins[wdim];
item.m_computedRect[dim] += (space - item.m_computedRect[2 + dim] - item.Margins[wdim]) / 2;
break;

case BehaveFlags.Right:
Expand Down

0 comments on commit 8144c97

Please sign in to comment.