@@ -6,23 +6,44 @@ namespace CommunityToolkit.Labs.WinUI.MarkdownTextBlock.TextElements;
6
6
7
7
internal partial class MyTableUIElement : Panel
8
8
{
9
+ // Children[0] = Border
10
+ // Children[1] = Header Background
11
+ // Children[2..columnCount] = Vertical lines
12
+ // Children[columnCount+1..columnCount + rowCount - 1] = Horizontal lines
13
+ // Children[columnCount + rowCount..] = Content
14
+
9
15
private readonly int _columnCount ;
10
16
private readonly int _rowCount ;
11
17
private readonly double _borderThickness ;
12
18
private double [ ] ? _columnWidths ;
13
19
private double [ ] ? _rowHeights ;
14
20
15
- public MyTableUIElement ( int columnCount , int rowCount , double borderThickness , Brush borderBrush )
21
+ public MyTableUIElement ( int columnCount , int rowCount , double borderThickness , Brush borderBrush , Brush headingBrush , CornerRadius cornerRadius )
16
22
{
17
23
_columnCount = columnCount ;
18
24
_rowCount = rowCount ;
19
25
_borderThickness = borderThickness ;
20
- for ( int col = 0 ; col < columnCount + 1 ; col ++ )
26
+
27
+ Margin = new Thickness ( left : 0 , top : 10 , right : 0 , bottom : 10 ) ;
28
+
29
+ Children . Add ( new Border
30
+ {
31
+ Background = headingBrush ,
32
+ CornerRadius = new CornerRadius ( topLeft : cornerRadius . TopLeft , topRight : cornerRadius . TopRight , 0 , 0 )
33
+ } ) ;
34
+ Children . Add ( new Border
35
+ {
36
+ BorderThickness = new Thickness ( _borderThickness ) ,
37
+ CornerRadius = cornerRadius ,
38
+ BorderBrush = borderBrush
39
+ } ) ;
40
+
41
+ for ( int col = 1 ; col < columnCount ; col ++ )
21
42
{
22
43
Children . Add ( new Rectangle { Fill = borderBrush } ) ;
23
44
}
24
45
25
- for ( int row = 0 ; row < rowCount + 1 ; row ++ )
46
+ for ( int row = 1 ; row < rowCount ; row ++ )
26
47
{
27
48
Children . Add ( new Rectangle { Fill = borderBrush } ) ;
28
49
}
@@ -33,7 +54,7 @@ private IEnumerable<FrameworkElement> ContentChildren
33
54
{
34
55
get
35
56
{
36
- for ( int i = _columnCount + _rowCount + 2 ; i < Children . Count ; i ++ )
57
+ for ( int i = _columnCount + _rowCount ; i < Children . Count ; i ++ )
37
58
{
38
59
yield return ( FrameworkElement ) Children [ i ] ;
39
60
}
@@ -45,7 +66,7 @@ private IEnumerable<Rectangle> VerticalLines
45
66
{
46
67
get
47
68
{
48
- for ( int i = 0 ; i < _columnCount + 1 ; i ++ )
69
+ for ( int i = 2 ; i < _columnCount + 1 ; i ++ )
49
70
{
50
71
yield return ( Rectangle ) Children [ i ] ;
51
72
}
@@ -57,7 +78,7 @@ private IEnumerable<Rectangle> HorizontalLines
57
78
{
58
79
get
59
80
{
60
- for ( int i = _columnCount + 1 ; i < _columnCount + _rowCount + 2 ; i ++ )
81
+ for ( int i = _columnCount + 1 ; i < _columnCount + _rowCount ; i ++ )
61
82
{
62
83
yield return ( Rectangle ) Children [ i ] ;
63
84
}
@@ -167,30 +188,32 @@ protected override Size ArrangeOverride(Size finalSize)
167
188
double x = 0 ;
168
189
foreach ( var borderLine in VerticalLines )
169
190
{
191
+ x += _borderThickness + _columnWidths [ colIndex ] ;
170
192
borderLine . Arrange ( new Rect ( x , 0 , _borderThickness , finalSize . Height ) ) ;
171
193
if ( colIndex >= _columnWidths . Length )
172
194
{
173
195
break ;
174
196
}
175
197
176
- x += _borderThickness + _columnWidths [ colIndex ] ;
177
198
colIndex ++ ;
178
199
}
179
200
}
180
201
181
202
// Arrange horizontal border elements.
182
203
{
204
+ Children [ 0 ] . Arrange ( new Rect ( 0 , 0 , finalSize . Width , _rowHeights [ 0 ] + ( _borderThickness * 2 ) ) ) ;
205
+ Children [ 1 ] . Arrange ( new Rect ( 0 , 0 , finalSize . Width , finalSize . Height ) ) ;
183
206
int rowIndex = 0 ;
184
207
double y = 0 ;
185
208
foreach ( var borderLine in HorizontalLines )
186
209
{
210
+ y += _borderThickness + _rowHeights [ rowIndex ] ;
187
211
borderLine . Arrange ( new Rect ( 0 , y , finalSize . Width , _borderThickness ) ) ;
188
212
if ( rowIndex >= _rowHeights . Length )
189
213
{
190
214
break ;
191
215
}
192
216
193
- y += _borderThickness + _rowHeights [ rowIndex ] ;
194
217
rowIndex ++ ;
195
218
}
196
219
}
0 commit comments