From b2cc7bbd36504e3d6bad166b10865d21e85a9c84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Zi=C4=85bek?= Date: Sun, 16 Jan 2022 17:08:57 +0100 Subject: [PATCH] Renamed Decoration element --- QuestPDF.Examples/ElementExamples.cs | 4 +- QuestPDF.Examples/InlinedExamples.cs | 2 +- QuestPDF.Examples/TextBenchmark.cs | 2 +- .../Layouts/SectionTemplate.cs | 2 +- .../Layouts/TableOfContentsTemplate.cs | 2 +- QuestPDF/Elements/Decoration.cs | 34 +++++++------- QuestPDF/Elements/Page.cs | 4 +- QuestPDF/Fluent/DecorationExtensions.cs | 44 +++++++++++++++---- QuestPDF/Fluent/TableExtensions.cs | 4 +- 9 files changed, 63 insertions(+), 35 deletions(-) diff --git a/QuestPDF.Examples/ElementExamples.cs b/QuestPDF.Examples/ElementExamples.cs index cdcbd3b..635961c 100644 --- a/QuestPDF.Examples/ElementExamples.cs +++ b/QuestPDF.Examples/ElementExamples.cs @@ -40,7 +40,7 @@ namespace QuestPDF.Examples .Decoration(decoration => { decoration - .Header() + .Before() .Background(Colors.Grey.Medium) .Padding(10) .Text("Notes", TextStyle.Default.Size(16).Color("#FFF")); @@ -501,7 +501,7 @@ namespace QuestPDF.Examples .SemiBold(); decoration - .Header() + .Before() .PaddingBottom(10) .Text("Example: scale component", headerFontStyle); diff --git a/QuestPDF.Examples/InlinedExamples.cs b/QuestPDF.Examples/InlinedExamples.cs index 72c7e1e..fce4c85 100644 --- a/QuestPDF.Examples/InlinedExamples.cs +++ b/QuestPDF.Examples/InlinedExamples.cs @@ -25,7 +25,7 @@ namespace QuestPDF.Examples .Padding(25) .Decoration(decoration => { - decoration.Header().Text(text => + decoration.Before().Text(text => { text.DefaultTextStyle(TextStyle.Default.Size(20)); diff --git a/QuestPDF.Examples/TextBenchmark.cs b/QuestPDF.Examples/TextBenchmark.cs index 4adaee9..47645a3 100644 --- a/QuestPDF.Examples/TextBenchmark.cs +++ b/QuestPDF.Examples/TextBenchmark.cs @@ -129,7 +129,7 @@ namespace QuestPDF.Examples column.Item().Element(Acknowledgements); }); - decoration.Footer().Element(Footer); + decoration.After().Element(Footer); }); } diff --git a/QuestPDF.ReportSample/Layouts/SectionTemplate.cs b/QuestPDF.ReportSample/Layouts/SectionTemplate.cs index 361277a..2e37ec3 100644 --- a/QuestPDF.ReportSample/Layouts/SectionTemplate.cs +++ b/QuestPDF.ReportSample/Layouts/SectionTemplate.cs @@ -21,7 +21,7 @@ namespace QuestPDF.ReportSample.Layouts .Decoration(decoration => { decoration - .Header() + .Before() .PaddingBottom(5) .Text(Model.Title, Typography.Headline); diff --git a/QuestPDF.ReportSample/Layouts/TableOfContentsTemplate.cs b/QuestPDF.ReportSample/Layouts/TableOfContentsTemplate.cs index a3cb715..3f93f93 100644 --- a/QuestPDF.ReportSample/Layouts/TableOfContentsTemplate.cs +++ b/QuestPDF.ReportSample/Layouts/TableOfContentsTemplate.cs @@ -19,7 +19,7 @@ namespace QuestPDF.ReportSample.Layouts .Decoration(decoration => { decoration - .Header() + .Before() .PaddingBottom(5) .Text("Table of contents", Typography.Headline); diff --git a/QuestPDF/Elements/Decoration.cs b/QuestPDF/Elements/Decoration.cs index 7b2fcd7..12e9646 100644 --- a/QuestPDF/Elements/Decoration.cs +++ b/QuestPDF/Elements/Decoration.cs @@ -17,22 +17,22 @@ namespace QuestPDF.Elements internal class Decoration : Element, ICacheable { - internal Element Header { get; set; } = new Empty(); + internal Element Before { get; set; } = new Empty(); internal Element Content { get; set; } = new Empty(); - internal Element Footer { get; set; } = new Empty(); + internal Element After { get; set; } = new Empty(); internal override IEnumerable GetChildren() { - yield return Header; + yield return Before; yield return Content; - yield return Footer; + yield return After; } internal override void CreateProxy(Func create) { - Header = create(Header); + Before = create(Before); Content = create(Content); - Footer = create(Footer); + After = create(After); } internal override SpacePlan Measure(Size availableSpace) @@ -68,17 +68,17 @@ namespace QuestPDF.Elements private IEnumerable PlanLayout(Size availableSpace) { - var headerMeasurement = Header.Measure(availableSpace); - var footerMeasurement = Footer.Measure(availableSpace); + var beforeMeasurement = Before.Measure(availableSpace); + var afterMeasurement = After.Measure(availableSpace); - var contentSpace = new Size(availableSpace.Width, availableSpace.Height - headerMeasurement.Height - footerMeasurement.Height); + var contentSpace = new Size(availableSpace.Width, availableSpace.Height - beforeMeasurement.Height - afterMeasurement.Height); var contentMeasurement = Content.Measure(contentSpace); yield return new DecorationItemRenderingCommand { - Element = Header, - Measurement = headerMeasurement, - Size = new Size(availableSpace.Width, headerMeasurement.Height), + Element = Before, + Measurement = beforeMeasurement, + Size = new Size(availableSpace.Width, beforeMeasurement.Height), Offset = Position.Zero }; @@ -87,15 +87,15 @@ namespace QuestPDF.Elements Element = Content, Measurement = contentMeasurement, Size = new Size(availableSpace.Width, contentMeasurement.Height), - Offset = new Position(0, headerMeasurement.Height) + Offset = new Position(0, beforeMeasurement.Height) }; yield return new DecorationItemRenderingCommand { - Element = Footer, - Measurement = footerMeasurement, - Size = new Size(availableSpace.Width, footerMeasurement.Height), - Offset = new Position(0, headerMeasurement.Height + contentMeasurement.Height) + Element = After, + Measurement = afterMeasurement, + Size = new Size(availableSpace.Width, afterMeasurement.Height), + Offset = new Position(0, beforeMeasurement.Height + contentMeasurement.Height) }; } } diff --git a/QuestPDF/Elements/Page.cs b/QuestPDF/Elements/Page.cs index 0368409..7d06bbe 100644 --- a/QuestPDF/Elements/Page.cs +++ b/QuestPDF/Elements/Page.cs @@ -45,7 +45,7 @@ namespace QuestPDF.Elements .Decoration(decoration => { decoration - .Header() + .Before() .DebugPointer("Page header") .Element(Header); @@ -57,7 +57,7 @@ namespace QuestPDF.Elements .Element(Content); decoration - .Footer() + .After() .DebugPointer("Page footer") .Element(Footer); }); diff --git a/QuestPDF/Fluent/DecorationExtensions.cs b/QuestPDF/Fluent/DecorationExtensions.cs index 3b6cf67..4dfec71 100644 --- a/QuestPDF/Fluent/DecorationExtensions.cs +++ b/QuestPDF/Fluent/DecorationExtensions.cs @@ -8,16 +8,16 @@ namespace QuestPDF.Fluent { internal Decoration Decoration { get; } = new Decoration(); - public IContainer Header() + public IContainer Before() { var container = new Container(); - Decoration.Header = container; + Decoration.Before = container; return container; } - public void Header(Action handler) + public void Before(Action handler) { - handler?.Invoke(Header()); + handler?.Invoke(Before()); } public IContainer Content() @@ -32,17 +32,45 @@ namespace QuestPDF.Fluent handler?.Invoke(Content()); } - public IContainer Footer() + public IContainer After() { var container = new Container(); - Decoration.Footer = container; + Decoration.After = container; return container; } - public void Footer(Action handler) + public void After(Action handler) { - handler?.Invoke(Footer()); + handler?.Invoke(After()); } + + #region Obsolete + + // public IContainer Header() + // { + // var container = new Container(); + // Decoration.Before = container; + // return container; + // } + // + // public void Header(Action handler) + // { + // handler?.Invoke(Header()); + // } + // + // public IContainer Footer() + // { + // var container = new Container(); + // Decoration.After = container; + // return container; + // } + // + // public void Footer(Action handler) + // { + // handler?.Invoke(Footer()); + // } + + #endregion } public static class DecorationExtensions diff --git a/QuestPDF/Fluent/TableExtensions.cs b/QuestPDF/Fluent/TableExtensions.cs index 8e66257..e0af338 100644 --- a/QuestPDF/Fluent/TableExtensions.cs +++ b/QuestPDF/Fluent/TableExtensions.cs @@ -101,9 +101,9 @@ namespace QuestPDF.Fluent container .Decoration(decoration => { - decoration.Header().Element(HeaderTable); + decoration.Before().Element(HeaderTable); decoration.Content().Element(ContentTable); - decoration.Footer().Element(FooterTable); + decoration.After().Element(FooterTable); }); return container;