A game framework written with osu! in mind.
at master 62 lines 1.8 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using Markdig.Syntax; 5using osu.Framework.Allocation; 6using osu.Framework.Graphics.Shapes; 7using osuTK.Graphics; 8 9namespace osu.Framework.Graphics.Containers.Markdown 10{ 11 /// <summary> 12 /// Visualises a quote block. 13 /// </summary> 14 /// <code> 15 /// > Quote 16 /// </code> 17 public class MarkdownQuoteBlock : CompositeDrawable, IMarkdownTextFlowComponent 18 { 19 private readonly QuoteBlock quoteBlock; 20 21 [Resolved] 22 private IMarkdownTextFlowComponent parentFlowComponent { get; set; } 23 24 public MarkdownQuoteBlock(QuoteBlock quoteBlock) 25 { 26 this.quoteBlock = quoteBlock; 27 28 AutoSizeAxes = Axes.Y; 29 RelativeSizeAxes = Axes.X; 30 } 31 32 [BackgroundDependencyLoader] 33 private void load() 34 { 35 MarkdownTextFlowContainer textFlow; 36 InternalChildren = new[] 37 { 38 CreateBackground(), 39 textFlow = CreateTextFlow() 40 }; 41 42 if (quoteBlock.LastChild is ParagraphBlock paragraphBlock) 43 textFlow.AddInlineText(paragraphBlock.Inline); 44 } 45 46 protected virtual Drawable CreateBackground() => new Box 47 { 48 Anchor = Anchor.CentreLeft, 49 Origin = Anchor.CentreLeft, 50 RelativeSizeAxes = Axes.Y, 51 Width = 5, 52 Colour = Color4.Gray 53 }; 54 55 public virtual MarkdownTextFlowContainer CreateTextFlow() 56 { 57 var textFlow = parentFlowComponent.CreateTextFlow(); 58 textFlow.Margin = new MarginPadding { Left = 20 }; 59 return textFlow; 60 } 61 } 62}