Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added IScrollInfo and ScrollInfoAdapter #122

Merged
merged 1 commit into from
Sep 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Perspex.Controls/Perspex.Controls.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@
<Compile Include="Platform\IPopupImpl.cs" />
<Compile Include="Platform\ITopLevelImpl.cs" />
<Compile Include="PlacementMode.cs" />
<Compile Include="Primitives\IScrollInfo.cs" />
<Compile Include="Primitives\Popup.cs" />
<Compile Include="Primitives\ScrollInfoAdapter.cs" />
<Compile Include="Templates\ControlTemplate`2.cs" />
<Compile Include="Templates\DataTemplate`1.cs" />
<Compile Include="Templates\IControlTemplate.cs" />
Expand Down
95 changes: 95 additions & 0 deletions src/Perspex.Controls/Primitives/IScrollInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Perspex.Controls.Primitives
{

public interface IScrollInfoBase
{
/// <summary>
/// ScrollOwner is the container that controls any scrollbars, headers, etc... that are dependant
/// on this IScrollInfo's properties. Implementers of IScrollInfo should call InvalidateScrollInfo()
/// on this object when properties change.
/// </summary>
ScrollViewer ScrollOwner { get; set; }

Rect MakeVisible(Visual visual, Rect rectangle);
}

public interface IVerticalScrollInfo : IScrollInfoBase
{
/// <summary>
/// VerticalOffset is the vertical offset into the scrolled content that represents the first unit visible.
/// </summary>
double VerticalOffset { get; set; }

/// <summary>
/// ExtentHeight contains the full vertical range of the scrolled content.
/// </summary>
double ExtentHeight { get; }

/// <summary>
/// ViewportHeight contains the currently visible vertical range of the scrolled content.
/// </summary>
double ViewportHeight { get; }

/// <summary>
/// This property indicates to the IScrollInfo whether or not it can scroll in the vertical given dimension.
/// </summary>
bool CanVerticallyScroll { get; set; }

void LineDown();

void LineUp();

void MouseWheelDown();

void MouseWheelUp();

void PageDown();

void PageUp();
}

public interface IHorizontalScrollInfo : IScrollInfoBase
{
/// <summary>
/// ExtentWidth contains the full horizontal range of the scrolled content.
/// </summary>
double ExtentWidth { get; }

/// <summary>
/// ViewportWidth contains the currently visible horizontal range of the scrolled content.
/// </summary>
double ViewportWidth { get; }

/// <summary>
/// HorizontalOffset is the horizontal offset into the scrolled content that represents the first unit visible.
/// </summary>
double HorizontalOffset { get; set; }

/// <summary>
/// This property indicates to the IScrollInfo whether or not it can scroll in the horizontal given dimension.
/// </summary>
bool CanHorizontallyScroll { get; set; }

void LineLeft();

void LineRight();

void MouseWheelLeft();

void MouseWheelRight();

void PageLeft();

void PageRight();
}

public interface IScrollInfo : IHorizontalScrollInfo, IVerticalScrollInfo
{
}
}
124 changes: 124 additions & 0 deletions src/Perspex.Controls/Primitives/ScrollInfoAdapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
namespace Perspex.Controls.Primitives
{
public class ScrollInfoAdapter : IScrollInfo
{
private readonly IScrollInfoBase nfo;
public ScrollInfoAdapter(IScrollInfoBase nfo)
{
this.nfo = nfo;
}

public ScrollViewer ScrollOwner
{
get { return this.nfo.ScrollOwner; }
set { this.nfo.ScrollOwner = value; }
}

public double ExtentWidth => (this.nfo as IHorizontalScrollInfo)?.ExtentWidth ?? 0;

public double ViewportWidth => (this.nfo as IHorizontalScrollInfo)?.ViewportWidth ?? 0;

public double ExtentHeight => (this.nfo as IVerticalScrollInfo)?.ExtentHeight ?? 0;

public double ViewportHeight => (this.nfo as IVerticalScrollInfo)?.ViewportHeight ?? 0;

private double horizontalOffset;
public double HorizontalOffset
{
get
{
return (this.nfo as IHorizontalScrollInfo)?.HorizontalOffset ?? this.horizontalOffset;
}

set
{
var info = (this.nfo as IHorizontalScrollInfo);
if (info == null)
this.horizontalOffset = value;
else
info.HorizontalOffset = value;
}
}

private double verticalOffset;
public double VerticalOffset
{
get
{
return (this.nfo as IVerticalScrollInfo)?.VerticalOffset ?? this.verticalOffset;
}

set
{
var info = (this.nfo as IVerticalScrollInfo);
if (info == null)
this.verticalOffset = value;
else
info.VerticalOffset = value;
}
}

public void LineLeft() => (this.nfo as IHorizontalScrollInfo)?.LineLeft();

public void LineRight() => (this.nfo as IHorizontalScrollInfo)?.LineRight();

public void MouseWheelLeft() => (this.nfo as IHorizontalScrollInfo)?.MouseWheelLeft();

public void MouseWheelRight() => (this.nfo as IHorizontalScrollInfo)?.MouseWheelRight();

public void PageLeft() => (this.nfo as IHorizontalScrollInfo)?.PageLeft();

public Rect MakeVisible(Visual visual, Rect rectangle) => this.nfo.MakeVisible(visual, rectangle);

public void PageRight() => (this.nfo as IHorizontalScrollInfo)?.PageRight();

public void LineDown() => (this.nfo as IVerticalScrollInfo)?.LineDown();

public void LineUp() => (this.nfo as IVerticalScrollInfo)?.LineUp();

public void MouseWheelDown() => (this.nfo as IVerticalScrollInfo)?.MouseWheelDown();

public void MouseWheelUp() => (this.nfo as IVerticalScrollInfo)?.MouseWheelUp();

public void PageDown() => (this.nfo as IVerticalScrollInfo)?.PageDown();

public void PageUp() => (this.nfo as IVerticalScrollInfo)?.PageUp();

private bool canVerticallyScroll;
public bool CanVerticallyScroll
{
get
{
return (this.nfo as IVerticalScrollInfo)?.CanVerticallyScroll ?? this.canVerticallyScroll;
}

set
{
var info = (this.nfo as IVerticalScrollInfo);
if (info == null)
this.canVerticallyScroll = value;
else
info.CanVerticallyScroll = value;
}
}

private bool canHorizontallyScroll;
public bool CanHorizontallyScroll
{
get
{
return (this.nfo as IHorizontalScrollInfo)?.CanHorizontallyScroll ?? this.canHorizontallyScroll;
}

set
{
var info = (this.nfo as IHorizontalScrollInfo);
if (info == null)
this.canHorizontallyScroll = value;
else
info.CanHorizontallyScroll = value;
}
}

}
}