Last active
December 20, 2015 11:19
-
-
Save jmhdez/6122223 to your computer and use it in GitHub Desktop.
Compartiendo elementos en posiciones dependientes del contenedor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IElement | |
{ | |
IEnumerable<ChildElement> Children { get; } | |
} | |
public class ChildElement | |
{ | |
public readonly IElement Value; | |
public readonly Point Point; | |
public ChildElement(int x, int y, IElement value) | |
{ | |
Point = new Point(x, y); | |
Value = value; | |
} | |
} | |
public class Container : IElement | |
{ | |
private readonly ISet<ChildElement> children = new HashSet<ChildElement>(); | |
public Container Add(int x, int y, IElement child) | |
{ | |
children.Add(new ChildElement(x, y, child)); | |
return this; | |
} | |
public IEnumerable<ChildElement> Children | |
{ | |
get { return children.AsEnumerable(); | |
} | |
} | |
var shared = new FormElement(); | |
var page1 = new Container() | |
.Add(3, 1, new CircleElement(radius: 6)) | |
.Add(25, 25, shared); | |
.Add(10, 50, new Container() | |
.Add(1, 1, new TextElement(text: "Sample Text Element")) | |
.Add(5, 5, new BoxElement(width: 100, height: 25))); | |
var page2 = new Container() | |
.Add(4, 4, new TitleElement(text: "The Title of this Page")) | |
.Add(10, 10, shared); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment