Skip to content

Commit

Permalink
Change logic and naming of ProportionalStackPanel.IsEmpty into Propor…
Browse files Browse the repository at this point in the history
…tionalStackPanel.IsCollapsed
  • Loading branch information
BAndysc committed Mar 10, 2024
1 parent 69070af commit e0c62f0
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 45 deletions.
9 changes: 8 additions & 1 deletion src/Dock.Avalonia/Controls/ProportionalDockControl.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@
<ItemsControl.Styles>
<Style Selector="ItemsControl > ContentPresenter">
<Setter x:DataType="core:IDock" Property="(ProportionalStackPanel.Proportion)" Value="{Binding Proportion}" />
<Setter x:DataType="core:IDock" Property="(ProportionalStackPanel.IsEmpty)" Value="{Binding IsEmpty}" />
<Setter Property="(ProportionalStackPanel.IsCollapsed)">
<Setter.Value>
<MultiBinding Converter="{x:Static BoolConverters.And}" x:DataType="core:IDock">
<CompiledBinding Path="IsCollapsable" />
<CompiledBinding Path="IsEmpty" />
</MultiBinding>
</Setter.Value>
</Setter>
</Style>
</ItemsControl.Styles>
<ItemsControl.ItemsPanel>
Expand Down
88 changes: 44 additions & 44 deletions src/Dock.Avalonia/Controls/ProportionalStackPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,29 @@ public static void SetProportion(AvaloniaObject control, double value)
}

/// <summary>
/// Defines the IsEmpty attached property.
/// Defines the IsCollapsed attached property.
/// </summary>
public static readonly AttachedProperty<bool> IsEmptyProperty =
AvaloniaProperty.RegisterAttached<ProportionalStackPanel, Control, bool>("IsEmpty", false, false, BindingMode.TwoWay);
public static readonly AttachedProperty<bool> IsCollapsedProperty =
AvaloniaProperty.RegisterAttached<ProportionalStackPanel, Control, bool>("IsCollapsed", false, false, BindingMode.TwoWay);

/// <summary>
/// Gets the value of the IsEmpty attached property on the specified control.
/// Gets the value of the IsCollapsed attached property on the specified control.
/// </summary>
/// <param name="control">The control.</param>
/// <returns>The IsEmpty attached property.</returns>
public static bool GetIsEmpty(AvaloniaObject control)
/// <returns>The IsCollapsed attached property.</returns>
public static bool GetIsCollapsed(AvaloniaObject control)
{
return control.GetValue(IsEmptyProperty);
return control.GetValue(IsCollapsedProperty);
}

/// <summary>
/// Sets the value of the IsEmpty attached property on the specified control.
/// Sets the value of the IsCollapsed attached property on the specified control.
/// </summary>
/// <param name="control">The control.</param>
/// <param name="value">The value of the IsEmpty property.</param>
public static void SetIsEmpty(AvaloniaObject control, bool value)
/// <param name="value">The value of the IsCollapsed property.</param>
public static void SetIsCollapsed(AvaloniaObject control, bool value)
{
control.SetValue(IsEmptyProperty, value);
control.SetValue(IsCollapsedProperty, value);
}

private void AssignProportions(global::Avalonia.Controls.Controls children)
Expand All @@ -89,14 +89,14 @@ private void AssignProportions(global::Avalonia.Controls.Controls children)
for (var i = 0; i < children.Count; i++)
{
var control = children[i];
var isEmpty = GetIsEmpty(control);
var isCollapsed = GetIsCollapsed(control);
var isSplitter = ProportionalStackPanelSplitter.IsSplitter(control, out _);

if (!isSplitter)
{
var proportion = GetProportion(control);

if (isEmpty)
if (isCollapsed)
{
proportion = 0.0;
}
Expand All @@ -117,8 +117,8 @@ private void AssignProportions(global::Avalonia.Controls.Controls children)
var toAssign = assignedProportion;
foreach (var control in children.Where(c =>
{
var isEmpty = GetIsEmpty(c);
return !isEmpty && double.IsNaN(GetProportion(c));
var isCollapsed = GetIsCollapsed(c);
return !isCollapsed && double.IsNaN(GetProportion(c));
}))
{
if (!ProportionalStackPanelSplitter.IsSplitter(control, out _))
Expand All @@ -138,8 +138,8 @@ private void AssignProportions(global::Avalonia.Controls.Controls children)

foreach (var child in children.Where(c =>
{
var isEmpty = GetIsEmpty(c);
return !isEmpty && !ProportionalStackPanelSplitter.IsSplitter(c, out _);
var isCollapsed = GetIsCollapsed(c);
return !isCollapsed && !ProportionalStackPanelSplitter.IsSplitter(c, out _);
}))
{
var proportion = GetProportion(child) + toAdd;
Expand All @@ -154,8 +154,8 @@ private void AssignProportions(global::Avalonia.Controls.Controls children)

foreach (var child in children.Where(c =>
{
var isEmpty = GetIsEmpty(c);
return !isEmpty && !ProportionalStackPanelSplitter.IsSplitter(c, out _);
var isCollapsed = GetIsCollapsed(c);
return !isCollapsed && !ProportionalStackPanelSplitter.IsSplitter(c, out _);
}))
{
var proportion = GetProportion(child) - toRemove;
Expand All @@ -166,7 +166,7 @@ private void AssignProportions(global::Avalonia.Controls.Controls children)

private double GetTotalSplitterThickness(global::Avalonia.Controls.Controls children)
{
var previousIsEmpty = false;
var previousisCollapsed = false;
var totalThickness = 0.0;

for (var i = 0; i < children.Count; i++)
Expand All @@ -176,17 +176,17 @@ private double GetTotalSplitterThickness(global::Avalonia.Controls.Controls chil

if (isSplitter && proportionalStackPanelSplitter is not null)
{
if (previousIsEmpty)
if (previousisCollapsed)
{
previousIsEmpty = false;
previousisCollapsed = false;
continue;
}

if (i + 1 < Children.Count)
{
var nextControl = Children[i + 1];
var nextIsEmpty = GetIsEmpty(nextControl);
if (nextIsEmpty)
var nextisCollapsed = GetIsCollapsed(nextControl);
if (nextisCollapsed)
{
continue;
}
Expand All @@ -197,7 +197,7 @@ private double GetTotalSplitterThickness(global::Avalonia.Controls.Controls chil
}
else
{
previousIsEmpty = GetIsEmpty(c);
previousisCollapsed = GetIsCollapsed(c);
}
}

Expand All @@ -224,7 +224,7 @@ protected override Size MeasureOverride(Size constraint)

AssignProportions(Children);

var previousIsEmpty = false;
var previousisCollapsed = false;

// Measure each of the Children
for (var i = 0; i < Children.Count; i++)
Expand All @@ -239,11 +239,11 @@ protected override Size MeasureOverride(Size constraint)

var proportion = GetProportion(control);

var isEmpty = !isSplitter && GetIsEmpty(control);
if (isEmpty)
var isCollapsed = !isSplitter && GetIsCollapsed(control);
if (isCollapsed)
{
// TODO: Also handle next is empty.
previousIsEmpty = true;
previousisCollapsed = true;
var size = new Size();
control.Measure(size);
continue;
Expand Down Expand Up @@ -273,25 +273,25 @@ protected override Size MeasureOverride(Size constraint)
}
else
{
var nextIsEmpty = false;
var nextisCollapsed = false;
if (i + 1 < Children.Count)
{
var nextControl = Children[i + 1];
nextIsEmpty = !ProportionalStackPanelSplitter.IsSplitter(nextControl, out _ ) && GetIsEmpty(nextControl);
nextisCollapsed = !ProportionalStackPanelSplitter.IsSplitter(nextControl, out _ ) && GetIsCollapsed(nextControl);
}

if (previousIsEmpty || nextIsEmpty)
if (previousisCollapsed || nextisCollapsed)
{
var size = new Size();
control.Measure(size);
previousIsEmpty = true;
previousisCollapsed = true;
continue;
}

control.Measure(remainingSize);
}

previousIsEmpty = false;
previousisCollapsed = false;

var desiredSize = control.DesiredSize;

Expand Down Expand Up @@ -351,41 +351,41 @@ protected override Size ArrangeOverride(Size arrangeSize)

AssignProportions(Children);

var previousIsEmpty = false;
var previousisCollapsed = false;

for (var i = 0; i < Children.Count; i++)
{
var control = Children[i];

var isSplitter = ProportionalStackPanelSplitter.IsSplitter(control, out _);

var isEmpty = !isSplitter && GetIsEmpty(control);
if (isEmpty)
var isCollapsed = !isSplitter && GetIsCollapsed(control);
if (isCollapsed)
{
// TODO: Also handle next is empty.
previousIsEmpty = true;
previousisCollapsed = true;
var rect = new Rect();
control.Arrange(rect);
index++;
continue;
}

var nextIsEmpty = false;
var nextisCollapsed = false;
if (i + 1 < Children.Count)
{
var nextControl = Children[i + 1];
nextIsEmpty = !ProportionalStackPanelSplitter.IsSplitter(nextControl, out _) && GetIsEmpty(nextControl);
nextisCollapsed = !ProportionalStackPanelSplitter.IsSplitter(nextControl, out _) && GetIsCollapsed(nextControl);
}

if (isSplitter && (previousIsEmpty || nextIsEmpty))
if (isSplitter && (previousisCollapsed || nextisCollapsed))
{
var rect = new Rect();
control.Arrange(rect);
index++;
continue;
}

previousIsEmpty = false;
previousisCollapsed = false;

// Determine the remaining space left to arrange the element
var remainingRect = new Rect(
Expand Down Expand Up @@ -461,8 +461,8 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang

static ProportionalStackPanel()
{
AffectsParentMeasure<ProportionalStackPanel>(IsEmptyProperty);
AffectsParentArrange<ProportionalStackPanel>(IsEmptyProperty);
AffectsParentMeasure<ProportionalStackPanel>(IsCollapsedProperty);
AffectsParentArrange<ProportionalStackPanel>(IsCollapsedProperty);
AffectsParentMeasure<ProportionalStackPanel>(ProportionProperty);
AffectsParentArrange<ProportionalStackPanel>(ProportionProperty);
}
Expand Down

0 comments on commit e0c62f0

Please sign in to comment.