public void EmptyEnumeratorPushBack() { var en = new PushBackEnumerator <int>(new List <int>(), 0, 0); en.MoveNext().Should().BeFalse(); en.PushBack(-1); en.MoveNext().Should().BeTrue(); en.Current.Should().Be(-1); en.MoveNext().Should().BeFalse(); }
public void SingleContentEnumerator() { var en = new PushBackEnumerator <int>(new List <int> { 1, 2 }, 0, 1); en.MoveNext().Should().BeTrue(); en.PushBack(-1); en.Current.Should().Be(1); en.MoveNext().Should().BeTrue(); en.Current.Should().Be(-1); en.MoveNext().Should().BeFalse(); }
public void ThreeItemContentEnumerator() { var en = new PushBackEnumerator <int>(new List <int> { 1, 2, 3 }, 0, 3); en.MoveNext().Should().BeTrue(); en.PushBack(-1); en.Current.Should().Be(1); en.MoveNext().Should().BeTrue(); en.Current.Should().Be(-1); en.MoveNext().Should().BeTrue(); en.Current.Should().Be(2); en.MoveNext().Should().BeTrue(); en.Current.Should().Be(3); en.MoveNext().Should().BeFalse(); }
public void EmptyEnumerator() { var en = new PushBackEnumerator <int>(new List <int>(), 0, 0); en.MoveNext().Should().BeFalse(); }
void Reflow(Size size) { float width = size.Width; if (Style.GetValue(TextStyles.WrapText) != WrapText.Auto) { width = float.PositiveInfinity; } if (!Dirty && Math.Abs(width - lineWidth) < 0.5) { return; } lineWidth = -1; for (var i = lineBreakContent.Count - 1; i >= 0; i--) { var v = lineBreakContent[i]; v.Chunk.RemoveNotify(this); lineBreakContent.RemoveAt(i); } lineMetrics.Clear(); bool justified = GetAlignment() == Alignment.Fill; var lineStartIndex = 0; var lineEndIndex = 0; float x = 0; var enumerator = new PushBackEnumerator <ITextChunkView <TDocument> >(rawContent, 0, rawContent.Count); var lineContent = new List <ITextChunkView <TDocument> >(); while (enumerator.MoveNext()) { var chunk = enumerator.Current; chunk.Measure(Size.Auto); if (chunk.DesiredSize.Width <= width) { lineContent.Add(chunk); x += chunk.DesiredSize.Width; continue; } // Attempt a linebreak ITextChunkView <TDocument> first; ITextChunkView <TDocument> second; chunk.BreakAt(width - x, out first, out second); first.Measure(Size.Auto); lineContent.Add(first); width = Math.Max(x + first.DesiredSize.Width, width); // Add all chunks for the current line into the break content. lineEndIndex += AddNodes(lineContent, justified, size); lineContent.Clear(); // only start a new line, if there is actual content in that line. // This check avoids an empty line if the first line's content is // too large to fit on the line. var lineMetric = ComputeLineMetrics(lineStartIndex, lineEndIndex); lineMetrics.Add(lineMetric); AlignLineChunks(lineMetric, width); lineStartIndex = lineEndIndex; x = 0; if (second != null) { enumerator.PushBack(second); } } if (lineContent.Count > 0) { lineEndIndex += AddNodes(lineContent, justified, size); var metrics = ComputeLineMetrics(lineStartIndex, lineEndIndex); lineMetrics.Add(metrics); AlignLineChunks(metrics, width); } if (justified && lineBreakContent.Count > 0) { var count = lineBreakContent.Count; for (var i = 0; i < count; i++) { var jc = lineBreakContent[i].Chunk as JustifiedTextChunkView <TDocument>; if (jc != null) { jc.LastLine = i == count - 1; } } } lineWidth = width; }