From 11a778423008b36471aba4bfae8babfca04e628d Mon Sep 17 00:00:00 2001 From: John Lewin Date: Mon, 29 Aug 2022 08:20:32 -0700 Subject: [PATCH] Use shared type for TableRow behavior, set styles for alignment --- .../Utilities/MarkdigAgg/AggTableRenderer.cs | 41 +++++++++++-------- .../{TableHeadingRow.cs => AggTableRow.cs} | 24 +++++++---- 2 files changed, 42 insertions(+), 23 deletions(-) rename MatterControlLib/Utilities/MarkdigAgg/{TableHeadingRow.cs => AggTableRow.cs} (63%) diff --git a/MatterControlLib/Utilities/MarkdigAgg/AggTableRenderer.cs b/MatterControlLib/Utilities/MarkdigAgg/AggTableRenderer.cs index 347c59f81..58810d34b 100644 --- a/MatterControlLib/Utilities/MarkdigAgg/AggTableRenderer.cs +++ b/MatterControlLib/Utilities/MarkdigAgg/AggTableRenderer.cs @@ -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; } } } diff --git a/MatterControlLib/Utilities/MarkdigAgg/TableHeadingRow.cs b/MatterControlLib/Utilities/MarkdigAgg/AggTableRow.cs similarity index 63% rename from MatterControlLib/Utilities/MarkdigAgg/TableHeadingRow.cs rename to MatterControlLib/Utilities/MarkdigAgg/AggTableRow.cs index 05b7cb948..1258993bf 100644 --- a/MatterControlLib/Utilities/MarkdigAgg/TableHeadingRow.cs +++ b/MatterControlLib/Utilities/MarkdigAgg/AggTableRow.cs @@ -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()) { - childTextWidget.Bold = true; + if (this.IsHeadingRow) + { + childTextWidget.Bold = true; + } } }