Browse Source

Added vertical scrollbar.

STILL VERY HACKY.
pull/4/head
Steven Kirk 11 years ago
parent
commit
79c071a6d0
  1. 19
      Perspex.Controls/Primitives/ScrollBar.cs
  2. 20
      Perspex.Controls/Primitives/Track.cs
  3. 14
      Perspex.Controls/StackPanel.cs
  4. 17
      Perspex.Themes.Default/ScrollBarStyle.cs
  5. 11
      TestApplication/Program.cs

19
Perspex.Controls/Primitives/ScrollBar.cs

@ -6,6 +6,8 @@
namespace Perspex.Controls.Primitives
{
using System;
public class ScrollBar : TemplatedControl
{
public static readonly PerspexProperty<double> MinimumProperty =
@ -23,6 +25,23 @@ namespace Perspex.Controls.Primitives
public static readonly PerspexProperty<Orientation> OrientationProperty =
PerspexProperty.Register<ScrollBar, Orientation>("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); }

20
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;
}
}
}

14
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;

17
Perspex.Themes.Default/ScrollBarStyle.cs

@ -24,7 +24,22 @@ namespace Perspex.Themes.Default
Setters = new[]
{
new Setter(ScrollBar.TemplateProperty, ControlTemplate.Create<ScrollBar>(this.Template)),
new Setter(ScrollBar.HeightProperty, 20.0),
},
},
new Style(x => x.OfType<ScrollBar>().Class(":horizontal"))
{
Setters = new[]
{
new Setter(ScrollBar.TemplateProperty, ControlTemplate.Create<ScrollBar>(this.Template)),
new Setter(ScrollBar.HeightProperty, 10.0),
},
},
new Style(x => x.OfType<ScrollBar>().Class(":vertical"))
{
Setters = new[]
{
new Setter(ScrollBar.TemplateProperty, ControlTemplate.Create<ScrollBar>(this.Template)),
new Setter(ScrollBar.WidthProperty, 10.0),
},
},
});

11
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,

Loading…
Cancel
Save