internal bool StartTable(TableSpec spec, List<Block> lines) { // Mustn't have more than 1 preceeding line if (lines.Count > 1) return false; // Rewind, parse the header row then fast forward back to current pos if (lines.Count == 1) { int savepos = position; position = lines[0].lineStart; spec.Headers = spec.ParseRow(this); if (spec.Headers == null) return false; position = savepos; lines.Clear(); } // Parse all rows while (true) { int savepos = position; var row = spec.ParseRow(this); if (row != null) { spec.Rows.Add(row); continue; } position = savepos; break; } return true; }
public static TableSpec Parse(StringScanner p) { // Leading line space allowed p.SkipLinespace(); // Quick check for typical case if (p.current != '|' && p.current != ':' && p.current != '-') return null; // Don't create the spec until it at least looks like one TableSpec spec = null; // Leading bar, looks like a table spec if (p.SkipChar('|')) { spec=new TableSpec(); spec.LeadingBar=true; } // Process all columns while (true) { // Parse column spec p.SkipLinespace(); // Must have something in the spec if (p.current == '|') return null; bool AlignLeft = p.SkipChar(':'); while (p.current == '-') p.SkipForward(1); bool AlignRight = p.SkipChar(':'); p.SkipLinespace(); // Work out column alignment ColumnAlignment col = ColumnAlignment.NA; if (AlignLeft && AlignRight) col = ColumnAlignment.Center; else if (AlignLeft) col = ColumnAlignment.Left; else if (AlignRight) col = ColumnAlignment.Right; if (p.eol) { // Not a spec? if (spec == null) return null; // Add the final spec? spec.Columns.Add(col); return spec; } // We expect a vertical bar if (!p.SkipChar('|')) return null; // Create the table spec if (spec==null) spec=new TableSpec(); // Add the column spec.Columns.Add(col); // Check for trailing vertical bar p.SkipLinespace(); if (p.eol) { spec.TrailingBar = true; return spec; } // Next column } }
public static TableSpec Parse(StringScanner p) { // Leading line space allowed p.SkipLinespace(); // Quick check for typical case if (p.current != '|' && p.current != ':' && p.current != '-') { return(null); } // Don't create the spec until it at least looks like one TableSpec spec = null; // Leading bar, looks like a table spec if (p.SkipChar('|')) { spec = new TableSpec(); spec.LeadingBar = true; } // Process all columns while (true) { // Parse column spec p.SkipLinespace(); // Must have something in the spec if (p.current == '|') { return(null); } bool AlignLeft = p.SkipChar(':'); while (p.current == '-') { p.SkipForward(1); } bool AlignRight = p.SkipChar(':'); p.SkipLinespace(); // Work out column alignment ColumnAlignment col = ColumnAlignment.NA; if (AlignLeft && AlignRight) { col = ColumnAlignment.Center; } else if (AlignLeft) { col = ColumnAlignment.Left; } else if (AlignRight) { col = ColumnAlignment.Right; } if (p.eol) { // Not a spec? if (spec == null) { return(null); } // Add the final spec? spec.Columns.Add(col); return(spec); } // We expect a vertical bar if (!p.SkipChar('|')) { return(null); } // Create the table spec if (spec == null) { spec = new TableSpec(); } // Add the column spec.Columns.Add(col); // Check for trailing vertical bar p.SkipLinespace(); if (p.eol) { spec.TrailingBar = true; return(spec); } // Next column } }
public virtual void Create_Table(PUGameObject container, TableSpec table) { }
public override void Create_Table(PUGameObject container, TableSpec spec) { float margin = DefaultFontSize(); currentY -= paragraphSpacing(); float savedY = currentY; PUGridLayoutGroup tableGroup = new PUGridLayoutGroup(); tableGroup.SetFrame (padding.left+2, currentY, container.size.Value.x, 100, 0, 1, "top,left"); tableGroup.LoadIntoPUGameObject (container); // Fill out the group, then figure out the height / widths needed based upon the content float maxCellWidth = 0; float maxCellHeight = 0; int numberOfCols = 0; int numberOfRows = 0; if (spec.Headers != null) { for (int i = 0; i < spec.Headers.Count; i++) { string header = spec.Headers [i]; ColumnAlignment alignment = spec.Columns [i]; TMPro.TextAlignmentOptions tmAlignment = TMPro.TextAlignmentOptions.Left; if (alignment == ColumnAlignment.Right) { tmAlignment = TMPro.TextAlignmentOptions.Right; } if (alignment == ColumnAlignment.Center) { tmAlignment = TMPro.TextAlignmentOptions.Center; } PUTMPro text = AddTextWithOptions (tableGroup, header, DefaultFont (), textColor (), 1.0f, "Bold", tmAlignment); Vector2 size = text.rectTransform.sizeDelta + new Vector2 (margin * 2.0f, margin); text.rectTransform.pivot = Vector2.zero; text.rectTransform.anchorMax = Vector2.one; text.rectTransform.anchorMin = Vector2.zero; PutTextInBox (tableGroup, text, 2, new Color32 (204, 204, 204, 255), new Color32 (255, 255, 255, 255)); text.SetStretchStretch (margin * 0.5f, margin, margin * 0.5f, margin); if (size.x > maxCellWidth) { maxCellWidth = size.x; } if (size.y > maxCellHeight) { maxCellHeight = size.y; } } } numberOfCols = spec.Rows[0].Count; numberOfRows = spec.Rows.Count; if (spec.Headers != null && spec.Headers.Count > 0) { numberOfRows++; } for(int i = 0; i < spec.Rows.Count; i++) { List<string> rows = spec.Rows[i]; for(int j = 0; j < rows.Count; j++) { string row = rows[j]; ColumnAlignment alignment = spec.Columns[j]; TMPro.TextAlignmentOptions tmAlignment = TMPro.TextAlignmentOptions.Left; if(alignment == ColumnAlignment.Right){ tmAlignment = TMPro.TextAlignmentOptions.Right; } if(alignment == ColumnAlignment.Center){ tmAlignment = TMPro.TextAlignmentOptions.Center; } PUTMPro text = AddTextWithOptions (tableGroup, row, DefaultFont(), textColor(), 1.0f, "Normal", tmAlignment); Vector2 size = text.rectTransform.sizeDelta + new Vector2(margin*2.0f,margin); text.rectTransform.pivot = Vector2.zero; text.rectTransform.anchorMax = Vector2.one; text.rectTransform.anchorMin = Vector2.zero; if(i % 2 != 0){ PutTextInBox (tableGroup, text, 2, new Color32 (204, 204, 204, 255), new Color32 (248, 248, 248, 255)); }else{ PutTextInBox (tableGroup, text, 2, new Color32 (204, 204, 204, 255), new Color32 (255, 255, 255, 255)); } text.SetStretchStretch (margin*0.5f, margin, margin*0.5f, margin); if(size.x > maxCellWidth){ maxCellWidth = size.x; } if(size.y > maxCellHeight){ maxCellHeight = size.y; } } } tableGroup.layout.cellSize = new Vector2 (maxCellWidth, maxCellHeight); tableGroup.rectTransform.sizeDelta = new Vector2 (maxCellWidth * numberOfCols, maxCellHeight * numberOfRows); currentY = savedY - tableGroup.rectTransform.sizeDelta.y; }