71 changed files with 806 additions and 426 deletions
@ -0,0 +1,30 @@ |
|||||
|
using System.Resources; |
||||
|
using System.Reflection; |
||||
|
using System.Runtime.CompilerServices; |
||||
|
using System.Runtime.InteropServices; |
||||
|
|
||||
|
// General Information about an assembly is controlled through the following
|
||||
|
// set of attributes. Change these attribute values to modify the information
|
||||
|
// associated with an assembly.
|
||||
|
[assembly: AssemblyTitle("XamlTestApplicationPcl")] |
||||
|
[assembly: AssemblyDescription("")] |
||||
|
[assembly: AssemblyConfiguration("")] |
||||
|
[assembly: AssemblyCompany("")] |
||||
|
[assembly: AssemblyProduct("XamlTestApplicationPcl")] |
||||
|
[assembly: AssemblyCopyright("Copyright © 2015")] |
||||
|
[assembly: AssemblyTrademark("")] |
||||
|
[assembly: AssemblyCulture("")] |
||||
|
[assembly: NeutralResourcesLanguage("en")] |
||||
|
|
||||
|
// Version information for an assembly consists of the following four values:
|
||||
|
//
|
||||
|
// Major Version
|
||||
|
// Minor Version
|
||||
|
// Build Number
|
||||
|
// Revision
|
||||
|
//
|
||||
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
|
// by using the '*' as shown below:
|
||||
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||
|
[assembly: AssemblyVersion("1.0.0.0")] |
||||
|
[assembly: AssemblyFileVersion("1.0.0.0")] |
||||
@ -0,0 +1,22 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
using Perspex; |
||||
|
using Perspex.Themes.Default; |
||||
|
|
||||
|
namespace XamlTestApplication |
||||
|
{ |
||||
|
public abstract class XamlTestApp : Application |
||||
|
{ |
||||
|
protected abstract void RegisterPlatform(); |
||||
|
|
||||
|
public XamlTestApp() |
||||
|
{ |
||||
|
RegisterServices(); |
||||
|
RegisterPlatform(); |
||||
|
Styles = new DefaultTheme(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,130 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> |
||||
|
<PropertyGroup> |
||||
|
<MinimumVisualStudioVersion>10.0</MinimumVisualStudioVersion> |
||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
||||
|
<ProjectGuid>{EA113F1A-D8D7-4142-9948-353270E7EBAE}</ProjectGuid> |
||||
|
<OutputType>Library</OutputType> |
||||
|
<AppDesignerFolder>Properties</AppDesignerFolder> |
||||
|
<RootNamespace>XamlTestApplication</RootNamespace> |
||||
|
<AssemblyName>XamlTestApplicationPcl</AssemblyName> |
||||
|
<DefaultLanguage>en-US</DefaultLanguage> |
||||
|
<FileAlignment>512</FileAlignment> |
||||
|
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> |
||||
|
<TargetFrameworkProfile>Profile7</TargetFrameworkProfile> |
||||
|
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
||||
|
<DebugSymbols>true</DebugSymbols> |
||||
|
<DebugType>full</DebugType> |
||||
|
<Optimize>false</Optimize> |
||||
|
<OutputPath>bin\Debug\</OutputPath> |
||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants> |
||||
|
<ErrorReport>prompt</ErrorReport> |
||||
|
<WarningLevel>4</WarningLevel> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
||||
|
<DebugType>pdbonly</DebugType> |
||||
|
<Optimize>true</Optimize> |
||||
|
<OutputPath>bin\Release\</OutputPath> |
||||
|
<DefineConstants>TRACE</DefineConstants> |
||||
|
<ErrorReport>prompt</ErrorReport> |
||||
|
<WarningLevel>4</WarningLevel> |
||||
|
</PropertyGroup> |
||||
|
<ItemGroup> |
||||
|
<!-- A reference to the entire .NET Framework is automatically included --> |
||||
|
<EmbeddedResource Include="Views\MainWindow.paml"> |
||||
|
<SubType>Designer</SubType> |
||||
|
</EmbeddedResource> |
||||
|
</ItemGroup> |
||||
|
<ItemGroup> |
||||
|
<Compile Include="Properties\AssemblyInfo.cs" /> |
||||
|
<Compile Include="ViewModels\MainWindowViewModel.cs" /> |
||||
|
<Compile Include="ViewModels\TestItem.cs" /> |
||||
|
<Compile Include="ViewModels\TestNode.cs" /> |
||||
|
<Compile Include="Views\MainWindow.cs" /> |
||||
|
<Compile Include="XamlTestApp.cs" /> |
||||
|
</ItemGroup> |
||||
|
<ItemGroup> |
||||
|
<Content Include="github_icon.png"> |
||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
||||
|
</Content> |
||||
|
</ItemGroup> |
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\..\src\Markup\Perspex.Markup.Xaml\Perspex.Markup.Xaml.csproj"> |
||||
|
<Project>{3e53a01a-b331-47f3-b828-4a5717e77a24}</Project> |
||||
|
<Name>Perspex.Markup.Xaml</Name> |
||||
|
</ProjectReference> |
||||
|
<ProjectReference Include="..\..\src\Perspex.Animation\Perspex.Animation.csproj"> |
||||
|
<Project>{d211e587-d8bc-45b9-95a4-f297c8fa5200}</Project> |
||||
|
<Name>Perspex.Animation</Name> |
||||
|
</ProjectReference> |
||||
|
<ProjectReference Include="..\..\src\Perspex.Application\Perspex.Application.csproj"> |
||||
|
<Project>{799a7bb5-3c2c-48b6-85a7-406a12c420da}</Project> |
||||
|
<Name>Perspex.Application</Name> |
||||
|
</ProjectReference> |
||||
|
<ProjectReference Include="..\..\src\Perspex.Base\Perspex.Base.csproj"> |
||||
|
<Project>{b09b78d8-9b26-48b0-9149-d64a2f120f3f}</Project> |
||||
|
<Name>Perspex.Base</Name> |
||||
|
</ProjectReference> |
||||
|
<ProjectReference Include="..\..\src\Perspex.Controls\Perspex.Controls.csproj"> |
||||
|
<Project>{d2221c82-4a25-4583-9b43-d791e3f6820c}</Project> |
||||
|
<Name>Perspex.Controls</Name> |
||||
|
</ProjectReference> |
||||
|
<ProjectReference Include="..\..\src\Perspex.Diagnostics\Perspex.Diagnostics.csproj"> |
||||
|
<Project>{7062ae20-5dcc-4442-9645-8195bdece63e}</Project> |
||||
|
<Name>Perspex.Diagnostics</Name> |
||||
|
</ProjectReference> |
||||
|
<ProjectReference Include="..\..\src\Perspex.HtmlRenderer\Perspex.HtmlRenderer.csproj"> |
||||
|
<Project>{5fb2b005-0a7f-4dad-add4-3ed01444e63d}</Project> |
||||
|
<Name>Perspex.HtmlRenderer</Name> |
||||
|
</ProjectReference> |
||||
|
<ProjectReference Include="..\..\src\Perspex.Input\Perspex.Input.csproj"> |
||||
|
<Project>{62024b2d-53eb-4638-b26b-85eeaa54866e}</Project> |
||||
|
<Name>Perspex.Input</Name> |
||||
|
</ProjectReference> |
||||
|
<ProjectReference Include="..\..\src\Perspex.Interactivity\Perspex.Interactivity.csproj"> |
||||
|
<Project>{6b0ed19d-a08b-461c-a9d9-a9ee40b0c06b}</Project> |
||||
|
<Name>Perspex.Interactivity</Name> |
||||
|
</ProjectReference> |
||||
|
<ProjectReference Include="..\..\src\Perspex.Layout\Perspex.Layout.csproj"> |
||||
|
<Project>{42472427-4774-4c81-8aff-9f27b8e31721}</Project> |
||||
|
<Name>Perspex.Layout</Name> |
||||
|
</ProjectReference> |
||||
|
<ProjectReference Include="..\..\src\Perspex.ReactiveUI\Perspex.ReactiveUI.csproj"> |
||||
|
<Project>{6417b24e-49c2-4985-8db2-3ab9d898ec91}</Project> |
||||
|
<Name>Perspex.ReactiveUI</Name> |
||||
|
</ProjectReference> |
||||
|
<ProjectReference Include="..\..\src\Perspex.SceneGraph\Perspex.SceneGraph.csproj"> |
||||
|
<Project>{eb582467-6abb-43a1-b052-e981ba910e3a}</Project> |
||||
|
<Name>Perspex.SceneGraph</Name> |
||||
|
</ProjectReference> |
||||
|
<ProjectReference Include="..\..\src\Perspex.Styling\Perspex.Styling.csproj"> |
||||
|
<Project>{f1baa01a-f176-4c6a-b39d-5b40bb1b148f}</Project> |
||||
|
<Name>Perspex.Styling</Name> |
||||
|
</ProjectReference> |
||||
|
<ProjectReference Include="..\..\src\Perspex.Themes.Default\Perspex.Themes.Default.csproj"> |
||||
|
<Project>{3e10a5fa-e8da-48b1-ad44-6a5b6cb7750f}</Project> |
||||
|
<Name>Perspex.Themes.Default</Name> |
||||
|
</ProjectReference> |
||||
|
</ItemGroup> |
||||
|
<ItemGroup> |
||||
|
<Reference Include="Splat, Version=1.6.2.0, Culture=neutral, processorArchitecture=MSIL"> |
||||
|
<HintPath>..\..\packages\Splat.1.6.2\lib\Portable-net45+win+wpa81+wp80\Splat.dll</HintPath> |
||||
|
<Private>True</Private> |
||||
|
</Reference> |
||||
|
</ItemGroup> |
||||
|
<ItemGroup> |
||||
|
<None Include="packages.config" /> |
||||
|
</ItemGroup> |
||||
|
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" /> |
||||
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. |
||||
|
Other similar extension points exist, see Microsoft.Common.targets. |
||||
|
<Target Name="BeforeBuild"> |
||||
|
</Target> |
||||
|
<Target Name="AfterBuild"> |
||||
|
</Target> |
||||
|
--> |
||||
|
</Project> |
||||
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
@ -0,0 +1,4 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<packages> |
||||
|
<package id="Splat" version="1.6.2" targetFramework="portable45-net45+win8" /> |
||||
|
</packages> |
||||
@ -0,0 +1,63 @@ |
|||||
|
// Copyright (c) The Perspex Project. All rights reserved.
|
||||
|
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
||||
|
|
||||
|
using System; |
||||
|
using System.Runtime.InteropServices; |
||||
|
using Perspex.Cairo.Media; |
||||
|
using Perspex.Media; |
||||
|
using Perspex.Platform; |
||||
|
using Perspex.Rendering; |
||||
|
|
||||
|
namespace Perspex.Cairo |
||||
|
{ |
||||
|
using global::Cairo; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// A cairo render target.
|
||||
|
/// </summary>
|
||||
|
public class RenderTarget : IRenderTarget |
||||
|
{ |
||||
|
private readonly Surface _surface; |
||||
|
private Gtk.Window _window; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="RenderTarget"/> class.
|
||||
|
/// </summary>
|
||||
|
/// <param name="window">The window.</param>
|
||||
|
/// <param name="width">The width of the window.</param>
|
||||
|
/// <param name="height">The height of the window.</param>
|
||||
|
public RenderTarget(Gtk.Window window, double width, double height) |
||||
|
{ |
||||
|
_window = window; |
||||
|
} |
||||
|
|
||||
|
public RenderTarget(ImageSurface surface) |
||||
|
{ |
||||
|
_surface = surface; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Resizes the renderer.
|
||||
|
/// </summary>
|
||||
|
/// <param name="width">The new width.</param>
|
||||
|
/// <param name="height">The new height.</param>
|
||||
|
public void Resize(int width, int height) |
||||
|
{ |
||||
|
// Don't need to do anything here.
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Creates a cairo surface that targets a platform-specific resource.
|
||||
|
/// </summary>
|
||||
|
/// <returns>A surface wrapped in an <see cref="IDrawingContext"/>.</returns>
|
||||
|
public IDrawingContext CreateDrawingContext() |
||||
|
{ |
||||
|
if(_surface != null) |
||||
|
return new DrawingContext(_surface); |
||||
|
return new DrawingContext(_window.GdkWindow); |
||||
|
} |
||||
|
|
||||
|
public void Dispose() => _surface?.Dispose(); |
||||
|
} |
||||
|
} |
||||
@ -1,81 +0,0 @@ |
|||||
// Copyright (c) The Perspex Project. All rights reserved.
|
|
||||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|
||||
|
|
||||
using System; |
|
||||
using System.Runtime.InteropServices; |
|
||||
using Perspex.Cairo.Media; |
|
||||
using Perspex.Media; |
|
||||
using Perspex.Platform; |
|
||||
using Perspex.Rendering; |
|
||||
|
|
||||
namespace Perspex.Cairo |
|
||||
{ |
|
||||
using global::Cairo; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// A cairo renderer.
|
|
||||
/// </summary>
|
|
||||
public class Renderer : RendererBase |
|
||||
{ |
|
||||
private readonly Surface _surface; |
|
||||
private Gdk.Window _window; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Initializes a new instance of the <see cref="Renderer"/> class.
|
|
||||
/// </summary>
|
|
||||
/// <param name="handle">The window handle.</param>
|
|
||||
/// <param name="width">The width of the window.</param>
|
|
||||
/// <param name="height">The height of the window.</param>
|
|
||||
public Renderer(IPlatformHandle handle, double width, double height) |
|
||||
{ |
|
||||
} |
|
||||
|
|
||||
public Renderer(ImageSurface surface) |
|
||||
{ |
|
||||
_surface = surface; |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Resizes the renderer.
|
|
||||
/// </summary>
|
|
||||
/// <param name="width">The new width.</param>
|
|
||||
/// <param name="height">The new height.</param>
|
|
||||
public override void Resize(int width, int height) |
|
||||
{ |
|
||||
// Don't need to do anything here.
|
|
||||
} |
|
||||
|
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Creates a cairo surface that targets a platform-specific resource.
|
|
||||
/// </summary>
|
|
||||
/// <param name="handle">The platform-specific handle.</param>
|
|
||||
/// <returns>A surface wrapped in an <see cref="IDrawingContext"/>.</returns>
|
|
||||
protected override IDrawingContext CreateDrawingContext(IPlatformHandle handle) |
|
||||
{ |
|
||||
switch (handle.HandleDescriptor) |
|
||||
{ |
|
||||
case "RTB": |
|
||||
return new DrawingContext(_surface); |
|
||||
case "GdkWindow": |
|
||||
if (_window == null) |
|
||||
_window = new Gdk.Window(handle.Handle); |
|
||||
|
|
||||
return new DrawingContext(_window); |
|
||||
default: |
|
||||
throw new NotSupportedException(string.Format( |
|
||||
"Don't know how to create a Cairo renderer from a '{0}' handle", |
|
||||
handle.HandleDescriptor)); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[DllImport("user32.dll")] |
|
||||
private static extern IntPtr GetDC(IntPtr hwnd); |
|
||||
|
|
||||
public override void Dispose() |
|
||||
{ |
|
||||
if (_surface != null) |
|
||||
_surface.Dispose(); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,64 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
using Perspex.Platform; |
||||
|
using Perspex.Rendering; |
||||
|
using Perspex.Threading; |
||||
|
|
||||
|
namespace Perspex.Controls.Platform |
||||
|
{ |
||||
|
public interface ITopLevelRenderer |
||||
|
{ |
||||
|
void Attach(TopLevel topLevel); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
class DefaultTopLevelRenderer : ITopLevelRenderer |
||||
|
{ |
||||
|
|
||||
|
public void Attach(TopLevel topLevel) |
||||
|
{ |
||||
|
var resources = new List<IDisposable>(); |
||||
|
var initialClientSize = topLevel.PlatformImpl.ClientSize; |
||||
|
|
||||
|
|
||||
|
var queueManager = ((IRenderRoot)topLevel).RenderQueueManager; |
||||
|
|
||||
|
if (queueManager == null) |
||||
|
return; |
||||
|
|
||||
|
var platformRender = PerspexLocator.Current.GetService<IPlatformRenderInterface>(); |
||||
|
if(platformRender == null) |
||||
|
return; |
||||
|
|
||||
|
var viewport = platformRender |
||||
|
.CreateRenderer(topLevel.PlatformImpl.Handle, initialClientSize.Width, initialClientSize.Height); |
||||
|
resources.Add(viewport); |
||||
|
|
||||
|
|
||||
|
resources.Add(topLevel.GetObservable(TopLevel.ClientSizeProperty).Subscribe(clientSize => |
||||
|
{ |
||||
|
viewport.Resize((int) clientSize.Width, (int) clientSize.Height); |
||||
|
})); |
||||
|
resources.Add(queueManager.RenderNeeded.Subscribe(_ |
||||
|
=> |
||||
|
Dispatcher.UIThread.InvokeAsync(() => topLevel.PlatformImpl.Invalidate(new Rect(topLevel.ClientSize))))); |
||||
|
|
||||
|
topLevel.PlatformImpl.Paint = rect => |
||||
|
{ |
||||
|
viewport.Render(topLevel); |
||||
|
queueManager.RenderFinished(); |
||||
|
}; |
||||
|
|
||||
|
topLevel.Closed += delegate |
||||
|
{ |
||||
|
foreach (var disposable in resources) |
||||
|
disposable.Dispose(); |
||||
|
resources.Clear(); |
||||
|
}; |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,76 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
using System.Reactive.Disposables; |
||||
|
using Perspex.Media.Imaging; |
||||
|
|
||||
|
namespace Perspex.Media |
||||
|
{ |
||||
|
public class ValidatingDrawingContext : IDrawingContext |
||||
|
{ |
||||
|
private readonly IDrawingContext _base; |
||||
|
|
||||
|
public ValidatingDrawingContext(IDrawingContext @base) |
||||
|
{ |
||||
|
_base = @base; |
||||
|
} |
||||
|
|
||||
|
public void Dispose() |
||||
|
{ |
||||
|
_base.Dispose(); |
||||
|
} |
||||
|
|
||||
|
public Matrix CurrentTransform => _base.CurrentTransform; |
||||
|
public void DrawImage(IBitmap source, double opacity, Rect sourceRect, Rect destRect) |
||||
|
{ |
||||
|
_base.DrawImage(source, opacity, sourceRect, destRect); |
||||
|
} |
||||
|
|
||||
|
public void DrawLine(Pen pen, Point p1, Point p2) |
||||
|
{ |
||||
|
_base.DrawLine(pen, p1, p2); |
||||
|
} |
||||
|
|
||||
|
public void DrawGeometry(Brush brush, Pen pen, Geometry geometry) |
||||
|
{ |
||||
|
_base.DrawGeometry(brush, pen, geometry); |
||||
|
} |
||||
|
|
||||
|
public void DrawRectangle(Pen pen, Rect rect, float cornerRadius = 0) |
||||
|
{ |
||||
|
_base.DrawRectangle(pen, rect, cornerRadius); |
||||
|
} |
||||
|
|
||||
|
public void DrawText(Brush foreground, Point origin, FormattedText text) |
||||
|
{ |
||||
|
_base.DrawText(foreground, origin, text); |
||||
|
} |
||||
|
|
||||
|
public void FillRectangle(Brush brush, Rect rect, float cornerRadius = 0) |
||||
|
{ |
||||
|
_base.FillRectangle(brush, rect, cornerRadius); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
Stack<IDisposable> _stateStack = new Stack<IDisposable>(); |
||||
|
|
||||
|
IDisposable Transform(IDisposable disposable) |
||||
|
{ |
||||
|
_stateStack.Push(disposable); |
||||
|
return Disposable.Create(() => |
||||
|
{ |
||||
|
var current = _stateStack.Peek(); |
||||
|
if (current != disposable) |
||||
|
throw new InvalidOperationException("Invalid push/pop order"); |
||||
|
current.Dispose(); |
||||
|
_stateStack.Pop(); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
public IDisposable PushClip(Rect clip) => Transform(_base.PushClip(clip)); |
||||
|
|
||||
|
public IDisposable PushOpacity(double opacity) => Transform(_base.PushOpacity(opacity)); |
||||
|
|
||||
|
public IDisposable PushTransform(Matrix matrix) => Transform(_base.PushTransform(matrix)); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,29 @@ |
|||||
|
// Copyright (c) The Perspex Project. All rights reserved.
|
||||
|
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
||||
|
|
||||
|
using System; |
||||
|
using Perspex.Media; |
||||
|
|
||||
|
namespace Perspex.Platform |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Defines a render target
|
||||
|
/// </summary>
|
||||
|
/// <remarks>
|
||||
|
/// The interface used for obtaining drawing context from surfaces you can render on.
|
||||
|
/// </remarks>
|
||||
|
public interface IRenderTarget : IDisposable |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Creates an <see cref="IDrawingContext"/> for a rendering session.
|
||||
|
/// </summary>
|
||||
|
IDrawingContext CreateDrawingContext(); |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Resizes the rendered viewport.
|
||||
|
/// </summary>
|
||||
|
/// <param name="width">The new width.</param>
|
||||
|
/// <param name="height">The new height.</param>
|
||||
|
void Resize(int width, int height); |
||||
|
} |
||||
|
} |
||||
@ -1,38 +0,0 @@ |
|||||
// Copyright (c) The Perspex Project. All rights reserved.
|
|
||||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|
||||
|
|
||||
using System; |
|
||||
|
|
||||
namespace Perspex.Platform |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Defines a renderer.
|
|
||||
/// </summary>
|
|
||||
/// <remarks>
|
|
||||
/// The interface used to render <see cref="IVisual"/>s. You will usually want to inherit from
|
|
||||
/// <see cref="Perspex.Rendering.RendererBase"/> rather than implementing the whole interface
|
|
||||
/// as RenderBase has a default implementation for the non-platform specific parts of a
|
|
||||
/// renderer.
|
|
||||
/// </remarks>
|
|
||||
public interface IRenderer : IDisposable |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Gets the number of times <see cref="Render"/> has been called.
|
|
||||
/// </summary>
|
|
||||
int RenderCount { get; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Renders the specified visual.
|
|
||||
/// </summary>
|
|
||||
/// <param name="visual">The visual to render.</param>
|
|
||||
/// <param name="handle">An optional platform-specific handle.</param>
|
|
||||
void Render(IVisual visual, IPlatformHandle handle); |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Resizes the rendered viewport.
|
|
||||
/// </summary>
|
|
||||
/// <param name="width">The new width.</param>
|
|
||||
/// <param name="height">The new height.</param>
|
|
||||
void Resize(int width, int height); |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,150 @@ |
|||||
|
// Copyright (c) The Perspex Project. All rights reserved.
|
||||
|
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
||||
|
|
||||
|
using Perspex.Controls; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Perspex.Controls.UnitTests |
||||
|
{ |
||||
|
public class StackPanelTests |
||||
|
{ |
||||
|
[Fact] |
||||
|
public void Lays_Out_Children_Vertically() |
||||
|
{ |
||||
|
var target = new StackPanel |
||||
|
{ |
||||
|
Children = new Controls |
||||
|
{ |
||||
|
new Border { Height = 20, Width = 120 }, |
||||
|
new Border { Height = 30 }, |
||||
|
new Border { Height = 50 }, |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
target.Measure(Size.Infinity); |
||||
|
target.Arrange(new Rect(target.DesiredSize)); |
||||
|
|
||||
|
Assert.Equal(new Size(120, 100), target.Bounds.Size); |
||||
|
Assert.Equal(new Rect(0, 0, 120, 20), target.Children[0].Bounds); |
||||
|
Assert.Equal(new Rect(0, 20, 120, 30), target.Children[1].Bounds); |
||||
|
Assert.Equal(new Rect(0, 50, 120, 50), target.Children[2].Bounds); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Lays_Out_Children_Horizontally() |
||||
|
{ |
||||
|
var target = new StackPanel |
||||
|
{ |
||||
|
Orientation = Orientation.Horizontal, |
||||
|
Children = new Controls |
||||
|
{ |
||||
|
new Border { Width = 20, Height = 120 }, |
||||
|
new Border { Width = 30 }, |
||||
|
new Border { Width = 50 }, |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
target.Measure(Size.Infinity); |
||||
|
target.Arrange(new Rect(target.DesiredSize)); |
||||
|
|
||||
|
Assert.Equal(new Size(100, 120), target.Bounds.Size); |
||||
|
Assert.Equal(new Rect(0, 0, 20, 120), target.Children[0].Bounds); |
||||
|
Assert.Equal(new Rect(20, 0, 30, 120), target.Children[1].Bounds); |
||||
|
Assert.Equal(new Rect(50, 0, 50, 120), target.Children[2].Bounds); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Lays_Out_Children_Vertically_With_Gap() |
||||
|
{ |
||||
|
var target = new StackPanel |
||||
|
{ |
||||
|
Gap = 10, |
||||
|
Children = new Controls |
||||
|
{ |
||||
|
new Border { Height = 20, Width = 120 }, |
||||
|
new Border { Height = 30 }, |
||||
|
new Border { Height = 50 }, |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
target.Measure(Size.Infinity); |
||||
|
target.Arrange(new Rect(target.DesiredSize)); |
||||
|
|
||||
|
Assert.Equal(new Size(120, 130), target.Bounds.Size); |
||||
|
Assert.Equal(new Rect(0, 0, 120, 20), target.Children[0].Bounds); |
||||
|
Assert.Equal(new Rect(0, 30, 120, 30), target.Children[1].Bounds); |
||||
|
Assert.Equal(new Rect(0, 70, 120, 50), target.Children[2].Bounds); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Lays_Out_Children_Horizontally_With_Gap() |
||||
|
{ |
||||
|
var target = new StackPanel |
||||
|
{ |
||||
|
Gap = 10, |
||||
|
Orientation = Orientation.Horizontal, |
||||
|
Children = new Controls |
||||
|
{ |
||||
|
new Border { Width = 20, Height = 120 }, |
||||
|
new Border { Width = 30 }, |
||||
|
new Border { Width = 50 }, |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
target.Measure(Size.Infinity); |
||||
|
target.Arrange(new Rect(target.DesiredSize)); |
||||
|
|
||||
|
Assert.Equal(new Size(130, 120), target.Bounds.Size); |
||||
|
Assert.Equal(new Rect(0, 0, 20, 120), target.Children[0].Bounds); |
||||
|
Assert.Equal(new Rect(30, 0, 30, 120), target.Children[1].Bounds); |
||||
|
Assert.Equal(new Rect(70, 0, 50, 120), target.Children[2].Bounds); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Lays_Out_Children_Vertically_Even_If_Larger_Than_Panel() |
||||
|
{ |
||||
|
var target = new StackPanel |
||||
|
{ |
||||
|
Height = 60, |
||||
|
Children = new Controls |
||||
|
{ |
||||
|
new Border { Height = 20, Width = 120 }, |
||||
|
new Border { Height = 30 }, |
||||
|
new Border { Height = 50 }, |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
target.Measure(Size.Infinity); |
||||
|
target.Arrange(new Rect(target.DesiredSize)); |
||||
|
|
||||
|
Assert.Equal(new Size(120, 60), target.Bounds.Size); |
||||
|
Assert.Equal(new Rect(0, 0, 120, 20), target.Children[0].Bounds); |
||||
|
Assert.Equal(new Rect(0, 20, 120, 30), target.Children[1].Bounds); |
||||
|
Assert.Equal(new Rect(0, 50, 120, 50), target.Children[2].Bounds); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Lays_Out_Children_Horizontally_Even_If_Larger_Than_Panel() |
||||
|
{ |
||||
|
var target = new StackPanel |
||||
|
{ |
||||
|
Width = 60, |
||||
|
Orientation = Orientation.Horizontal, |
||||
|
Children = new Controls |
||||
|
{ |
||||
|
new Border { Width = 20, Height = 120 }, |
||||
|
new Border { Width = 30 }, |
||||
|
new Border { Width = 50 }, |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
target.Measure(Size.Infinity); |
||||
|
target.Arrange(new Rect(target.DesiredSize)); |
||||
|
|
||||
|
Assert.Equal(new Size(60, 120), target.Bounds.Size); |
||||
|
Assert.Equal(new Rect(0, 0, 20, 120), target.Children[0].Bounds); |
||||
|
Assert.Equal(new Rect(20, 0, 30, 120), target.Children[1].Bounds); |
||||
|
Assert.Equal(new Rect(50, 0, 50, 120), target.Children[2].Bounds); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 615 B |
|
After Width: | Height: | Size: 615 B |
Loading…
Reference in new issue