From 713933b7fb78e96070408ca1b966ff35efa26bc4 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Tue, 10 Oct 2017 14:11:51 +0100 Subject: [PATCH 1/3] [Scrollbar] dont try and arrange the thumb and buttons if the extent is zero. --- src/Avalonia.Controls/Primitives/Track.cs | 34 +++++++++++++---------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/Avalonia.Controls/Primitives/Track.cs b/src/Avalonia.Controls/Primitives/Track.cs index 663b7a22d5..ce768fe58d 100644 --- a/src/Avalonia.Controls/Primitives/Track.cs +++ b/src/Avalonia.Controls/Primitives/Track.cs @@ -137,14 +137,17 @@ namespace Avalonia.Controls.Primitives decreaseButton.Arrange(new Rect(0, 0, firstWidth, finalSize.Height)); } - if (thumb != null) + if (!double.IsNaN(thumbWidth)) { - thumb.Arrange(new Rect(firstWidth, 0, thumbWidth, finalSize.Height)); - } - - if (increaseButton != null) - { - increaseButton.Arrange(new Rect(firstWidth + thumbWidth, 0, remaining - firstWidth, finalSize.Height)); + if (thumb != null) + { + thumb.Arrange(new Rect(firstWidth, 0, thumbWidth, finalSize.Height)); + } + + if (increaseButton != null) + { + increaseButton.Arrange(new Rect(firstWidth + thumbWidth, 0, remaining - firstWidth, finalSize.Height)); + } } } else @@ -158,14 +161,17 @@ namespace Avalonia.Controls.Primitives decreaseButton.Arrange(new Rect(0, 0, finalSize.Width, firstHeight)); } - if (thumb != null) - { - thumb.Arrange(new Rect(0, firstHeight, finalSize.Width, thumbHeight)); - } - - if (increaseButton != null) + if (!double.IsNaN(thumbHeight)) { - increaseButton.Arrange(new Rect(0, firstHeight + thumbHeight, finalSize.Width, Math.Max(remaining - firstHeight, 0))); + if (thumb != null) + { + thumb.Arrange(new Rect(0, firstHeight, finalSize.Width, thumbHeight)); + } + + if (increaseButton != null) + { + increaseButton.Arrange(new Rect(0, firstHeight + thumbHeight, finalSize.Width, Math.Max(remaining - firstHeight, 0))); + } } } From db8cd568ac4ca94a1a973408caa3d6ef5d7477c5 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Wed, 11 Oct 2017 13:30:30 +0100 Subject: [PATCH 2/3] [Scrollbar] Simplify the thumb height / thumb width logic. --- src/Avalonia.Controls/Primitives/Track.cs | 24 +++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Controls/Primitives/Track.cs b/src/Avalonia.Controls/Primitives/Track.cs index ce768fe58d..f98ceab23f 100644 --- a/src/Avalonia.Controls/Primitives/Track.cs +++ b/src/Avalonia.Controls/Primitives/Track.cs @@ -128,7 +128,17 @@ namespace Avalonia.Controls.Primitives if (Orientation == Orientation.Horizontal) { - var thumbWidth = double.IsNaN(viewportSize) ? thumb?.DesiredSize.Width ?? 0 : finalSize.Width * viewportSize / extent; + double thumbWidth = 0; + + if (double.IsNaN(viewportSize)) + { + thumbWidth = thumb?.DesiredSize.Width ?? 0; + } + else if (extent > 0) + { + thumbWidth = finalSize.Width * viewportSize / extent; + } + var remaining = finalSize.Width - thumbWidth; var firstWidth = range <= 0 ? 0 : remaining * offset / range; @@ -152,7 +162,17 @@ namespace Avalonia.Controls.Primitives } else { - var thumbHeight = double.IsNaN(viewportSize) ? thumb?.DesiredSize.Height ?? 0 : finalSize.Height * viewportSize / extent; + double thumbHeight = 0; + + if (double.IsNaN(viewportSize)) + { + thumbHeight = thumb?.DesiredSize.Height ?? 0; + } + else if (extent > 0) + { + thumbHeight = finalSize.Height * viewportSize / extent; + } + var remaining = finalSize.Height - thumbHeight; var firstHeight = range <= 0 ? 0 : remaining * offset / range; From eee063455d54350e0ccb38e8a58319e4593c51fa Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Wed, 11 Oct 2017 13:31:24 +0100 Subject: [PATCH 3/3] [Track] remove redundant IsNaN check. --- src/Avalonia.Controls/Primitives/Track.cs | 34 ++++++++++------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/src/Avalonia.Controls/Primitives/Track.cs b/src/Avalonia.Controls/Primitives/Track.cs index f98ceab23f..8c577665d5 100644 --- a/src/Avalonia.Controls/Primitives/Track.cs +++ b/src/Avalonia.Controls/Primitives/Track.cs @@ -147,17 +147,14 @@ namespace Avalonia.Controls.Primitives decreaseButton.Arrange(new Rect(0, 0, firstWidth, finalSize.Height)); } - if (!double.IsNaN(thumbWidth)) + if (thumb != null) { - if (thumb != null) - { - thumb.Arrange(new Rect(firstWidth, 0, thumbWidth, finalSize.Height)); - } - - if (increaseButton != null) - { - increaseButton.Arrange(new Rect(firstWidth + thumbWidth, 0, remaining - firstWidth, finalSize.Height)); - } + thumb.Arrange(new Rect(firstWidth, 0, thumbWidth, finalSize.Height)); + } + + if (increaseButton != null) + { + increaseButton.Arrange(new Rect(firstWidth + thumbWidth, 0, remaining - firstWidth, finalSize.Height)); } } else @@ -181,17 +178,14 @@ namespace Avalonia.Controls.Primitives decreaseButton.Arrange(new Rect(0, 0, finalSize.Width, firstHeight)); } - if (!double.IsNaN(thumbHeight)) + if (thumb != null) + { + thumb.Arrange(new Rect(0, firstHeight, finalSize.Width, thumbHeight)); + } + + if (increaseButton != null) { - if (thumb != null) - { - thumb.Arrange(new Rect(0, firstHeight, finalSize.Width, thumbHeight)); - } - - if (increaseButton != null) - { - increaseButton.Arrange(new Rect(0, firstHeight + thumbHeight, finalSize.Width, Math.Max(remaining - firstHeight, 0))); - } + increaseButton.Arrange(new Rect(0, firstHeight + thumbHeight, finalSize.Width, Math.Max(remaining - firstHeight, 0))); } }