InlinedExamples.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System;
  2. using System.Linq;
  3. using System.Reflection.Metadata.Ecma335;
  4. using NUnit.Framework;
  5. using QuestPDF.Examples.Engine;
  6. using QuestPDF.Fluent;
  7. using QuestPDF.Helpers;
  8. using QuestPDF.Infrastructure;
  9. namespace QuestPDF.Examples
  10. {
  11. public class InlinedExamples
  12. {
  13. [Test]
  14. public void Inlined()
  15. {
  16. RenderingTest
  17. .Create()
  18. .PageSize(800, 650)
  19. .ProduceImages()
  20. .ShowResults()
  21. .Render(container =>
  22. {
  23. container
  24. .Padding(25)
  25. .Decoration(decoration =>
  26. {
  27. decoration.Before().Text(text =>
  28. {
  29. text.DefaultTextStyle(TextStyle.Default.Size(20));
  30. text.CurrentPageNumber();
  31. text.Span(" / ");
  32. text.TotalPages();
  33. });
  34. decoration
  35. .Content()
  36. .PaddingTop(25)
  37. //.MinimalBox()
  38. .Border(1)
  39. .Background(Colors.Grey.Lighten2)
  40. .Inlined(inlined =>
  41. {
  42. inlined.Spacing(25);
  43. inlined.AlignSpaceAround();
  44. inlined.BaselineMiddle();
  45. var random = new Random(123);
  46. foreach (var _ in Enumerable.Range(0, 50))
  47. {
  48. var width = random.Next(2, 7);
  49. var height = random.Next(2, 7);
  50. var sizeText = $"{width}×{height}";
  51. inlined
  52. .Item()
  53. .Border(1)
  54. .Width(width * 25)
  55. .Height(height * 25)
  56. .Background(Placeholders.BackgroundColor())
  57. .Layers(layers =>
  58. {
  59. layers.Layer().Grid(grid =>
  60. {
  61. grid.Columns(width);
  62. Enumerable.Range(0, width * height).ToList().ForEach(x => grid.Item().Border(1).BorderColor(Colors.White).Width(25).Height(25));
  63. });
  64. layers
  65. .PrimaryLayer()
  66. .AlignCenter()
  67. .AlignMiddle()
  68. .Text(sizeText, TextStyle.Default.Size(15));
  69. });
  70. }
  71. });
  72. });
  73. });
  74. }
  75. [Test]
  76. public void Inline_AlignLeft_BaselineBottom()
  77. {
  78. RenderingTest
  79. .Create()
  80. .PageSize(800, 600)
  81. .ProduceImages()
  82. .ShowResults()
  83. .Render(container =>
  84. {
  85. container
  86. .Padding(20)
  87. .MinimalBox()
  88. .Border(1)
  89. .Background(Colors.Grey.Lighten4)
  90. .Inlined(inlined =>
  91. {
  92. inlined.VerticalSpacing(50);
  93. inlined.HorizontalSpacing(25);
  94. inlined.AlignRight();
  95. inlined.BaselineMiddle();
  96. foreach (var _ in Enumerable.Range(0, 100))
  97. inlined.Item().Element(RandomBlock);
  98. });
  99. });
  100. void RandomBlock(IContainer container)
  101. {
  102. container
  103. .Width(Placeholders.Random.Next(1, 5) * 20)
  104. .Height(Placeholders.Random.Next(1, 5) * 20)
  105. .Border(1)
  106. .BorderColor(Colors.Grey.Darken2)
  107. .Background(Placeholders.BackgroundColor());
  108. }
  109. }
  110. }
  111. }