Skip to content

Commit

Permalink
Merge pull request AvaloniaUI#474 from VitalElement/IScrollableUpdates
Browse files Browse the repository at this point in the history
implemented ScrollSize from IScrollable.
  • Loading branch information
grokys committed Mar 17, 2016
2 parents 8e6bbf6 + 4107a59 commit c4f7de1
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 5 deletions.
16 changes: 16 additions & 0 deletions samples/XamlTestApplicationPcl/TestScrollable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ Size IScrollable.Viewport
get { return _viewport; }
}

public Size ScrollSize
{
get
{
return new Size(double.PositiveInfinity, 1);
}
}

public Size PageScrollSize
{
get
{
return new Size(double.PositiveInfinity, Bounds.Height);
}
}

protected override Size MeasureOverride(Size availableSize)
{
using (var line = new FormattedText(
Expand Down
23 changes: 18 additions & 5 deletions src/Perspex.Controls/Presenters/ScrollContentPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,24 @@ protected override void OnPointerWheelChanged(PointerWheelEventArgs e)
{
if (Extent.Height > Viewport.Height)
{
var y = Offset.Y + (-e.Delta.Y * 50);
y = Math.Max(y, 0);
y = Math.Min(y, Extent.Height - Viewport.Height);
Offset = new Vector(Offset.X, y);
e.Handled = true;
var scrollable = Child as IScrollable;

if (scrollable != null)
{
var y = Offset.Y + (-e.Delta.Y * scrollable.ScrollSize.Height);
y = Math.Max(y, 0);
y = Math.Min(y, Extent.Height - Viewport.Height);
Offset = new Vector(Offset.X, y);
e.Handled = true;
}
else
{
var y = Offset.Y + (-e.Delta.Y * 50);
y = Math.Max(y, 0);
y = Math.Min(y, Extent.Height - Viewport.Height);
Offset = new Vector(Offset.X, y);
e.Handled = true;
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/Perspex.Controls/Primitives/IScrollable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,15 @@ public interface IScrollable
/// Gets the size of the viewport, in logical units.
/// </summary>
Size Viewport { get; }

/// <summary>
/// Gets the size to scroll by, in logical units.
/// </summary>
Size ScrollSize { get; }

/// <summary>
/// Gets the size to page by, in logical units.
/// </summary>
Size PageScrollSize { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,22 @@ public Size Viewport
}
}

public Size ScrollSize
{
get
{
return new Size(double.PositiveInfinity, 1);
}
}

public Size PageScrollSize
{
get
{
return new Size(double.PositiveInfinity, Viewport.Height);
}
}

protected override Size MeasureOverride(Size availableSize)
{
AvailableSize = availableSize;
Expand Down

0 comments on commit c4f7de1

Please sign in to comment.