Skip to content

Commit 7a9310c

Browse files
committed
fix: #1791
1 parent 2ea451f commit 7a9310c

4 files changed

Lines changed: 31 additions & 18 deletions

File tree

src/Avalonia/HandyControl_Avalonia/Controls/Panel/UniformSpacingPanel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ protected override Size MeasureOverride(Size availableSize)
163163
for (int i = 0, count = Children.Count; i < count; ++i)
164164
{
165165
var child = Children[i];
166+
if (!child.IsVisible) continue;
166167

167168
if (itemHorizontalAlignmentSet)
168169
{
@@ -192,6 +193,7 @@ protected override Size MeasureOverride(Size availableSize)
192193
for (int i = 0, count = Children.Count; i < count; i++)
193194
{
194195
var child = Children[i];
196+
if (!child.IsVisible) continue;
195197

196198
if (itemHorizontalAlignmentSet)
197199
{
@@ -258,6 +260,7 @@ protected override Size ArrangeOverride(Size finalSize)
258260
for (int i = 0, count = Children.Count; i < count; i++)
259261
{
260262
var child = Children[i];
263+
if (!child.IsVisible) continue;
261264

262265
var sz = new PanelUvSize(
263266
_orientation,
@@ -327,6 +330,7 @@ private void ArrangeLine(double lineV, bool useItemU, double itemU, double spaci
327330
for (int i = 0; i < Children.Count; i++)
328331
{
329332
Control child = Children[i];
333+
if (!child.IsVisible) continue;
330334
var childSize = new PanelUvSize(orientation, child.DesiredSize);
331335
double layoutSlotU = useItemU ? itemU : childSize.U;
332336

@@ -354,6 +358,7 @@ private void ArrangeWrapLine(
354358
for (int i = start; i < end; i++)
355359
{
356360
var child = Children[i];
361+
if (!child.IsVisible) continue;
357362

358363
var childSize = new PanelUvSize(_orientation, child.DesiredSize);
359364
double layoutSlotU = useItemU ? itemU : childSize.U;

src/Shared/HandyControl_Shared/Controls/Panel/CirclePanel.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
using System.Windows;
34
using System.Windows.Controls;
45
using System.Windows.Media;
@@ -38,12 +39,13 @@ public double OffsetAngle
3839
protected override Size MeasureOverride(Size availableSize)
3940
{
4041
var diameter = Diameter;
42+
var layoutChildren = Children.OfType<UIElement>().Where(element => element.Visibility != Visibility.Collapsed).ToList();
4143

42-
if (Children.Count == 0) return new Size(diameter, diameter);
44+
if (layoutChildren.Count == 0) return new Size(diameter, diameter);
4345

4446
var newSize = new Size(diameter, diameter);
4547

46-
foreach (UIElement element in Children)
48+
foreach (var element in layoutChildren)
4749
{
4850
element.Measure(newSize);
4951
}
@@ -55,12 +57,18 @@ protected override Size ArrangeOverride(Size finalSize)
5557
{
5658
var keepVertical = KeepVertical;
5759
var offsetAngle = OffsetAngle;
60+
var layoutChildren = Children.OfType<UIElement>().Where(element => element.Visibility != Visibility.Collapsed).ToList();
61+
62+
if (layoutChildren.Count == 0)
63+
{
64+
return finalSize;
65+
}
5866

5967
var i = 0;
60-
var perDeg = 360.0 / Children.Count;
68+
var perDeg = 360.0 / layoutChildren.Count;
6169
var radius = Diameter / 2;
6270

63-
foreach (UIElement element in Children)
71+
foreach (var element in layoutChildren)
6472
{
6573
var centerX = element.DesiredSize.Width / 2.0;
6674
var centerY = element.DesiredSize.Height / 2.0;

src/Shared/HandyControl_Shared/Controls/Panel/HoneycombPanel.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
using System.Windows;
34
using System.Windows.Controls;
45

@@ -60,21 +61,19 @@ private static int GetYCount(int count)
6061
protected override Size MeasureOverride(Size availableSize)
6162
{
6263
var maxSize = new Size();
64+
var layoutChildren = InternalChildren.Cast<UIElement>().Where(child => child != null && child.Visibility != Visibility.Collapsed).ToList();
6365

64-
foreach (UIElement child in InternalChildren)
66+
foreach (var child in layoutChildren)
6567
{
66-
if (child != null)
67-
{
68-
child.Measure(availableSize);
69-
maxSize.Width = Math.Max(maxSize.Width, child.DesiredSize.Width);
70-
maxSize.Height = Math.Max(maxSize.Height, child.DesiredSize.Height);
71-
}
68+
child.Measure(availableSize);
69+
maxSize.Width = Math.Max(maxSize.Width, child.DesiredSize.Width);
70+
maxSize.Height = Math.Max(maxSize.Height, child.DesiredSize.Height);
7271
}
7372

7473
_unitLength = Math.Max(maxSize.Width, maxSize.Height) / 2;
7574

76-
var xCount = GetXCount(InternalChildren.Count);
77-
var yCount = GetYCount(InternalChildren.Count);
75+
var xCount = GetXCount(layoutChildren.Count);
76+
var yCount = GetYCount(layoutChildren.Count);
7877

7978
var availableWidth = xCount * _unitLength;
8079
var availableHeight = yCount * Math.Pow(3, 0.5) * _unitLength + _unitLength * 2;
@@ -90,6 +89,7 @@ protected override Size ArrangeOverride(Size finalSize)
9089

9190
foreach (UIElement child in InternalChildren)
9291
{
92+
if (child == null || child.Visibility == Visibility.Collapsed) continue;
9393
child.Arrange(_stuffer.Move());
9494
}
9595

src/Shared/HandyControl_Shared/Controls/Panel/UniformSpacingPanel.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ private void ArrangeWrapLine(double v, double lineV, int start, int end, bool us
138138
for (var i = start; i < end; i++)
139139
{
140140
var child = children[i];
141-
if (child == null) continue;
141+
if (child == null || child.Visibility == Visibility.Collapsed) continue;
142142

143143
var childSize = new PanelUvSize(_orientation, child.DesiredSize);
144144
var layoutSlotU = useItemU ? itemU : childSize.U;
@@ -161,7 +161,7 @@ private void ArrangeLine(double lineV, bool useItemU, double itemU, double spaci
161161
for (var i = 0; i < children.Count; i++)
162162
{
163163
var child = children[i];
164-
if (child == null) continue;
164+
if (child == null || child.Visibility == Visibility.Collapsed) continue;
165165

166166
var childSize = new PanelUvSize(_orientation, child.DesiredSize);
167167
var layoutSlotU = useItemU ? itemU : childSize.U;
@@ -214,7 +214,7 @@ protected override Size MeasureOverride(Size constraint)
214214
for (int i = 0, count = children.Count; i < count; ++i)
215215
{
216216
var child = children[i];
217-
if (child == null) continue;
217+
if (child == null || child.Visibility == Visibility.Collapsed) continue;
218218

219219
if (itemHorizontalAlignmentSet)
220220
{
@@ -244,7 +244,7 @@ protected override Size MeasureOverride(Size constraint)
244244
for (int i = 0, count = children.Count; i < count; i++)
245245
{
246246
var child = children[i];
247-
if (child == null) continue;
247+
if (child == null || child.Visibility == Visibility.Collapsed) continue;
248248

249249
if (itemHorizontalAlignmentSet)
250250
{
@@ -336,7 +336,7 @@ protected override Size ArrangeOverride(Size finalSize)
336336
for (int i = 0, count = children.Count; i < count; i++)
337337
{
338338
var child = children[i];
339-
if (child == null) continue;
339+
if (child == null || child.Visibility == Visibility.Collapsed) continue;
340340

341341
var sz = new PanelUvSize(
342342
_orientation,

0 commit comments

Comments
 (0)