RowExamples.cs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 ColumnTypes()
  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. .Stack(stack =>
  25. {
  26. stack.Item().LabelCell("Total width: 600px");
  27. stack.Item().Row(row =>
  28. {
  29. row.ConstantColumn(150).ValueCell("150px");
  30. row.ConstantColumn(100).ValueCell("100px");
  31. row.RelativeColumn(4).ValueCell("200px");
  32. row.RelativeColumn(3).ValueCell("150px");
  33. });
  34. stack.Item().Row(row =>
  35. {
  36. row.ConstantColumn(100).ValueCell("100px");
  37. row.ConstantColumn(50).ValueCell("50px");
  38. row.RelativeColumn(3).ValueCell("300px");
  39. row.RelativeColumn(1).ValueCell("100px");
  40. row.ConstantColumn(50).ValueCell("50px");
  41. });
  42. });
  43. });
  44. }
  45. [Test]
  46. public void Stability()
  47. {
  48. // up to version 2021.12, this code would always result with the infinite layout exception
  49. RenderingTest
  50. .Create()
  51. .ProducePdf()
  52. .MaxPages(100)
  53. .PageSize(250, 150)
  54. .ShowResults()
  55. .Render(container =>
  56. {
  57. container
  58. .Padding(25)
  59. .Row(row =>
  60. {
  61. row.RelativeColumn().Stack(stack =>
  62. {
  63. stack.Item().ShowOnce().Element(CreateBox).Text("X");
  64. stack.Item().Element(CreateBox).Text("1");
  65. stack.Item().Element(CreateBox).Text("2");
  66. });
  67. row.RelativeColumn().Stack(stack =>
  68. {
  69. stack.Item().Element(CreateBox).Text("1");
  70. stack.Item().Element(CreateBox).Text("2");
  71. });
  72. });
  73. });
  74. static IContainer CreateBox(IContainer container)
  75. {
  76. return container
  77. .ExtendHorizontal()
  78. .ExtendVertical()
  79. .Background(Colors.Grey.Lighten4)
  80. .Border(1)
  81. .AlignCenter()
  82. .AlignMiddle()
  83. .ShowOnce();
  84. }
  85. }
  86. }
  87. }