From e0c62f0b689ce607dfeb61251e115acb850721e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Korczy=C5=84ski?= Date: Sun, 10 Mar 2024 16:48:00 +0000 Subject: [PATCH] Change logic and naming of ProportionalStackPanel.IsEmpty into ProportionalStackPanel.IsCollapsed --- .../Controls/ProportionalDockControl.axaml | 9 +- .../Controls/ProportionalStackPanel.cs | 88 +++++++++---------- 2 files changed, 52 insertions(+), 45 deletions(-) diff --git a/src/Dock.Avalonia/Controls/ProportionalDockControl.axaml b/src/Dock.Avalonia/Controls/ProportionalDockControl.axaml index 6859ab333..32976b692 100644 --- a/src/Dock.Avalonia/Controls/ProportionalDockControl.axaml +++ b/src/Dock.Avalonia/Controls/ProportionalDockControl.axaml @@ -15,7 +15,14 @@ diff --git a/src/Dock.Avalonia/Controls/ProportionalStackPanel.cs b/src/Dock.Avalonia/Controls/ProportionalStackPanel.cs index 6a7b8e6a3..f937bcb27 100644 --- a/src/Dock.Avalonia/Controls/ProportionalStackPanel.cs +++ b/src/Dock.Avalonia/Controls/ProportionalStackPanel.cs @@ -56,29 +56,29 @@ public static void SetProportion(AvaloniaObject control, double value) } /// - /// Defines the IsEmpty attached property. + /// Defines the IsCollapsed attached property. /// - public static readonly AttachedProperty IsEmptyProperty = - AvaloniaProperty.RegisterAttached("IsEmpty", false, false, BindingMode.TwoWay); + public static readonly AttachedProperty IsCollapsedProperty = + AvaloniaProperty.RegisterAttached("IsCollapsed", false, false, BindingMode.TwoWay); /// - /// Gets the value of the IsEmpty attached property on the specified control. + /// Gets the value of the IsCollapsed attached property on the specified control. /// /// The control. - /// The IsEmpty attached property. - public static bool GetIsEmpty(AvaloniaObject control) + /// The IsCollapsed attached property. + public static bool GetIsCollapsed(AvaloniaObject control) { - return control.GetValue(IsEmptyProperty); + return control.GetValue(IsCollapsedProperty); } /// - /// Sets the value of the IsEmpty attached property on the specified control. + /// Sets the value of the IsCollapsed attached property on the specified control. /// /// The control. - /// The value of the IsEmpty property. - public static void SetIsEmpty(AvaloniaObject control, bool value) + /// The value of the IsCollapsed property. + public static void SetIsCollapsed(AvaloniaObject control, bool value) { - control.SetValue(IsEmptyProperty, value); + control.SetValue(IsCollapsedProperty, value); } private void AssignProportions(global::Avalonia.Controls.Controls children) @@ -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; } @@ -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 _)) @@ -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; @@ -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; @@ -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++) @@ -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; } @@ -197,7 +197,7 @@ private double GetTotalSplitterThickness(global::Avalonia.Controls.Controls chil } else { - previousIsEmpty = GetIsEmpty(c); + previousisCollapsed = GetIsCollapsed(c); } } @@ -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++) @@ -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; @@ -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; @@ -351,7 +351,7 @@ protected override Size ArrangeOverride(Size arrangeSize) AssignProportions(Children); - var previousIsEmpty = false; + var previousisCollapsed = false; for (var i = 0; i < Children.Count; i++) { @@ -359,25 +359,25 @@ protected override Size ArrangeOverride(Size arrangeSize) 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); @@ -385,7 +385,7 @@ protected override Size ArrangeOverride(Size arrangeSize) continue; } - previousIsEmpty = false; + previousisCollapsed = false; // Determine the remaining space left to arrange the element var remainingRect = new Rect( @@ -461,8 +461,8 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang static ProportionalStackPanel() { - AffectsParentMeasure(IsEmptyProperty); - AffectsParentArrange(IsEmptyProperty); + AffectsParentMeasure(IsCollapsedProperty); + AffectsParentArrange(IsCollapsedProperty); AffectsParentMeasure(ProportionProperty); AffectsParentArrange(ProportionProperty); }