Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SpatialDistribution.cs
1using System.Threading.Tasks;
2using SkiaSharp;
3
5{
9 public abstract class SpatialDistribution : LayoutContainer
10 {
14 protected Padding[] measured;
15
22 : base(Document, Parent)
23 {
24 }
25
31 public abstract Task<ICellLayout> GetCellLayout(DrawingState State);
32
38 public override async Task DoMeasureDimensions(DrawingState State)
39 {
40 await base.DoMeasureDimensions(State);
41
42 this.cellLayout = await this.GetCellLayout(State);
43
44 if (this.HasChildren)
45 {
46 foreach (ILayoutElement Child in this.Children)
47 {
48 if (!Child.IsVisible)
49 continue;
50
51 if (Child is IDynamicChildren DynamicChildren)
52 {
53 foreach (ILayoutElement Child2 in DynamicChildren.DynamicChildren)
54 await this.cellLayout.Add(Child2);
55 }
56 else
57 await this.cellLayout.Add(Child);
58 }
59
60 this.cellLayout.Flush();
61 }
62 }
63
68 public override async Task AfterMeasureDimensions(DrawingState State)
69 {
70 await base.AfterMeasureDimensions(State);
71
72 this.cellLayout?.Distribute(false);
73
74 this.Left = 0;
75 this.Top = 0;
76 this.Right = null;
77 this.Bottom = null;
78 this.Width = this.cellLayout.TotWidth;
79 this.Height = this.cellLayout.TotHeight;
80 }
81
82 private ICellLayout cellLayout = null;
83
88 public override void MeasurePositions(DrawingState State)
89 {
90 base.MeasurePositions(State);
91
92 this.cellLayout?.MeasurePositions(State);
93 this.cellLayout?.Distribute(true);
94 this.measured = this.cellLayout?.Align();
95 }
96
100 protected override bool MeasureChildrenPositions => false; // Cell Layout calls MeasurePositions on children.
101
106 public override async Task Draw(DrawingState State)
107 {
108 SKCanvas Canvas = State.Canvas;
109 SKMatrix M = Canvas.TotalMatrix;
110
111 foreach (Padding P in this.measured)
112 {
113 Canvas.Translate(P.OffsetX, P.OffsetY);
114 await P.Element.Draw(State);
115 Canvas.SetMatrix(M);
116 }
117 }
118
119 }
120}
Contains a 2D layout document.
SKCanvas Canvas
Current drawing canvas.
Provides padding for a layout element in a group contruct.
Definition: Padding.cs:11
ILayoutElement Element
Embedded element
Definition: Padding.cs:36
Abstract base class of elements that do spatial distribution of children.
override async Task AfterMeasureDimensions(DrawingState State)
Called when dimensions have been measured.
override void MeasurePositions(DrawingState State)
Measures layout entities and defines unassigned properties, related to positions.
abstract Task< ICellLayout > GetCellLayout(DrawingState State)
Gets a cell layout object that will be responsible for laying out cells.
override async Task DoMeasureDimensions(DrawingState State)
Measures layout entities and defines unassigned properties, related to dimensions.
override bool MeasureChildrenPositions
If children positions are to be measured.
override async Task Draw(DrawingState State)
Draws layout entities.
SpatialDistribution(Layout2DDocument Document, ILayoutElement Parent)
Abstract base class of elements that do spatial distribution of children.
Abstract base class for layout containers (area elements containing embedded layout elements).
bool HasChildren
If the element has children or not.
ILayoutElement[] Children
Child elements
Basic interface for cell layout objects.
Definition: ICellLayout.cs:9
Padding[] Align()
Aligns cells and returns an array of padded cells.
void Flush()
Flushes any waiting elements int he layout pipeline.
Task Add(ILayoutElement Element)
Adds a cell to the layout.
void MeasurePositions(DrawingState State)
Measures layout entities and defines unassigned properties, related to positions.
void Distribute(bool SetPosition)
Distributes cells in layout.
float TotHeight
Total height of layout
Definition: ICellLayout.cs:51
Interface for layout elements that generate children dynamically.
Base interface for all layout elements.
Task Draw(DrawingState State)
Draws layout entities.
bool IsVisible
If the element is visible or not.