8 changed files with 164 additions and 16 deletions
@ -0,0 +1,23 @@ |
|||||
|
// -----------------------------------------------------------------------
|
||||
|
// <copyright file="ILayoutManager.cs" company="Steven Kirk">
|
||||
|
// Copyright 2013 MIT Licence. See licence.md for more information.
|
||||
|
// </copyright>
|
||||
|
// -----------------------------------------------------------------------
|
||||
|
|
||||
|
namespace Perspex.Layout |
||||
|
{ |
||||
|
using System; |
||||
|
using System.Reactive; |
||||
|
using Perspex.Controls; |
||||
|
|
||||
|
public interface ILayoutManager |
||||
|
{ |
||||
|
IObservable<Unit> LayoutNeeded { get; } |
||||
|
|
||||
|
void ExecuteLayoutPass(); |
||||
|
|
||||
|
void InvalidateMeasure(ILayoutable item); |
||||
|
|
||||
|
void InvalidateArrange(ILayoutable item); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
// -----------------------------------------------------------------------
|
||||
|
// <copyright file="ILayoutRoot.cs" company="Steven Kirk">
|
||||
|
// Copyright 2013 MIT Licence. See licence.md for more information.
|
||||
|
// </copyright>
|
||||
|
// -----------------------------------------------------------------------
|
||||
|
|
||||
|
namespace Perspex.Layout |
||||
|
{ |
||||
|
public interface ILayoutRoot : ILayoutable |
||||
|
{ |
||||
|
Size ClientSize { get; } |
||||
|
|
||||
|
ILayoutManager LayoutManager { get; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,23 @@ |
|||||
|
// -----------------------------------------------------------------------
|
||||
|
// <copyright file="ILayoutable.cs" company="Steven Kirk">
|
||||
|
// Copyright 2013 MIT Licence. See licence.md for more information.
|
||||
|
// </copyright>
|
||||
|
// -----------------------------------------------------------------------
|
||||
|
|
||||
|
namespace Perspex.Layout |
||||
|
{ |
||||
|
public interface ILayoutable |
||||
|
{ |
||||
|
Size? DesiredSize { get; } |
||||
|
|
||||
|
ILayoutRoot GetLayoutRoot(); |
||||
|
|
||||
|
void Arrange(Rect rect); |
||||
|
|
||||
|
void Measure(Size availableSize); |
||||
|
|
||||
|
void InvalidateArrange(); |
||||
|
|
||||
|
void InvalidateMeasure(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,48 @@ |
|||||
|
namespace Perspex.Layout |
||||
|
{ |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Reactive; |
||||
|
using System.Reactive.Subjects; |
||||
|
using Perspex.Controls; |
||||
|
|
||||
|
public class LayoutManager : ILayoutManager |
||||
|
{ |
||||
|
private ILayoutRoot root; |
||||
|
|
||||
|
private Subject<Unit> layoutNeeded; |
||||
|
|
||||
|
public LayoutManager() |
||||
|
{ |
||||
|
this.layoutNeeded = new Subject<Unit>(); |
||||
|
} |
||||
|
|
||||
|
public IObservable<Unit> LayoutNeeded |
||||
|
{ |
||||
|
get { return this.layoutNeeded; } |
||||
|
} |
||||
|
|
||||
|
public void ExecuteLayoutPass() |
||||
|
{ |
||||
|
if (root != null) |
||||
|
{ |
||||
|
root.Measure(root.ClientSize); |
||||
|
root.Arrange(new Rect(root.ClientSize)); |
||||
|
} |
||||
|
|
||||
|
root = null; |
||||
|
} |
||||
|
|
||||
|
public void InvalidateMeasure(ILayoutable item) |
||||
|
{ |
||||
|
this.root = item.GetLayoutRoot(); |
||||
|
this.layoutNeeded.OnNext(Unit.Default); |
||||
|
} |
||||
|
|
||||
|
public void InvalidateArrange(ILayoutable item) |
||||
|
{ |
||||
|
this.root = item.GetLayoutRoot(); |
||||
|
this.layoutNeeded.OnNext(Unit.Default); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue