Browse Source

Added IScrollInfo and ScrollInfoAdapter

Ceterum censeo StyleCopum esse delendum
pull/122/head
Nikita Tsukanov 11 years ago
parent
commit
d0fadf3535
  1. 2
      src/Perspex.Controls/Perspex.Controls.csproj
  2. 95
      src/Perspex.Controls/Primitives/IScrollInfo.cs
  3. 124
      src/Perspex.Controls/Primitives/ScrollInfoAdapter.cs

2
src/Perspex.Controls/Perspex.Controls.csproj

@ -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" />

95
src/Perspex.Controls/Primitives/IScrollInfo.cs

@ -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
src/Perspex.Controls/Primitives/ScrollInfoAdapter.cs

@ -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;
}
}
}
}
Loading…
Cancel
Save