void Render(ListBlock parent, ListStyle listTheme, int index, ListItemBlock block) { var initialStack = stack; stack = new StackLayout() { Spacing = 0, VerticalOptions = listTheme.ItemVerticalOptions, }; Render(block.AsEnumerable()); Grid.SetColumn(stack, 1); var horizontalStack = new Grid { ColumnDefinitions = new ColumnDefinitionCollection { new ColumnDefinition() { Width = GridLength.Auto }, new ColumnDefinition() { Width = GridLength.Star }, }, ColumnSpacing = listTheme.Spacing ?? Theme.Margin, RowSpacing = 0, Margin = new Thickness(block.Column * listTheme.Indentation, 0, 0, 0), }; if (listTheme.BulletStyleType == ListStyleType.None) { horizontalStack.ColumnSpacing = 0; } var bullet = GetListBullet(listTheme, index, parent, block); if (bullet != null) { Grid.SetColumn(bullet, 0); horizontalStack.Children.Add(bullet); } horizontalStack.Children.Add(stack); initialStack.Children.Add(horizontalStack); stack = initialStack; }
View GetListBullet(ListStyle listTheme, int index, ListBlock parent, ListItemBlock block) { if (listTheme.BulletStyleType == ListStyleType.None) { return(null); } if (listTheme.BulletStyleType == ListStyleType.Custom) { return(listTheme.CustomCallback?.Invoke(index, parent, block)); } if (listTheme.BulletStyleType == ListStyleType.Decimal || listTheme.BulletStyleType == ListStyleType.Symbol) { return(new Label { Text = listTheme.BulletStyleType == ListStyleType.Symbol ? listTheme.Symbol : $"{index}.", FontSize = listTheme.BulletFontSize ?? Theme.Paragraph.FontSize, TextColor = listTheme.BulletColor ?? Theme.Paragraph.ForegroundColor, LineHeight = listTheme.BulletLineHeight ?? Theme.Paragraph.LineHeight, FontAttributes = listTheme.BulletFontAttributes, VerticalOptions = listTheme.BulletVerticalOptions, }); } else if (listTheme.BulletStyleType == ListStyleType.Square || listTheme.BulletStyleType == ListStyleType.Circle) { var bullet = new Frame { WidthRequest = listTheme.BulletSize, HeightRequest = listTheme.BulletSize, BackgroundColor = listTheme.BulletColor ?? Theme.Paragraph.ForegroundColor, Padding = 0, HasShadow = false, VerticalOptions = listTheme.BulletVerticalOptions, CornerRadius = 0, }; if (listTheme.BulletStyleType == ListStyleType.Circle) { bullet.CornerRadius = listTheme.BulletSize / 2; } return(bullet); } return(null); }
public MarkdownTheme() { Paragraph = new MarkdownStyle { Attributes = FontAttributes.None, FontSize = 12, }; Heading1 = new MarkdownStyle { Attributes = FontAttributes.Bold, BorderSize = 1, FontSize = 26, }; Heading2 = new MarkdownStyle { Attributes = FontAttributes.Bold, BorderSize = 1, FontSize = 22, }; Heading3 = new MarkdownStyle { Attributes = FontAttributes.Bold, FontSize = 20, }; Heading4 = new MarkdownStyle { Attributes = FontAttributes.Bold, FontSize = 18, }; Heading5 = new MarkdownStyle { Attributes = FontAttributes.Bold, FontSize = 16, }; Heading6 = new MarkdownStyle { Attributes = FontAttributes.Bold, FontSize = 14, }; Link = new LinkStyle { Attributes = FontAttributes.None, FontSize = 12, }; Code = new MarkdownStyle { Attributes = FontAttributes.None, FontSize = 12, }; Quote = new MarkdownStyle { Attributes = FontAttributes.None, BorderSize = 4, FontSize = 12, BackgroundColor = Color.Gray.MultiplyAlpha(.1), }; Separator = new MarkdownStyle { BorderSize = 2, }; OrderedList = new ListStyle { BulletStyleType = ListStyleType.Decimal, BulletVerticalOptions = LayoutOptions.Start, ItemVerticalOptions = LayoutOptions.Start, }; UnorderedList = new ListStyle { BulletStyleType = ListStyleType.Square, BulletVerticalOptions = LayoutOptions.Center, ItemVerticalOptions = LayoutOptions.Center, }; // Platform specific properties switch (Device.RuntimePlatform) { case Device.iOS: Code.FontFamily = "Courier"; break; case Device.Android: Code.FontFamily = "monospace"; break; } }