Browse Source

Separated visual and logical tree into interfaces.

IVisual and ILogical, duh.
pull/4/head
grokys 12 years ago
parent
commit
b292905a84
  1. 1
      Perspex.UnitTests/Perspex.UnitTests.csproj
  2. 9
      Perspex.UnitTests/Styling/SelectorTests_Id.cs
  3. 4
      Perspex.Windows/Renderer.cs
  4. 2
      Perspex.Windows/Window.cs
  5. 2
      Perspex/ControlTemplate.cs
  6. 6
      Perspex/Controls/ContentControl.cs
  7. 10
      Perspex/Controls/ContentPresenter.cs
  8. 2
      Perspex/Controls/Control.cs
  9. 7
      Perspex/Controls/Decorator.cs
  10. 11
      Perspex/Controls/TemplatedControl.cs
  11. 21
      Perspex/ILogical.cs
  12. 4
      Perspex/IVisual.cs
  13. 1
      Perspex/Perspex.csproj
  14. 3
      Perspex/Properties/AssemblyInfo.cs
  15. 23
      Perspex/Visual.cs

1
Perspex.UnitTests/Perspex.UnitTests.csproj

@ -75,7 +75,6 @@
<Compile Include="Styling\SelectorTests_Class.cs" />
<Compile Include="Styling\SelectorTests_Id.cs" />
<Compile Include="Styling\SelectorTests_OfType.cs" />
<Compile Include="Styling\SelectorTests_InTemplateOf.cs" />
<Compile Include="Styling\TestControlBase.cs" />
</ItemGroup>
<ItemGroup>

9
Perspex.UnitTests/Styling/SelectorTests_Id.cs

@ -44,15 +44,6 @@ namespace Perspex.UnitTests.Styling
CollectionAssert.AreEqual(new[] { false }, target.GetActivator().Take(1).ToEnumerable().ToArray());
}
[TestMethod]
public void Id_Matches_Control_With_TemplatedParent_After_InTemplateOf()
{
var control = new Control1 { Id = "foo", TemplatedParent = new TemplatedControl1() };
var target = control.Select().InTemplateOf<TemplatedControl1>().Id("foo");
CollectionAssert.AreEqual(new[] { true }, target.GetActivator().Take(1).ToEnumerable().ToArray());
}
[TestMethod]
public void When_Id_Matches_Control_Other_Selectors_Are_Subscribed()
{

4
Perspex.Windows/Renderer.cs

@ -71,7 +71,7 @@ namespace Perspex.Windows
/// Renders the specified visual.
/// </summary>
/// <param name="visual">The visual to render.</param>
public void Render(Visual visual)
public void Render(IVisual visual)
{
using (DrawingContext context = new DrawingContext(this.renderTarget, this.DirectWriteFactory))
{
@ -94,7 +94,7 @@ namespace Perspex.Windows
/// </summary>
/// <param name="visual">The visual to render.</param>
/// <param name="context">The drawing context.</param>
private void Render(Visual visual, DrawingContext context)
private void Render(IVisual visual, DrawingContext context)
{
visual.Render(context);

2
Perspex.Windows/Window.cs

@ -164,7 +164,7 @@ namespace Perspex.Windows
control.IsMouseOver = visual.Bounds.Contains(p);
}
foreach (Visual child in visual.VisualChildren)
foreach (Visual child in ((IVisual)visual).VisualChildren)
{
this.MouseMove(child, p - visual.Bounds.Position);
}

2
Perspex/ControlTemplate.cs

@ -46,7 +46,7 @@ namespace Perspex
control.TemplatedParent = templatedParent;
foreach (Control child in control.VisualChildren.OfType<Control>())
foreach (Control child in ((IVisual)control).VisualChildren.OfType<Control>())
{
this.SetTemplatedParent(child, templatedParent);
}

6
Perspex/Controls/ContentControl.cs

@ -24,7 +24,7 @@ namespace Perspex.Controls
if (control != null)
{
control.VisualParent = this;
((IVisual)control).VisualParent = this;
control.SetValue(ParentPropertyRW, this);
}
});
@ -38,7 +38,7 @@ namespace Perspex.Controls
protected override Size ArrangeContent(Size finalSize)
{
Control child = this.VisualChildren.SingleOrDefault() as Control;
Control child = ((IVisual)this).VisualChildren.SingleOrDefault() as Control;
if (child != null)
{
@ -53,7 +53,7 @@ namespace Perspex.Controls
protected override Size MeasureContent(Size availableSize)
{
Control child = this.VisualChildren.SingleOrDefault() as Control;
Control child = ((IVisual)this).VisualChildren.SingleOrDefault() as Control;
if (child != null)
{

10
Perspex/Controls/ContentPresenter.cs

@ -11,7 +11,7 @@ namespace Perspex.Controls
using System.Linq;
using Perspex.Media;
public class ContentPresenter : Control
public class ContentPresenter : Control, IVisual
{
public static readonly PerspexProperty<object> ContentProperty =
ContentControl.ContentProperty.AddOwner<Control>();
@ -33,7 +33,7 @@ namespace Perspex.Controls
set { this.SetValue(DataTemplateProperty, value); }
}
public override IEnumerable<IVisual> VisualChildren
IEnumerable<IVisual> IVisual.VisualChildren
{
get
{
@ -60,7 +60,7 @@ namespace Perspex.Controls
if (this.visualChild != null)
{
this.visualChild.VisualParent = this;
((IVisual)this.visualChild).VisualParent = this;
}
}
@ -70,7 +70,7 @@ namespace Perspex.Controls
protected override Size ArrangeContent(Size finalSize)
{
Control child = this.VisualChildren.SingleOrDefault() as Control;
Control child = ((IVisual)this).VisualChildren.SingleOrDefault() as Control;
if (child != null)
{
@ -127,7 +127,7 @@ namespace Perspex.Controls
protected override Size MeasureContent(Size availableSize)
{
Control child = this.VisualChildren.SingleOrDefault() as Control;
Control child = ((IVisual)this).VisualChildren.SingleOrDefault() as Control;
if (child != null)
{

2
Perspex/Controls/Control.cs

@ -192,7 +192,7 @@ namespace Perspex.Controls
throw new InvalidOperationException("ID already set.");
}
if (this.VisualParent != null)
if (((IVisual)this).VisualParent != null)
{
throw new InvalidOperationException("Cannot set ID : control already added to tree.");
}

7
Perspex/Controls/Decorator.cs

@ -9,8 +9,9 @@ namespace Perspex.Controls
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
public abstract class Decorator : Control
public abstract class Decorator : Control, IVisual
{
public static readonly PerspexProperty<Control> ContentProperty =
PerspexProperty.Register<ContentControl, Control>("Content");
@ -21,7 +22,7 @@ namespace Perspex.Controls
public Decorator()
{
// TODO: Unset old content's visual parent.
this.GetObservable(ContentProperty).Subscribe(x =>
this.GetObservable(ContentProperty).OfType<IVisual>().Subscribe(x =>
{
if (x != null)
{
@ -42,7 +43,7 @@ namespace Perspex.Controls
set { this.SetValue(PaddingProperty, value); }
}
public override IEnumerable<IVisual> VisualChildren
IEnumerable<IVisual> IVisual.VisualChildren
{
get
{

11
Perspex/Controls/TemplatedControl.cs

@ -11,12 +11,12 @@ namespace Perspex.Controls
using System.Linq;
using Perspex.Media;
public abstract class TemplatedControl : Control, ITemplatedControl
public abstract class TemplatedControl : Control, IVisual, ITemplatedControl
{
public static readonly PerspexProperty<ControlTemplate> TemplateProperty =
PerspexProperty.Register<TemplatedControl, ControlTemplate>("Template");
private Visual visualChild;
private IVisual visualChild;
public ControlTemplate Template
{
@ -24,7 +24,7 @@ namespace Perspex.Controls
set { this.SetValue(TemplateProperty, value); }
}
public override IEnumerable<IVisual> VisualChildren
IEnumerable<IVisual> ITemplatedControl.VisualChildren
{
get
{
@ -40,6 +40,11 @@ namespace Perspex.Controls
}
}
IEnumerable<IVisual> IVisual.VisualChildren
{
get { return ((ITemplatedControl)this).VisualChildren; }
}
public sealed override void Render(IDrawingContext context)
{
}

21
Perspex/ILogical.cs

@ -0,0 +1,21 @@
// -----------------------------------------------------------------------
// <copyright file="ILogical.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public interface ILogical
{
ILogical LogicalParent { get; set; }
IEnumerable<ILogical> LogicalChildren { get; }
}
}

4
Perspex/IVisual.cs

@ -15,8 +15,8 @@ namespace Perspex
Rect Bounds { get; }
IEnumerable<IVisual> VisualChildren { get; }
IVisual VisualParent { get; }
IVisual VisualParent { get; set; }
void Render(IDrawingContext context);
}

1
Perspex/Perspex.csproj

@ -79,6 +79,7 @@
<Compile Include="Controls\ITemplatedControl.cs" />
<Compile Include="Controls\TextBlock.cs" />
<Compile Include="ControlTemplate.cs" />
<Compile Include="ILogical.cs" />
<Compile Include="Input\MouseEventArgs.cs" />
<Compile Include="Interactive.cs" />
<Compile Include="IVisual.cs" />

3
Perspex/Properties/AssemblyInfo.cs

@ -1,5 +1,6 @@
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
@ -26,3 +27,5 @@ using System.Resources;
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: InternalsVisibleTo("Perspex.UnitTests")]

23
Perspex/Visual.cs

@ -12,8 +12,10 @@ namespace Perspex
using System.Linq;
using Perspex.Media;
public abstract class Visual : PerspexObject, IVisual
public abstract class Visual : PerspexObject, IVisual, ILogical
{
private ILogical logicalParent;
private IVisual visualParent;
public Rect Bounds
@ -22,19 +24,30 @@ namespace Perspex
protected set;
}
public virtual IEnumerable<IVisual> VisualChildren
ILogical ILogical.LogicalParent
{
get { return this.logicalParent; }
set { this.logicalParent = value; }
}
IEnumerable<ILogical> ILogical.LogicalChildren
{
get { return new ILogical[0]; }
}
IEnumerable<IVisual> IVisual.VisualChildren
{
get { return Enumerable.Empty<Visual>(); }
}
public IVisual VisualParent
IVisual IVisual.VisualParent
{
get
{
return this.visualParent;
return this.visualParent;
}
internal set
set
{
if (this.visualParent != value)
{

Loading…
Cancel
Save