Skip to content

Commit

Permalink
removes previous bruteforce method (#14548)
Browse files Browse the repository at this point in the history
instead checks if the final size of the container is supposed to be bigger than zero: if it is, then it will continue to attempt to set the split fraction until the size is no longer zero, then it will do it once last time before stopping
  • Loading branch information
vulppine authored Mar 9, 2023
1 parent 5e88334 commit 12192ad
Showing 1 changed file with 4 additions and 28 deletions.
32 changes: 4 additions & 28 deletions Content.Client/UserInterface/Controls/RecordedSplitContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,12 @@ public sealed class RecordedSplitContainer : SplitContainer
protected override Vector2 ArrangeOverride(Vector2 finalSize)
{
if (ResizeMode == SplitResizeMode.RespectChildrenMinSize
&& DesiredSplitCenter != null)
&& DesiredSplitCenter != null
&& !finalSize.Equals(Vector2.Zero))
{
var secondMin = GetChild(1).DesiredSize;
double minSize = Orientation == SplitOrientation.Vertical
? secondMin.Y
: secondMin.X;
double finalSizeComponent = Orientation == SplitOrientation.Vertical
? finalSize.Y
: finalSize.X;
SplitFraction = (float) DesiredSplitCenter.Value;

var firstTotalFractional = (finalSizeComponent - minSize - SplitWidth - SplitEdgeSeparation) / finalSizeComponent;
DesiredSplitCenter = Math.Round(DesiredSplitCenter.Value, 2, MidpointRounding.ToZero);

// total space the split center takes up must fit the available space percentage given to the first child
var canFirstFit = DesiredSplitCenter <= firstTotalFractional;

if (DesiredSplitCenter > 1 || DesiredSplitCenter < 0 || !canFirstFit)
{
DesiredSplitCenter = Math.Round(firstTotalFractional, 2, MidpointRounding.ToZero);
}

// don't need anything more than two digits of precision for this
var currentSplitFraction = Math.Round(SplitFraction, 2, MidpointRounding.ToZero);

// brute force it
if (currentSplitFraction != DesiredSplitCenter.Value)
{
SplitFraction = (float) DesiredSplitCenter.Value;
}
else
if (!Size.Equals(Vector2.Zero))
{
DesiredSplitCenter = null;
}
Expand Down

0 comments on commit 12192ad

Please sign in to comment.