RightToLeftExamples.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. using NUnit.Framework;
  2. using QuestPDF.Elements;
  3. using QuestPDF.Examples.Engine;
  4. using QuestPDF.Fluent;
  5. using QuestPDF.Helpers;
  6. using QuestPDF.Infrastructure;
  7. namespace QuestPDF.Examples
  8. {
  9. public class RightToLeftExamples
  10. {
  11. [Test]
  12. public void Unconstrained()
  13. {
  14. RenderingTest
  15. .Create()
  16. .ProduceImages()
  17. .PageSize(600, 600)
  18. .ShowResults()
  19. .Render(container =>
  20. {
  21. container
  22. .AlignCenter()
  23. .AlignMiddle()
  24. .ContentFromRightToLeft()
  25. .Unconstrained()
  26. .Background(Colors.Red.Medium)
  27. .Height(200)
  28. .Width(200);
  29. });
  30. }
  31. [Test]
  32. public void Row()
  33. {
  34. RenderingTest
  35. .Create()
  36. .ProduceImages()
  37. .PageSize(600, 600)
  38. .ShowResults()
  39. .Render(container =>
  40. {
  41. container
  42. .Padding(25)
  43. .ContentFromRightToLeft()
  44. .Border(1)
  45. .Row(row =>
  46. {
  47. row.ConstantItem(200).Background(Colors.Red.Lighten2).Height(200);
  48. row.ConstantItem(150).Background(Colors.Green.Lighten2).Height(200);
  49. row.ConstantItem(100).Background(Colors.Blue.Lighten2).Height(200);
  50. });
  51. });
  52. }
  53. [Test]
  54. public void MinimalBox()
  55. {
  56. RenderingTest
  57. .Create()
  58. .ProduceImages()
  59. .PageSize(600, 600)
  60. .ShowResults()
  61. .Render(container =>
  62. {
  63. container
  64. .Padding(25)
  65. .ContentFromRightToLeft()
  66. .Border(1)
  67. .MinimalBox()
  68. .Column(column =>
  69. {
  70. column.Item().Background(Colors.Red.Lighten2).Width(200).Height(200);
  71. column.Item().Background(Colors.Green.Lighten2).Width(150).Height(150);
  72. column.Item().Background(Colors.Blue.Lighten2).Width(100).Height(100);
  73. });
  74. });
  75. }
  76. [Test]
  77. public void Table()
  78. {
  79. RenderingTest
  80. .Create()
  81. .ProduceImages()
  82. .PageSize(600, 600)
  83. .ShowResults()
  84. .Render(container =>
  85. {
  86. container
  87. .Padding(25)
  88. .ContentFromRightToLeft()
  89. .Border(1)
  90. .Table(table =>
  91. {
  92. table.ColumnsDefinition(columns =>
  93. {
  94. columns.ConstantColumn(200);
  95. columns.ConstantColumn(150);
  96. columns.ConstantColumn(100);
  97. });
  98. table.Cell().Background(Colors.Red.Lighten2).Height(200);
  99. table.Cell().Background(Colors.Green.Lighten2).Height(200);
  100. table.Cell().Background(Colors.Blue.Lighten2).Height(200);
  101. });
  102. });
  103. }
  104. [Test]
  105. public void AspectRatio()
  106. {
  107. RenderingTest
  108. .Create()
  109. .ProduceImages()
  110. .PageSize(600, 600)
  111. .ShowResults()
  112. .Render(container =>
  113. {
  114. container
  115. .Padding(25)
  116. .ContentFromRightToLeft()
  117. .Border(1)
  118. .AspectRatio(0.55f, AspectRatioOption.FitArea)
  119. .Background(Colors.Red.Medium);
  120. });
  121. }
  122. [Test]
  123. public void Constrained()
  124. {
  125. RenderingTest
  126. .Create()
  127. .ProduceImages()
  128. .PageSize(600, 600)
  129. .ShowResults()
  130. .Render(container =>
  131. {
  132. container
  133. .Padding(25)
  134. .ContentFromRightToLeft()
  135. .Border(1)
  136. .MaxWidth(100)
  137. .Background(Colors.Red.Medium);
  138. });
  139. }
  140. [Test]
  141. public void Dynamic()
  142. {
  143. RenderingTest
  144. .Create()
  145. .ProduceImages()
  146. .PageSize(600, 600)
  147. .ShowResults()
  148. .Render(container =>
  149. {
  150. container
  151. .Padding(25)
  152. .ContentFromRightToLeft()
  153. .Dynamic(new SimpleDynamic());
  154. });
  155. }
  156. class SimpleDynamic : IDynamicComponent<int>
  157. {
  158. public int State { get; set; }
  159. public DynamicComponentComposeResult Compose(DynamicContext context)
  160. {
  161. var content = context.CreateElement(container =>
  162. {
  163. container
  164. .Row(row =>
  165. {
  166. row.ConstantItem(200).Background(Colors.Red.Lighten2).Height(200);
  167. row.ConstantItem(150).Background(Colors.Green.Lighten2).Height(200);
  168. row.ConstantItem(100).Background(Colors.Blue.Lighten2).Height(200);
  169. });
  170. });
  171. return new DynamicComponentComposeResult
  172. {
  173. Content = content,
  174. HasMoreContent = false
  175. };
  176. }
  177. }
  178. }
  179. }