From fab0f5bfe1d4100cfd7bf8b921b36509c9917ff2 Mon Sep 17 00:00:00 2001 From: MarcinZiabek Date: Thu, 29 Sep 2022 21:21:25 +0200 Subject: [PATCH] RTL: constrained --- QuestPDF.Examples/RightToLeftExamples.cs | 19 +++++++++++++++++++ QuestPDF/Elements/Constrained.cs | 14 +++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/QuestPDF.Examples/RightToLeftExamples.cs b/QuestPDF.Examples/RightToLeftExamples.cs index bca4226..e045a61 100644 --- a/QuestPDF.Examples/RightToLeftExamples.cs +++ b/QuestPDF.Examples/RightToLeftExamples.cs @@ -124,5 +124,24 @@ namespace QuestPDF.Examples .Background(Colors.Red.Medium); }); } + + [Test] + public void Constrained() + { + RenderingTest + .Create() + .ProduceImages() + .PageSize(600, 600) + .ShowResults() + .Render(container => + { + container + .Padding(25) + .ContentFromRightToLeft() + .Border(1) + .MaxWidth(100) + .Background(Colors.Red.Medium); + }); + } } } \ No newline at end of file diff --git a/QuestPDF/Elements/Constrained.cs b/QuestPDF/Elements/Constrained.cs index 910bb91..4022339 100644 --- a/QuestPDF/Elements/Constrained.cs +++ b/QuestPDF/Elements/Constrained.cs @@ -5,8 +5,10 @@ using QuestPDF.Infrastructure; namespace QuestPDF.Elements { - internal class Constrained : ContainerElement, ICacheable + internal class Constrained : ContainerElement, ICacheable, IContentDirectionAware { + public ContentDirection ContentDirection { get; set; } + public float? MinWidth { get; set; } public float? MaxWidth { get; set; } @@ -45,11 +47,17 @@ namespace QuestPDF.Elements internal override void Draw(Size availableSpace) { - var available = new Size( + var size = new Size( Min(MaxWidth, availableSpace.Width), Min(MaxHeight, availableSpace.Height)); - Child?.Draw(available); + var offset = ContentDirection == ContentDirection.LeftToRight + ? Position.Zero + : new Position(availableSpace.Width - size.Width, 0); + + Canvas.Translate(offset); + base.Draw(size); + Canvas.Translate(offset.Reverse()); } private static float Min(float? x, float y)