Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix layout cycle error in ProportionalStackPanel #367

Merged
merged 1 commit into from
Oct 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using Avalonia.Data;
using Avalonia.Layout;
using Avalonia.VisualTree;

namespace Avalonia.Controls;

Expand All @@ -11,6 +12,8 @@ namespace Avalonia.Controls;
/// </summary>
public class ProportionalStackPanel : Panel
{
private bool isAssigningProportions;

/// <summary>
/// Defines the <see cref="Orientation"/> property.
/// </summary>
Expand Down Expand Up @@ -80,7 +83,20 @@ public static void SetIsCollapsed(AvaloniaObject control, bool value)
control.SetValue(IsCollapsedProperty, value);
}

private void AssignProportions(global::Avalonia.Controls.Controls children)
private void AssignProportions()
{
isAssigningProportions = true;
try
{
AssignProportionsInternal(Children);
}
finally
{
isAssigningProportions = false;
}
}

private static void AssignProportionsInternal(global::Avalonia.Controls.Controls children)
{
var assignedProportion = 0.0;
var unassignedProportions = 0;
Expand Down Expand Up @@ -221,7 +237,7 @@ protected override Size MeasureOverride(Size constraint)
var maximumHeight = 0.0;
var splitterThickness = GetTotalSplitterThickness(Children);

AssignProportions(Children);
AssignProportions();

var needsNextSplitter = false;
double sumOfFractions = 0;
Expand Down Expand Up @@ -344,7 +360,7 @@ protected override Size ArrangeOverride(Size arrangeSize)
var splitterThickness = GetTotalSplitterThickness(Children);
var index = 0;

AssignProportions(Children);
AssignProportions();

var needsNextSplitter = false;
double sumOfFractions = 0;
Expand Down Expand Up @@ -492,7 +508,17 @@ static ProportionalStackPanel()
{
AffectsParentMeasure<ProportionalStackPanel>(IsCollapsedProperty);
AffectsParentArrange<ProportionalStackPanel>(IsCollapsedProperty);
AffectsParentMeasure<ProportionalStackPanel>(ProportionProperty);
AffectsParentArrange<ProportionalStackPanel>(ProportionProperty);

ProportionProperty.Changed.AddClassHandler<Control>((sender, e) =>
{
if (sender.GetVisualParent() is not ProportionalStackPanel parent)
return;

if (parent.isAssigningProportions)
return;

parent.InvalidateMeasure();
parent.InvalidateArrange();
});
}
}
Loading