Use DependsOnSuperViewContentSize in DimAuto and fix PosCenter/PosPercent semantics

Co-authored-by: tig <585482+tig@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-02-03 04:10:00 +00:00
parent 8bb1d24947
commit 0a675fc557
5 changed files with 36 additions and 33 deletions

View File

@@ -150,11 +150,8 @@ public record DimAuto (Dim? MaximumContentDim, Dim? MinimumContentDim, DimAutoSt
.Where (v =>
(v.X is PosAbsolute or PosFunc
|| v.Width is DimAuto or DimAbsolute or DimFunc) // BUGBUG: We should use v.X.Has and v.Width.Has?
&& !v.X.Has<PosAnchorEnd> (out _)
&& !v.X.Has<PosAlign> (out _)
&& !v.X.Has<PosCenter> (out _)
&& !v.Width.Has<DimFill> (out _)
&& !v.Width.Has<DimPercent> (out _))
&& !v.X.DependsOnSuperViewContentSize
&& !v.Width.DependsOnSuperViewContentSize)
.ToList ();
}
else
@@ -163,11 +160,8 @@ public record DimAuto (Dim? MaximumContentDim, Dim? MinimumContentDim, DimAutoSt
.Where (v =>
(v.Y is PosAbsolute or PosFunc
|| v.Height is DimAuto or DimAbsolute or DimFunc) // BUGBUG: We should use v.Y.Has and v.Height.Has?
&& !v.Y.Has<PosAnchorEnd> (out _)
&& !v.Y.Has<PosAlign> (out _)
&& !v.Y.Has<PosCenter> (out _)
&& !v.Height.Has<DimFill> (out _)
&& !v.Height.Has<DimPercent> (out _))
&& !v.Y.DependsOnSuperViewContentSize
&& !v.Height.DependsOnSuperViewContentSize)
.ToList ();
}

View File

@@ -403,11 +403,18 @@ public abstract record Pos
/// without needing to perform type checking.
/// </para>
/// <para>
/// Types that depend on SuperView content size include <see cref="PosCenter"/> and <see cref="PosPercent"/>.
/// Types that depend on and actively contribute to SuperView content size determination include
/// <see cref="PosAnchorEnd"/> and <see cref="PosAlign"/>. These types require special handling during
/// auto-sizing because they affect the minimum content size needed.
/// </para>
/// <para>
/// Types like <see cref="PosCenter"/> and <see cref="PosPercent"/> also use the SuperView's content size
/// for positioning, but they do NOT actively contribute to determining that size, so this property
/// returns <see langword="false"/> for them.
/// </para>
/// </remarks>
/// <returns>
/// <see langword="true"/> if this Pos's calculation depends on the SuperView's content size;
/// <see langword="true"/> if this Pos actively contributes to determining the SuperView's content size;
/// otherwise, <see langword="false"/>.
/// </returns>
internal virtual bool DependsOnSuperViewContentSize => false;

View File

@@ -17,7 +17,4 @@ public record PosCenter : Pos
return (superviewDimension - newDimension) / 2;
}
/// <inheritdoc/>
internal override bool DependsOnSuperViewContentSize => true;
}

View File

@@ -21,7 +21,4 @@ public record PosPercent (int Percent) : Pos
public override string ToString () => $"Percent({Percent})";
internal override int GetAnchor (int size) => (int)(size * (Percent / 100f));
/// <inheritdoc/>
internal override bool DependsOnSuperViewContentSize => true;
}

View File

@@ -154,17 +154,17 @@ public class DependsOnSuperViewContentSizeTests
}
[Fact]
public void PosCenter_DependsOnSuperViewContentSize ()
public void PosCenter_DoesNotDependOnSuperViewContentSize ()
{
Pos pos = Pos.Center ();
Assert.True (pos.DependsOnSuperViewContentSize);
Assert.False (pos.DependsOnSuperViewContentSize);
}
[Fact]
public void PosPercent_DependsOnSuperViewContentSize ()
public void PosPercent_DoesNotDependOnSuperViewContentSize ()
{
Pos pos = Pos.Percent (50);
Assert.True (pos.DependsOnSuperViewContentSize);
Assert.False (pos.DependsOnSuperViewContentSize);
}
[Fact]
@@ -192,40 +192,48 @@ public class DependsOnSuperViewContentSizeTests
public void PosCombine_DependsIfEitherChildDepends ()
{
// Both depend
Pos pos1 = Pos.Center () + Pos.Percent (10);
Pos pos1 = Pos.AnchorEnd () + Pos.Align (Alignment.Center);
Assert.True (pos1.DependsOnSuperViewContentSize);
// Left depends
Pos pos2 = Pos.Center () + Pos.Absolute (10);
Pos pos2 = Pos.AnchorEnd () + Pos.Absolute (10);
Assert.True (pos2.DependsOnSuperViewContentSize);
// Right depends
Pos pos3 = Pos.Absolute (10) + Pos.Percent (50);
Pos pos3 = Pos.Absolute (10) + Pos.Align (Alignment.End);
Assert.True (pos3.DependsOnSuperViewContentSize);
// Neither depends
Pos pos4 = Pos.Absolute (10) + Pos.Absolute (5);
// Neither depends (Center and Percent don't depend)
Pos pos4 = Pos.Center () + Pos.Percent (10);
Assert.False (pos4.DependsOnSuperViewContentSize);
// Neither depends (absolute values)
Pos pos5 = Pos.Absolute (10) + Pos.Absolute (5);
Assert.False (pos5.DependsOnSuperViewContentSize);
}
[Fact]
public void PosCombine_Subtraction_DependsIfEitherChildDepends ()
{
// Both depend
Pos pos1 = Pos.AnchorEnd () - Pos.Percent (10);
Pos pos1 = Pos.AnchorEnd () - Pos.Align (Alignment.Center);
Assert.True (pos1.DependsOnSuperViewContentSize);
// Left depends
Pos pos2 = Pos.Center () - Pos.Absolute (10);
Pos pos2 = Pos.AnchorEnd () - Pos.Absolute (10);
Assert.True (pos2.DependsOnSuperViewContentSize);
// Right depends (unusual but possible)
Pos pos3 = Pos.Absolute (100) - Pos.Percent (10);
// Right depends
Pos pos3 = Pos.Absolute (100) - Pos.AnchorEnd ();
Assert.True (pos3.DependsOnSuperViewContentSize);
// Neither depends
Pos pos4 = Pos.Absolute (100) - Pos.Absolute (10);
// Neither depends (Center and Percent don't depend)
Pos pos4 = Pos.Percent (100) - Pos.Center ();
Assert.False (pos4.DependsOnSuperViewContentSize);
// Neither depends (absolute values)
Pos pos5 = Pos.Absolute (100) - Pos.Absolute (10);
Assert.False (pos5.DependsOnSuperViewContentSize);
}
#endregion