Browse Source

Added IVisual interface.

pull/4/head
grokys 12 years ago
parent
commit
4080c18f59
  1. 3
      Perspex.UnitTests/Perspex.UnitTests.csproj
  2. 2
      Perspex.UnitTests/Styling/SelectorTests_Class.cs
  3. 7
      Perspex.UnitTests/Styling/SelectorTests_Id.cs
  4. 80
      Perspex.UnitTests/Styling/SelectorTests_InTemplateOf.cs
  5. 4
      Perspex.UnitTests/Styling/SelectorTests_OfType.cs
  6. 34
      Perspex.UnitTests/Styling/SelectorTests_Template.cs
  7. 6
      Perspex.UnitTests/Styling/TestControlBase.cs
  8. 4
      Perspex.Windows/Window.cs
  9. 2
      Perspex/Controls/ContentPresenter.cs
  10. 31
      Perspex/Controls/Control.cs
  11. 2
      Perspex/Controls/Decorator.cs
  12. 3
      Perspex/Controls/ITemplatedControl.cs
  13. 2
      Perspex/Controls/TemplatedControl.cs
  14. 23
      Perspex/IVisual.cs
  15. 1
      Perspex/Perspex.csproj
  16. 37
      Perspex/Visual.cs
  17. 8
      Perspex/VisualExtensions.cs

3
Perspex.UnitTests/Perspex.UnitTests.csproj

@ -69,12 +69,11 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="PerspexObjectTests.cs" />
<Compile Include="StyleTests.cs" />
<Compile Include="Styling\SelectorTests_Template.cs" />
<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\SubscribeCheck.cs" />
<Compile Include="Styling\TestControlBase.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Perspex\Perspex.csproj">

2
Perspex.UnitTests/Styling/SelectorTests_Class.cs

@ -69,7 +69,7 @@ namespace Perspex.UnitTests.Styling
CollectionAssert.AreEqual(new[] { false }, activator.Take(1).ToEnumerable().ToArray());
}
public class Control1 : SubscribeCheck
public class Control1 : TestControlBase
{
}
}

7
Perspex.UnitTests/Styling/SelectorTests_Id.cs

@ -7,6 +7,7 @@
namespace Perspex.UnitTests.Styling
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@ -74,12 +75,16 @@ namespace Perspex.UnitTests.Styling
Assert.AreEqual(0, control.SubscribeCheckObservable.SubscribedCount);
}
public class Control1 : SubscribeCheck
public class Control1 : TestControlBase
{
}
public class TemplatedControl1 : ITemplatedControl
{
public IEnumerable<IVisual> VisualChildren
{
get { throw new NotImplementedException(); }
}
}
}
}

80
Perspex.UnitTests/Styling/SelectorTests_InTemplateOf.cs

@ -17,55 +17,61 @@ namespace Perspex.UnitTests.Styling
public class SelectorTests_InTemplateOf
{
[TestMethod]
public void InTemplateOf_Matches_Control_Of_Correct_Type()
public void Remove_These()
{
var control = new Control1 { TemplatedParent = new TemplatedControl1() };
var target = control.Select().InTemplateOf<TemplatedControl1>();
CollectionAssert.AreEqual(new[] { true }, target.GetActivator().Take(1).ToEnumerable().ToArray());
Assert.Fail();
}
[TestMethod]
public void InTemplateOf_Doesnt_Match_Control_Of_Wrong_Type()
{
var control = new Control1 { TemplatedParent = new TemplatedControl1() };
var target = control.Select().InTemplateOf<TemplatedControl2>();
//[TestMethod]
//public void InTemplateOf_Matches_Control_Of_Correct_Type()
//{
// var control = new Control1 { TemplatedParent = new TemplatedControl1() };
// var target = control.Select().InTemplateOf<TemplatedControl1>();
CollectionAssert.AreEqual(new[] { false }, target.GetActivator().Take(1).ToEnumerable().ToArray());
}
// CollectionAssert.AreEqual(new[] { true }, target.GetActivator().Take(1).ToEnumerable().ToArray());
//}
[TestMethod]
public void When_InTemplateOf_Matches_Control_Other_Selectors_Are_Subscribed()
{
var control = new Control1 { TemplatedParent = new TemplatedControl1() };
var target = control.Select().InTemplateOf<TemplatedControl1>().SubscribeCheck();
//[TestMethod]
//public void InTemplateOf_Doesnt_Match_Control_Of_Wrong_Type()
//{
// var control = new Control1 { TemplatedParent = new TemplatedControl1() };
// var target = control.Select().InTemplateOf<TemplatedControl2>();
var result = target.GetActivator().ToEnumerable().Take(1).ToArray();
// CollectionAssert.AreEqual(new[] { false }, target.GetActivator().Take(1).ToEnumerable().ToArray());
//}
Assert.AreEqual(1, control.SubscribeCheckObservable.SubscribedCount);
}
//[TestMethod]
//public void When_InTemplateOf_Matches_Control_Other_Selectors_Are_Subscribed()
//{
// var control = new Control1 { TemplatedParent = new TemplatedControl1() };
// var target = control.Select().InTemplateOf<TemplatedControl1>().SubscribeCheck();
[TestMethod]
public void When_InTemplateOf_Doesnt_Match_Control_Other_Selectors_Are_Not_Subscribed()
{
var control = new Control1 { TemplatedParent = new TemplatedControl1() };
var target = control.Select().InTemplateOf<TemplatedControl2>().SubscribeCheck();
// var result = target.GetActivator().ToEnumerable().Take(1).ToArray();
var result = target.GetActivator().ToEnumerable().Take(1).ToArray();
// Assert.AreEqual(1, control.SubscribeCheckObservable.SubscribedCount);
//}
Assert.AreEqual(0, control.SubscribeCheckObservable.SubscribedCount);
}
//[TestMethod]
//public void When_InTemplateOf_Doesnt_Match_Control_Other_Selectors_Are_Not_Subscribed()
//{
// var control = new Control1 { TemplatedParent = new TemplatedControl1() };
// var target = control.Select().InTemplateOf<TemplatedControl2>().SubscribeCheck();
public class Control1 : SubscribeCheck
{
}
// var result = target.GetActivator().ToEnumerable().Take(1).ToArray();
public class TemplatedControl1 : ITemplatedControl
{
}
// Assert.AreEqual(0, control.SubscribeCheckObservable.SubscribedCount);
//}
public class TemplatedControl2 : ITemplatedControl
{
}
//public class Control1 : TestControlBase
//{
//}
//public class TemplatedControl1 : ITemplatedControl
//{
//}
//public class TemplatedControl2 : ITemplatedControl
//{
//}
}
}

4
Perspex.UnitTests/Styling/SelectorTests_OfType.cs

@ -54,11 +54,11 @@ namespace Perspex.UnitTests.Styling
Assert.AreEqual(0, control.SubscribeCheckObservable.SubscribedCount);
}
public class Control1 : SubscribeCheck
public class Control1 : TestControlBase
{
}
public class Control2 : SubscribeCheck
public class Control2 : TestControlBase
{
}
}

34
Perspex.UnitTests/Styling/SelectorTests_Template.cs

@ -1,34 +0,0 @@
// -----------------------------------------------------------------------
// <copyright file="SelectorTests.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.UnitTests.Styling
{
using System.Linq;
using System.Reactive.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Perspex.Styling;
[TestClass]
public class SelectorTests_Template
{
[TestMethod]
public void Foo()
{
var control = new Control1
{
Classes = new Classes { "foo" },
};
var target = control.Select().Class("foo");
CollectionAssert.AreEqual(new[] { true }, target.GetActivator().Take(1).ToEnumerable().ToArray());
}
public class Control1 : SubscribeCheck
{
}
}
}

6
Perspex.UnitTests/Styling/SubscribeCheck.cs → Perspex.UnitTests/Styling/TestControlBase.cs

@ -24,9 +24,9 @@ namespace Perspex.UnitTests.Styling
}
}
public class SubscribeCheck : IStyleable
public class TestControlBase : IStyleable
{
public SubscribeCheck()
public TestControlBase()
{
this.Classes = new Classes();
this.SubscribeCheckObservable = new TestObservable();
@ -53,7 +53,7 @@ namespace Perspex.UnitTests.Styling
{
public static Match SubscribeCheck(this Match match)
{
match.Observables.Add(((SubscribeCheck)match.Control).SubscribeCheckObservable);
match.Observables.Add(((TestControlBase)match.Control).SubscribeCheckObservable);
return match;
}
}

4
Perspex.Windows/Window.cs

@ -137,7 +137,7 @@ namespace Perspex.Windows
private void MouseDown(Visual visual, Point p)
{
Visual hit = visual.GetVisualAt(p);
IVisual hit = visual.GetVisualAt(p);
if (hit != null)
{
@ -172,7 +172,7 @@ namespace Perspex.Windows
private void MouseUp(Visual visual, Point p)
{
Visual hit = visual.GetVisualAt(p);
IVisual hit = visual.GetVisualAt(p);
if (hit != null)
{

2
Perspex/Controls/ContentPresenter.cs

@ -33,7 +33,7 @@ namespace Perspex.Controls
set { this.SetValue(DataTemplateProperty, value); }
}
public override IEnumerable<Visual> VisualChildren
public override IEnumerable<IVisual> VisualChildren
{
get
{

31
Perspex/Controls/Control.cs

@ -72,6 +72,8 @@ namespace Perspex.Controls
private Classes classes;
private string id;
private Styles styles;
public Control()
@ -164,16 +166,39 @@ namespace Perspex.Controls
}
}
public Size? DesiredSize
{
get;
set;
}
public Brush Foreground
{
get { return this.GetValue(ForegroundProperty); }
set { this.SetValue(ForegroundProperty, value); }
}
public Size? DesiredSize
public string Id
{
get;
set;
get
{
return this.id;
}
set
{
if (this.id != null)
{
throw new InvalidOperationException("ID already set.");
}
if (this.VisualParent != null)
{
throw new InvalidOperationException("Cannot set ID : control already added to tree.");
}
this.id = value;
}
}
public bool IsMouseOver

2
Perspex/Controls/Decorator.cs

@ -42,7 +42,7 @@ namespace Perspex.Controls
set { this.SetValue(PaddingProperty, value); }
}
public override IEnumerable<Visual> VisualChildren
public override IEnumerable<IVisual> VisualChildren
{
get
{

3
Perspex/Controls/ITemplatedControl.cs

@ -6,7 +6,10 @@
namespace Perspex.Controls
{
using System.Collections.Generic;
public interface ITemplatedControl
{
IEnumerable<IVisual> VisualChildren { get; }
}
}

2
Perspex/Controls/TemplatedControl.cs

@ -24,7 +24,7 @@ namespace Perspex.Controls
set { this.SetValue(TemplateProperty, value); }
}
public override IEnumerable<Visual> VisualChildren
public override IEnumerable<IVisual> VisualChildren
{
get
{

23
Perspex/IVisual.cs

@ -0,0 +1,23 @@
// -----------------------------------------------------------------------
// <copyright file="IVisual.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex
{
using System;
using System.Collections.Generic;
using Perspex.Media;
public interface IVisual
{
Rect Bounds { get; }
IEnumerable<IVisual> VisualChildren { get; }
IVisual VisualParent { get; }
void Render(IDrawingContext context);
}
}

1
Perspex/Perspex.csproj

@ -81,6 +81,7 @@
<Compile Include="ControlTemplate.cs" />
<Compile Include="Input\MouseEventArgs.cs" />
<Compile Include="Interactive.cs" />
<Compile Include="IVisual.cs" />
<Compile Include="Styling\Activator.cs" />
<Compile Include="Styling\IStyleable.cs" />
<Compile Include="Styling\IStyle.cs" />

37
Perspex/Visual.cs

@ -12,11 +12,9 @@ namespace Perspex
using System.Linq;
using Perspex.Media;
public abstract class Visual : PerspexObject
public abstract class Visual : PerspexObject, IVisual
{
private string id;
private Visual visualParent;
private IVisual visualParent;
public Rect Bounds
{
@ -24,47 +22,24 @@ namespace Perspex
protected set;
}
public string Id
{
get
{
return this.id;
}
set
{
if (this.id != null)
{
throw new InvalidOperationException("ID already set.");
}
if (this.visualParent != null)
{
throw new InvalidOperationException("Cannot set ID : control already added to tree.");
}
this.id = value;
}
}
public virtual IEnumerable<Visual> VisualChildren
public virtual IEnumerable<IVisual> VisualChildren
{
get { return Enumerable.Empty<Visual>(); }
}
public Visual VisualParent
public IVisual VisualParent
{
get
{
return this.visualParent;
}
set
internal set
{
if (this.visualParent != value)
{
this.visualParent = value;
this.InheritanceParent = value;
this.InheritanceParent = (PerspexObject)value;
}
}
}

8
Perspex/VisualExtensions.cs

@ -12,7 +12,7 @@ namespace Perspex
public static class VisualExtensions
{
public static T GetVisualAncestor<T>(this Visual visual) where T : Visual
public static T GetVisualAncestor<T>(this IVisual visual) where T : Visual
{
Contract.Requires<NullReferenceException>(visual != null);
@ -33,7 +33,7 @@ namespace Perspex
return null;
}
public static Visual GetVisualAt(this Visual visual, Point p)
public static IVisual GetVisualAt(this IVisual visual, Point p)
{
Contract.Requires<NullReferenceException>(visual != null);
@ -43,9 +43,9 @@ namespace Perspex
if (visual.VisualChildren.Any())
{
foreach (Visual child in visual.VisualChildren)
foreach (IVisual child in visual.VisualChildren)
{
Visual hit = child.GetVisualAt(p);
IVisual hit = child.GetVisualAt(p);
if (hit != null)
{

Loading…
Cancel
Save