Use shared type for TableRow behavior, set styles for alignment
This commit is contained in:
parent
f0dba3865f
commit
11a7784230
2 changed files with 42 additions and 23 deletions
|
|
@ -36,18 +36,16 @@ namespace Markdig.Renderers.Agg
|
|||
{
|
||||
var row = (TableRow)rowObj;
|
||||
|
||||
GuiWidget aggRow = row.IsHeader ? new TableHeadingRow() : new FlowLayoutWidget()
|
||||
var aggRow = new AggTableRow()
|
||||
{
|
||||
HAnchor = HAnchor.Fit,
|
||||
VAnchor = VAnchor.Absolute,
|
||||
Height = 25,
|
||||
IsHeadingRow = row.IsHeader,
|
||||
};
|
||||
|
||||
renderer.Push(aggRow);
|
||||
|
||||
if (row.IsHeader)
|
||||
{
|
||||
// Update to desired header row styling
|
||||
// Update to desired header row styling and/or moving into AggTableRow for consistency
|
||||
aggRow.BackgroundColor = MatterHackers.MatterControl.AppContext.Theme.TabBarBackground;
|
||||
}
|
||||
|
||||
|
|
@ -63,6 +61,16 @@ namespace Markdig.Renderers.Agg
|
|||
Height = 25,
|
||||
};
|
||||
|
||||
// TODO: Cell Width - implement next, might be easy to track and perform in AggTableRow
|
||||
/* (Spec)
|
||||
* If any line of the markdown source is longer than the column width (see --columns), then the
|
||||
* table will take up the full text width and the cell contents will wrap, with the relative cell
|
||||
* widths determined by the number of dashes in the line separating the table header from the table
|
||||
* body. (For example ---|- would make the first column 3/4 and the second column 1/4 of the full
|
||||
* text width.) On the other hand, if no lines are wider than column width, then cell contents will
|
||||
* not be wrapped, and the cells will be sized to their contents.
|
||||
*/
|
||||
|
||||
// Cell box above enforces boundaries, use flow for layout
|
||||
var aggCellFlow = new FlowLayoutWidget()
|
||||
{
|
||||
|
|
@ -80,21 +88,22 @@ namespace Markdig.Renderers.Agg
|
|||
: cell.ColumnIndex;
|
||||
columnIndex = columnIndex >= table.ColumnDefinitions.Count ? table.ColumnDefinitions.Count - 1 : columnIndex;
|
||||
|
||||
// TODO: implement alignment into Agg types that won't throw when set
|
||||
var alignment = table.ColumnDefinitions[columnIndex].Alignment;
|
||||
// TODO: revise alignment via Agg types that produce aligned text
|
||||
var columnDefinition = table.ColumnDefinitions[columnIndex];
|
||||
var alignment = columnDefinition.Alignment;
|
||||
if (alignment.HasValue)
|
||||
{
|
||||
switch (alignment)
|
||||
{
|
||||
//case TableColumnAlign.Center:
|
||||
// aggCell.HAnchor |= HAnchor.Center;
|
||||
// break;
|
||||
//case TableColumnAlign.Right:
|
||||
// aggCell.HAnchor |= HAnchor.Right;
|
||||
// break;
|
||||
//case TableColumnAlign.Left:
|
||||
// aggCell.HAnchor |= HAnchor.Left;
|
||||
// break;
|
||||
case TableColumnAlign.Center:
|
||||
aggCellFlow.HAnchor |= HAnchor.Center;
|
||||
break;
|
||||
case TableColumnAlign.Right:
|
||||
aggCellFlow.HAnchor |= HAnchor.Right;
|
||||
break;
|
||||
case TableColumnAlign.Left:
|
||||
aggCellFlow.HAnchor |= HAnchor.Left;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,29 +10,39 @@ using MatterHackers.Agg.UI;
|
|||
|
||||
namespace Markdig.Renderers.Agg
|
||||
{
|
||||
public class TableHeadingRow: FlowLayoutWidget
|
||||
public class AggTableRow: FlowLayoutWidget
|
||||
{
|
||||
public TableHeadingRow()
|
||||
public AggTableRow()
|
||||
{
|
||||
this.VAnchor = VAnchor.Fit;
|
||||
this.HAnchor = HAnchor.Stretch;
|
||||
this.Margin = new BorderDouble(3, 4, 0, 12);
|
||||
// Likely needs to be implemented here as well
|
||||
//this.RowPadding = new BorderDouble(0, 3);
|
||||
|
||||
// Hack to force content on-screen (seemingly not working when set late/after constructor)
|
||||
VAnchor = VAnchor.Absolute;
|
||||
Height = 25;
|
||||
}
|
||||
|
||||
public bool IsHeadingRow { get; set; }
|
||||
|
||||
// Override AddChild to push styles to child elements when table rows are resolved to the tree
|
||||
public override GuiWidget AddChild(GuiWidget childToAdd, int indexInChildrenList = -1)
|
||||
{
|
||||
if (childToAdd is TextWidget textWidget)
|
||||
{
|
||||
// textWidget.TextColor = new Color("#036ac3");
|
||||
textWidget.Bold = true;
|
||||
if (this.IsHeadingRow)
|
||||
{
|
||||
textWidget.Bold = true;
|
||||
}
|
||||
}
|
||||
else if (childToAdd is TextLinkX textLink)
|
||||
{
|
||||
foreach (var childTextWidget in childToAdd.Children.OfType<TextWidget>())
|
||||
{
|
||||
childTextWidget.Bold = true;
|
||||
if (this.IsHeadingRow)
|
||||
{
|
||||
childTextWidget.Bold = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue