diff --git a/Perspex.Controls/Primitives/ScrollBar.cs b/Perspex.Controls/Primitives/ScrollBar.cs index fe65e1d474..518d696e3b 100644 --- a/Perspex.Controls/Primitives/ScrollBar.cs +++ b/Perspex.Controls/Primitives/ScrollBar.cs @@ -6,6 +6,8 @@ namespace Perspex.Controls.Primitives { + using System; + public class ScrollBar : TemplatedControl { public static readonly PerspexProperty MinimumProperty = @@ -23,6 +25,23 @@ namespace Perspex.Controls.Primitives public static readonly PerspexProperty OrientationProperty = PerspexProperty.Register("Orientation"); + public ScrollBar() + { + this.GetObservable(OrientationProperty).Subscribe(o => + { + if (o == Orientation.Horizontal) + { + this.Classes.Remove(":vertical"); + this.Classes.Add(":horizontal"); + } + else + { + this.Classes.Remove(":horizontal"); + this.Classes.Add(":vertical"); + } + }); + } + public double Minimum { get { return this.GetValue(MinimumProperty); } diff --git a/Perspex.Controls/Primitives/Track.cs b/Perspex.Controls/Primitives/Track.cs index 727bfb2710..1ead64e517 100644 --- a/Perspex.Controls/Primitives/Track.cs +++ b/Perspex.Controls/Primitives/Track.cs @@ -51,6 +51,7 @@ namespace Perspex.Controls.Primitives AffectsArrange(MinimumProperty); AffectsArrange(MaximumProperty); AffectsArrange(ValueProperty); + AffectsMeasure(OrientationProperty); } public double Minimum @@ -127,6 +128,9 @@ namespace Perspex.Controls.Primitives } else { + var height = finalSize.Height * thumbsize; + var y = finalSize.Height * (this.Value / range); + thumb.Arrange(new Rect(0, y, finalSize.Width, height)); } } @@ -136,16 +140,22 @@ namespace Perspex.Controls.Primitives private void ThumbDragged(object sender, VectorEventArgs e) { var range = this.Maximum - this.Minimum; + var value = this.Value; if (this.Orientation == Orientation.Horizontal) { - var value = this.Value + e.Vector.X * (range / this.ActualSize.Width); + value += e.Vector.X * (range / this.ActualSize.Width); - value = Math.Max(value, this.Minimum); - value = Math.Min(value, this.Maximum - this.ViewportSize); - - this.Value = value; } + else + { + value += e.Vector.Y * (range / this.ActualSize.Height); + } + + value = Math.Max(value, this.Minimum); + value = Math.Min(value, this.Maximum - this.ViewportSize); + + this.Value = value; } } } diff --git a/Perspex.Controls/StackPanel.cs b/Perspex.Controls/StackPanel.cs index 4ce3d9a9ac..49c35fd454 100644 --- a/Perspex.Controls/StackPanel.cs +++ b/Perspex.Controls/StackPanel.cs @@ -114,25 +114,13 @@ namespace Perspex.Controls if (Orientation == Orientation.Vertical) { - childWidth = finalSize.Width; - Rect childFinal = new Rect(0, arrangedHeight, childWidth, childHeight); - - if (childFinal.IsEmpty) - { - child.Arrange(new Rect()); - } - else - { - child.Arrange(childFinal); - } - + child.Arrange(childFinal); arrangedWidth = Math.Max(arrangedWidth, childWidth); arrangedHeight += childHeight + gap; } else { - childHeight = finalSize.Height; Rect childFinal = new Rect(arrangedWidth, 0, childWidth, childHeight); child.Arrange(childFinal); arrangedWidth += childWidth + gap; diff --git a/Perspex.Themes.Default/ScrollBarStyle.cs b/Perspex.Themes.Default/ScrollBarStyle.cs index b59c1b8db7..5783db4b21 100644 --- a/Perspex.Themes.Default/ScrollBarStyle.cs +++ b/Perspex.Themes.Default/ScrollBarStyle.cs @@ -24,7 +24,22 @@ namespace Perspex.Themes.Default Setters = new[] { new Setter(ScrollBar.TemplateProperty, ControlTemplate.Create(this.Template)), - new Setter(ScrollBar.HeightProperty, 20.0), + }, + }, + new Style(x => x.OfType().Class(":horizontal")) + { + Setters = new[] + { + new Setter(ScrollBar.TemplateProperty, ControlTemplate.Create(this.Template)), + new Setter(ScrollBar.HeightProperty, 10.0), + }, + }, + new Style(x => x.OfType().Class(":vertical")) + { + Setters = new[] + { + new Setter(ScrollBar.TemplateProperty, ControlTemplate.Create(this.Template)), + new Setter(ScrollBar.WidthProperty, 10.0), }, }, }); diff --git a/TestApplication/Program.cs b/TestApplication/Program.cs index 62fcee4cc4..49434ecd9f 100644 --- a/TestApplication/Program.cs +++ b/TestApplication/Program.cs @@ -84,8 +84,8 @@ namespace TestApplication static void Main(string[] args) { - //LogManager.Enable(new TestLogger()); - //LogManager.Instance.LogLayoutMessages = true; + LogManager.Enable(new TestLogger()); + LogManager.Instance.LogLayoutMessages = true; App application = new App { @@ -258,6 +258,13 @@ namespace TestApplication Gap = 8, Children = new Controls { + new ScrollBar + { + Orientation = Orientation.Vertical, + ViewportSize = 25, + Value = 25, + Height = 300, + }, new ScrollBar { Orientation = Orientation.Horizontal,