/// <summary> /// Renders the set of data using the default alignment /// </summary> /// <param name="writer"></param> public void Render(TextWriter writer) { int length = rows.Count; if (length == 0) { return; } var columns = GetColumnState(); var lookup = Dividers.ToLookup(x => x.Index >= 0 ? x.Index : (length + x.Index + 1)); for (int i = 0; i <= length; ++i) { var dividers = lookup[i]; if (dividers.Any()) { foreach (var divider in dividers) { render_divider_line(writer, divider, columns, ColumnsExpected); } } if (i < length) { string[] rowData = rows[i]; render_data_line(writer, rowData, columns, ColumnsExpected); } } }
/// <summary> /// Adds a divider at the current index. /// </summary> /// <param name="repeatChar">The char to repeat in the separator</param> /// <param name="useColumnseparator">If true, the column separators are inserted at the correct intervals, otherwise the divider will span the entire length</param> /// <example> /// tab.AddRow("Head1", "Head2"); /// tab.Divide('-'); // after header /// tab.ImportRows(/*...*/); /// tab.Divide('-'); // after import of rows, before summary /// tab.AddRow("Foot1", "Foot2"); /// </example> /// <returns></returns> public PlainTextTable Divide(char repeatChar, bool useColumnseparator = false) { Dividers.Add(new Divider { Index = rows.Count, Char = repeatChar, UseColumnSeparator = useColumnseparator }); return(this); }
/// <summary> /// Adds a new divider to the Dividers collection. /// /// Dividers are rendered before the index of the next row. /// </summary> /// <param name="index"> /// The line index of where the divider should be inserted. /// /// Use a negative value to work from the last item, backwards (for a footer, for instance). /// /// * An index of 1 will insert a divider after the first row /// * An index of -1 will insert a divider after the last row (an end-of-table divider) /// * An index of -2 will insert a divider before the last row (a summary divider) /// </param> /// <param name="repeatChar">The char to repeat in the separator</param> /// <param name="useColumnseparator">If true, the column separators are inserted at the correct intervals, otherwise the divider will span the entire length</param> /// <returns></returns> public PlainTextTable DivideAt(int index, char repeatChar, bool useColumnseparator = false) { Dividers.Add(new Divider { Index = index, Char = repeatChar, UseColumnSeparator = useColumnseparator }); return(this); }
private void CreateLabel(ref int nextLabelIndex) { Label label = Program.branchLabelList[nextLabelIndex]; Divider labelDivider = Instantiate(dividerPrefab, transform, false).GetComponent <Divider>(); labelDivider.Init(label.val, label); Dividers.Add(labelDivider); // TODO: Need to test on bad devices to see if there's a performance hit when the code list is reset // NOTE: Maybe if there is, we can use pooling and continue to do a full reset GameObject labelBlock = Instantiate(labelBlockPrefab, transform, false); labelBlock.GetComponent <LabelBlock>().Init(label, labelDivider, this); ++nextLabelIndex; }
private void Generate() { cg.blocksRaycasts = initialCGBlocksRaycasts; Dividers.Clear(); SlotFields.Clear(); // Create code block for each instruction in program instructionBlockTransforms = new Transform[Program.instructions.Count]; int lineNumber = 0; int nextLabelIndex = 0; foreach (Instruction instruction in Program.instructions) { // Create any labels for the current line while (nextLabelIndex < Program.branchLabelList.Count && Program.branchLabelList[nextLabelIndex].val == lineNumber) { CreateLabel(ref nextLabelIndex); } // Create divider Divider divider = Instantiate(dividerPrefab, transform, false).GetComponent <Divider>(); divider.Init(lineNumber); Dividers.Add(divider); // Create code block GameObject instructionBlock = Instantiate(instructionBlockPrefab, transform, false); instructionBlock.GetComponent <InstructionBlock>().Init(lineNumber, instruction, divider, this); instructionBlockTransforms[lineNumber] = instructionBlock.transform; ++lineNumber; } // Create any remaining labels while (nextLabelIndex < Program.branchLabelList.Count) { CreateLabel(ref nextLabelIndex); } // Create end divider Divider endDivider = Instantiate(dividerPrefab, transform, false).GetComponent <Divider>(); endDivider.Init(lineNumber); Dividers.Add(endDivider); OnRectTransformDimensionsChange(); }