2using System.Collections.Generic;
3using System.Threading.Tasks;
13 private readonly List<GridPadding> elements =
new List<GridPadding>();
15 private readonly
int nrColumns;
16 private readonly
float[] rights;
17 private readonly
float[] widths;
18 private readonly List<float> bottoms;
19 private readonly List<float> heights;
30 this.session = Session;
31 this.nrColumns = NrColumns;
32 this.rights =
new float[this.nrColumns];
33 this.widths =
new float[this.nrColumns];
34 this.bottoms =
new List<float>();
35 this.heights =
new List<float>();
40 if (X < 0 || X >= this.nrColumns)
46 int i = Y * this.nrColumns + X;
47 if (i >= this.elements.Count)
50 return this.elements[i];
56 if (this.x >= this.nrColumns)
63 private float GetRight(
int x)
67 else if (x >= this.nrColumns)
68 throw new InvalidOperationException(
"Cell does not fit in grid.");
70 return this.rights[x];
73 private float GetBottom(
int y)
78 int c = this.bottoms.Count;
86 this.bottoms.Add(this.bottoms[c - 1]);
91 return this.bottoms[y];
105 Span.ColSpan = Span.RowSpan = 1;
107 while (!(this.GetElement(this.x, this.y) is
null))
110 this.SetElement(this.x, this.y, Span.
ColSpan, Span.
RowSpan, Element);
112 int X2 = this.x + Span.ColSpan - 1;
113 if (X2 >= this.nrColumns)
114 X2 = this.nrColumns - 1;
116 float? f = Element.
Width;
117 if (f.HasValue && Span.
ColSpan == 1 && f.Value >
this.widths[
this.x])
118 this.widths[this.x] = f.Value;
120 float Right = this.GetRight(this.x - 1) + (f ?? 0);
121 float Right2 = this.GetRight(X2);
122 float Diff = Right - Right2;
126 this.rights[X2] += Diff;
128 if (++X2 >= this.nrColumns)
131 Right2 = this.GetRight(X2);
132 Right += this.widths[X2];
133 Diff = Right - Right2;
136 int Y2 = this.y + Span.RowSpan - 1;
140 float Bottom = this.GetBottom(this.y - 1) + (f ?? 0);
141 float Bottom2 = this.GetBottom(Y2);
142 int c = this.bottoms.Count;
144 if (f.HasValue && Span.
RowSpan == 1 && f.Value >
this.heights[
this.y])
145 this.heights[this.y] = f.Value;
147 Diff = Bottom - Bottom2;
151 this.bottoms[Y2] += Diff;
156 Bottom2 = this.GetBottom(Y2);
157 Bottom += this.heights[Y2];
158 Diff = Bottom - Bottom2;
162 if (this.x >= this.nrColumns)
176 private void SetElement(
int X,
int Y,
int ColSpan,
int RowSpan,
ILayoutElement Element)
180 if (ColSpan > 1 || RowSpan > 1)
185 for (; RowSpan > 0; RowSpan--)
187 for (i = 0; i < ColSpan; i++)
189 if (!this.SetElement(X + i, Y, P))
190 throw new InvalidOperationException(
"Cell does not fit in grid.");
204 if (!this.SetElement(X, Y, P))
205 throw new InvalidOperationException(
"Cell does not fit in grid.");
209 private bool SetElement(
int X,
int Y, GridPadding Element)
211 if (X < 0 || X >= this.nrColumns)
217 int i = Y * this.nrColumns + X;
218 int c = this.elements.Count;
222 this.elements.Add(
null);
228 this.elements.Add(Element);
233 if (this.elements[i] is
null)
235 this.elements[i] = Element;
246 public float TotWidth => this.GetRight(this.nrColumns - 1);
251 public float TotHeight => this.GetBottom(this.bottoms.Count - 1);
265 if (!(Element is
null))
268 P.OffsetX -= Element.Left ?? 0;
269 P.OffsetY -= Element.Top ?? 0;
286 float Left = this.GetRight(X - 1);
287 float Top = this.GetBottom(Y - 1);
288 float Right = this.GetRight(X + P.
ColSpan - 1);
289 float Bottom = this.GetBottom(Y + P.
RowSpan - 1);
290 float MaxWidth = Right - Left;
291 float MaxHeight = Bottom - Top;
293 P.
Distribute(MaxWidth, MaxHeight, this.session, SetPosition);
304 List<Padding> Result =
new List<Padding>();
312 float Left = this.GetRight(X - 1);
313 float Top = this.GetBottom(Y - 1);
321 return Result.ToArray();
Defines a cell in a grid.
async Task< CellSpan > CalcSpan(Variables Session)
Calculates the span of the cell.
Lays out cells in a grid.
async Task Add(ILayoutElement Element)
Adds a cell to the layout.
Padding[] Align()
Aligns cells and returns an array of padded cells.
GridCells(Variables Session, int NrColumns)
Lays out cells in a grid.
void MeasurePositions(DrawingState State)
Measures layout entities and defines unassigned properties, related to positions.
float TotWidth
Total width of layout
void Flush()
Flushes any waiting elements int he layout pipeline.
void Distribute(bool SetPosition)
Distributes cells in layout.
float TotHeight
Total height of layout
Provides padding for a layout element in a grid.
int Y
Cell Y-coordinate in grid.
int X
Cell X-coordinate in grid.
Provides padding for a layout element in a group contruct.
Task Distribute(float? MaxWidth, float? MaxHeight, Variables Session, bool SetPosition)
Aligns a measured cell
ILayoutElement Element
Embedded element
Basic interface for cell layout objects.
Base interface for all layout elements.
float? Width
Width of element
void MeasurePositions(DrawingState State)
Measures layout entities and defines unassigned properties, related to positions.
float? Height
Height of element
Contains information about a cells span in a grid.