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 fenced code block. 13 /// </summary> 14 /// <code> 15 /// ``` 16 /// code 17 /// ``` 18 /// </code> 19 public class MarkdownFencedCodeBlock : CompositeDrawable, IMarkdownTextFlowComponent 20 { 21 private readonly FencedCodeBlock fencedCodeBlock; 22 23 [Resolved] 24 private IMarkdownTextFlowComponent parentFlowComponent { get; set; } 25 26 public MarkdownFencedCodeBlock(FencedCodeBlock fencedCodeBlock) 27 { 28 this.fencedCodeBlock = fencedCodeBlock; 29 30 AutoSizeAxes = Axes.Y; 31 RelativeSizeAxes = Axes.X; 32 } 33 34 [BackgroundDependencyLoader] 35 private void load() 36 { 37 MarkdownTextFlowContainer textFlowContainer; 38 InternalChildren = new[] 39 { 40 CreateBackground(), 41 textFlowContainer = CreateTextFlow(), 42 }; 43 44 foreach (var line in fencedCodeBlock.Lines.Lines) 45 textFlowContainer.AddParagraph(line.ToString()); 46 } 47 48 protected virtual Drawable CreateBackground() => new Box 49 { 50 RelativeSizeAxes = Axes.Both, 51 Colour = Color4.Gray, 52 Alpha = 0.5f 53 }; 54 55 public virtual MarkdownTextFlowContainer CreateTextFlow() 56 { 57 var textFlow = parentFlowComponent.CreateTextFlow(); 58 textFlow.Margin = new MarginPadding { Left = 10, Right = 10, Top = 10, Bottom = 10 }; 59 return textFlow; 60 } 61 } 62}