RowExamples.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using NUnit.Framework;
  2. using QuestPDF.Examples.Engine;
  3. using QuestPDF.Fluent;
  4. using QuestPDF.Helpers;
  5. using QuestPDF.Infrastructure;
  6. namespace QuestPDF.Examples
  7. {
  8. public class RowExamples
  9. {
  10. [Test]
  11. public void ItemTypes()
  12. {
  13. RenderingTest
  14. .Create()
  15. .ProducePdf()
  16. .PageSize(650, 300)
  17. .ShowResults()
  18. .Render(container =>
  19. {
  20. container
  21. .Padding(25)
  22. .MinimalBox()
  23. .Border(1)
  24. .Column(column =>
  25. {
  26. column.Item().LabelCell("Total width: 600px");
  27. column.Item().Row(row =>
  28. {
  29. row.ConstantItem(150).ValueCell("150px");
  30. row.ConstantItem(100).ValueCell("100px");
  31. row.RelativeItem(4).ValueCell("200px");
  32. row.RelativeItem(3).ValueCell("150px");
  33. });
  34. column.Item().Row(row =>
  35. {
  36. row.ConstantItem(100).ValueCell("100px");
  37. row.ConstantItem(50).ValueCell("50px");
  38. row.RelativeItem(2).ValueCell("100px");
  39. row.RelativeItem(1).ValueCell("50px");
  40. });
  41. });
  42. });
  43. }
  44. [Test]
  45. public void Stability()
  46. {
  47. // up to version 2021.12, this code would always result with the infinite layout exception
  48. RenderingTest
  49. .Create()
  50. .ProducePdf()
  51. .MaxPages(100)
  52. .PageSize(250, 150)
  53. .ShowResults()
  54. .Render(container =>
  55. {
  56. container
  57. .Padding(25)
  58. .Row(row =>
  59. {
  60. row.RelativeItem().Column(column =>
  61. {
  62. column.Item().ShowOnce().Element(CreateBox).Text("X");
  63. column.Item().Element(CreateBox).Text("1");
  64. column.Item().Element(CreateBox).Text("2");
  65. });
  66. row.RelativeItem().Column(column =>
  67. {
  68. column.Item().Element(CreateBox).Text("1");
  69. column.Item().Element(CreateBox).Text("2");
  70. });
  71. });
  72. });
  73. static IContainer CreateBox(IContainer container)
  74. {
  75. return container
  76. .ExtendHorizontal()
  77. .ExtendVertical()
  78. .Background(Colors.Grey.Lighten4)
  79. .Border(1)
  80. .AlignCenter()
  81. .AlignMiddle()
  82. .ShowOnce();
  83. }
  84. }
  85. }
  86. }