private static Inline FormatInlineTextRun(AdaptiveTextRun textRun, AdaptiveRenderContext context) { Marked marked = new Marked(); marked.Options.Renderer = new AdaptiveXamlMarkdownRenderer(); marked.Options.Mangle = false; marked.Options.Sanitize = true; // Handle Date/Time parsing string text = RendererUtilities.ApplyTextFunctions(textRun.Text, context.Lang); // Handle markdown string xaml = $"<Span xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xml:space=\"preserve\">{marked.Parse(text)}</Span>"; StringReader stringReader = new StringReader(xaml); XmlReader xmlReader = XmlReader.Create(stringReader); Span uiInlineElement = XamlReader.Load(xmlReader) as Span; uiInlineElement.Style = context.GetStyle($"Adaptive.{textRun.Type}"); uiInlineElement.FontFamily = new FontFamily(context.Config.GetFontFamily(textRun.FontStyle)); uiInlineElement.FontWeight = FontWeight.FromOpenTypeWeight(context.Config.GetFontWeight(textRun.FontStyle, textRun.Weight)); uiInlineElement.FontSize = context.Config.GetFontSize(textRun.FontStyle, textRun.Size); uiInlineElement.SetColor(textRun.Color, textRun.IsSubtle, context); return(uiInlineElement); }
private static void AddInlineTextRun(TextBlock uiRichTB, AdaptiveTextRun textRun, AdaptiveRenderContext context) { Span textRunSpan; if (textRun.SelectAction != null && context.Config.SupportsInteractivity) { Hyperlink selectActionLink = new Hyperlink(); selectActionLink.Click += (sender, e) => { context.InvokeAction(uiRichTB, new AdaptiveActionEventArgs(textRun.SelectAction)); e.Handled = true; }; textRunSpan = selectActionLink as Span; } else { textRunSpan = new Span(); } // Handle Date/Time parsing string text = RendererUtilities.ApplyTextFunctions(textRun.Text, context.Lang); textRunSpan.Inlines.Add(text); textRunSpan.Style = context.GetStyle($"Adaptive.{textRun.Type}"); textRunSpan.FontFamily = new FontFamily(RendererUtil.GetFontFamilyFromList(context.Config.GetFontFamily(textRun.FontType))); textRunSpan.FontWeight = FontWeight.FromOpenTypeWeight(context.Config.GetFontWeight(textRun.FontType, textRun.Weight)); textRunSpan.FontSize = context.Config.GetFontSize(textRun.FontType, textRun.Size); if (textRun.Italic) { textRunSpan.FontStyle = FontStyles.Italic; } if (textRun.Strikethrough) { textRunSpan.TextDecorations.Add(TextDecorations.Strikethrough); } if (textRun.Underline) { textRunSpan.TextDecorations.Add(TextDecorations.Underline); } if (textRun.Highlight) { textRunSpan.SetHighlightColor(textRun.Color, textRun.IsSubtle, context); } textRunSpan.SetColor(textRun.Color, textRun.IsSubtle, context); uiRichTB.Inlines.Add(textRunSpan); }
private static TextBlock CreateControl(AdaptiveTextBlock textBlock, AdaptiveRenderContext context) { Marked marked = new Marked(); marked.Options.Renderer = new AdaptiveXamlMarkdownRenderer(); marked.Options.Mangle = false; marked.Options.Sanitize = true; string text = RendererUtilities.ApplyTextFunctions(textBlock.Text); // uiTextBlock.Text = textBlock.Text; string xaml = $"<TextBlock xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">{marked.Parse(text)}</TextBlock>"; StringReader stringReader = new StringReader(xaml); XmlReader xmlReader = XmlReader.Create(stringReader); var uiTextBlock = (System.Windows.Controls.TextBlock)XamlReader.Load(xmlReader); uiTextBlock.Style = context.GetStyle($"Adaptive.{textBlock.Type}"); uiTextBlock.FontFamily = new FontFamily(context.Config.FontFamily); uiTextBlock.TextWrapping = TextWrapping.NoWrap; switch (textBlock.Weight) { case AdaptiveTextWeight.Bolder: uiTextBlock.FontWeight = FontWeight.FromOpenTypeWeight(700); break; case AdaptiveTextWeight.Lighter: uiTextBlock.FontWeight = FontWeight.FromOpenTypeWeight(300); break; case AdaptiveTextWeight.Default: default: uiTextBlock.FontWeight = FontWeight.FromOpenTypeWeight(400); break; } uiTextBlock.TextTrimming = TextTrimming.CharacterEllipsis; if (textBlock.HorizontalAlignment != AdaptiveHorizontalAlignment.Left) { System.Windows.HorizontalAlignment alignment; if (Enum.TryParse <System.Windows.HorizontalAlignment>(textBlock.HorizontalAlignment.ToString(), out alignment)) { uiTextBlock.HorizontalAlignment = alignment; } } if (textBlock.Wrap) { uiTextBlock.TextWrapping = TextWrapping.Wrap; } return(uiTextBlock); }
private static TextBlock CreateControl(AdaptiveTextBlock textBlock, AdaptiveRenderContext context) { Marked marked = new Marked(); marked.Options.Renderer = new AdaptiveXamlMarkdownRenderer(); marked.Options.Mangle = false; marked.Options.Sanitize = true; string text = RendererUtilities.ApplyTextFunctions(textBlock.Text, context.Lang); // uiTextBlock.Text = textBlock.Text; string xaml = $"<TextBlock xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">{marked.Parse(text)}</TextBlock>"; StringReader stringReader = new StringReader(xaml); XmlReader xmlReader = XmlReader.Create(stringReader); var uiTextBlock = (System.Windows.Controls.TextBlock)XamlReader.Load(xmlReader); uiTextBlock.Style = context.GetStyle($"Adaptive.{textBlock.Type}"); uiTextBlock.TextWrapping = TextWrapping.NoWrap; uiTextBlock.FontFamily = new FontFamily(RendererUtil.GetFontFamilyFromList(context.Config.GetFontFamily(textBlock.FontType))); uiTextBlock.FontWeight = FontWeight.FromOpenTypeWeight(context.Config.GetFontWeight(textBlock.FontType, textBlock.Weight)); uiTextBlock.FontSize = context.Config.GetFontSize(textBlock.FontType, textBlock.Size); uiTextBlock.TextTrimming = TextTrimming.CharacterEllipsis; if (textBlock.Italic) { uiTextBlock.FontStyle = FontStyles.Italic; } if (textBlock.Strikethrough) { uiTextBlock.TextDecorations = TextDecorations.Strikethrough; } if (textBlock.HorizontalAlignment != AdaptiveHorizontalAlignment.Left) { System.Windows.TextAlignment alignment; if (Enum.TryParse <System.Windows.TextAlignment>(textBlock.HorizontalAlignment.ToString(), out alignment)) { uiTextBlock.TextAlignment = alignment; } } if (textBlock.Wrap) { uiTextBlock.TextWrapping = TextWrapping.Wrap; } return(uiTextBlock); }
private static Inline FormatInlineTextRun(AdaptiveTextRun textRun, AdaptiveRenderContext context) { // Handle Date/Time parsing string text = RendererUtilities.ApplyTextFunctions(textRun.Text, context.Lang); Span uiInlineElement = new Span(); uiInlineElement.Inlines.Add(text); uiInlineElement.Style = context.GetStyle($"Adaptive.{textRun.Type}"); uiInlineElement.FontFamily = new FontFamily(context.Config.GetFontFamily(textRun.FontStyle)); uiInlineElement.FontWeight = FontWeight.FromOpenTypeWeight(context.Config.GetFontWeight(textRun.FontStyle, textRun.Weight)); uiInlineElement.FontSize = context.Config.GetFontSize(textRun.FontStyle, textRun.Size); uiInlineElement.SetColor(textRun.Color, textRun.IsSubtle, context); return(uiInlineElement); }
public override string GetNonInteractiveValue() { var chosen = Value?.Split(',').Select(p => p.Trim()).Where(s => !string.IsNullOrEmpty(s)).ToList() ?? new List <string>(); string choiceText; var choices = Choices.Select(choice => choice.Title).ToList(); if (Style == AdaptiveChoiceInputStyle.Compact) { choiceText = IsMultiSelect ? $"Choices: {RendererUtilities.JoinString(choices, ", ", " and ")}" : $"Choices: {RendererUtilities.JoinString(choices, ", ", " or ")}"; } else // if (adaptiveChoiceSetInput.Style == ChoiceInputStyle.Expanded) { choiceText = $"* {RendererUtilities.JoinString(choices, "\n* ", "\n* ")}"; } RendererUtilities.JoinString(Choices.Where(c => chosen.Contains(c.Value)).Select(c => c.Title).ToList(), ", ", " and "); return(choiceText); }
protected static HtmlTag TextBlockRender(AdaptiveTextBlock textBlock, AdaptiveRendererContext context) { int fontSize; switch (textBlock.Size) { case AdaptiveTextSize.Small: fontSize = context.Config.FontSizes.Small; break; case AdaptiveTextSize.Medium: fontSize = context.Config.FontSizes.Medium; break; case AdaptiveTextSize.Large: fontSize = context.Config.FontSizes.Large; break; case AdaptiveTextSize.ExtraLarge: fontSize = context.Config.FontSizes.ExtraLarge; break; case AdaptiveTextSize.Default: default: fontSize = context.Config.FontSizes.Default; break; } int weight = 400; switch (textBlock.Weight) { case AdaptiveTextWeight.Lighter: weight = 200; break; case AdaptiveTextWeight.Bolder: weight = 600; break; } // Not sure where this magic value comes from? var lineHeight = fontSize * 1.33; var uiTextBlock = new HtmlTag("div", false) .AddClass($"ac-{textBlock.Type.Replace(".", "").ToLower()}") .Style("box-sizing", "border-box") .Style("text-align", textBlock.HorizontalAlignment.ToString().ToLower()) .Style("color", context.GetColor(textBlock.Color, textBlock.IsSubtle)) .Style("line-height", $"{lineHeight.ToString("F")}px") .Style("font-size", $"{fontSize}px") .Style("font-weight", $"{weight}"); if (textBlock.MaxLines > 0) { uiTextBlock = uiTextBlock .Style("max-height", $"{lineHeight * textBlock.MaxLines}px") .Style("overflow", "hidden"); } var setWrapStyleOnParagraph = false; if (textBlock.Wrap == false) { uiTextBlock = uiTextBlock .Style("white-space", "nowrap"); setWrapStyleOnParagraph = true; } else { uiTextBlock = uiTextBlock .Style("word-wrap", "break-word"); } var textTags = MarkdownToHtmlTagConverter.Convert(RendererUtilities.ApplyTextFunctions(textBlock.Text)); uiTextBlock.Children.AddRange(textTags); Action <HtmlTag> setParagraphStyles = null; setParagraphStyles = (HtmlTag htmlTag) => { if (htmlTag.Element?.ToLowerInvariant() == "p") { htmlTag.Style("margin-top", "0px"); htmlTag.Style("margin-bottom", "0px"); htmlTag.Style("width", "100%"); if (setWrapStyleOnParagraph) { htmlTag.Style("text-overflow", "ellipsis"); htmlTag.Style("overflow", "hidden"); } } foreach (var child in htmlTag.Children) { setParagraphStyles(child); } }; setParagraphStyles(uiTextBlock); return(uiTextBlock); }
protected override void RenderRootControl(Grid grid, IControlOutputContext context) { foreach (var column in grid.Columns) { if (!string.IsNullOrWhiteSpace(column.Formatter)) { var formatterScript = RendererUtilities.GenerateWrappedScriptCall(column.Formatter, 2, out string formatterFunctionName); column.Formatter = formatterFunctionName; context.Output.PostContent.AppendHtml($"<script>{formatterScript}</script>"); } } TagBuilder tagBuilder = new TagBuilder("table"); tagBuilder.TagRenderMode = TagRenderMode.Normal; tagBuilder.GenerateId(context.Id, "_"); foreach (var attribute in context.Attributes) { tagBuilder.Attributes.TryAdd(attribute.Name, Convert.ToString(attribute.Value)); } context.Output.Content.SetHtmlContent(tagBuilder); var contractResolver = new BootstrapGridRenderer.GridContractResolver(); var mappingBuilder = contractResolver.AddTypeMapping <Grid>() .MapProperty(x => x.Columns, "columns") .MapProperty(x => x.Height, "height") .MapProperty(x => x.ShowDetails, "detailView") .MapProperty(x => x.ResponseFormatter, "responseHandler") .MapProperty(x => x.DataFieldName, "dataField", false) .MapProperty(x => x.TotalFieldName, "totalField", false) ; contractResolver.AddTypeMapping <GridColumn>() .MapProperty(x => x.Field, "field") .MapProperty(x => x.Title, "title") .MapProperty(x => x.Width, "width") .MapProperty(x => x.Formatter, "formatter") .MapProperty(x => x.Alignment, "align") .MapProperty(x => x.IsHidden, "visible", shouldNegate: true) ; if (grid.DataSource is string) { mappingBuilder.MapProperty(x => x.DataSource, "url"); } else { mappingBuilder.MapProperty(x => x.DataSource, "data", new DataSourceConverter()); } JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings() { ContractResolver = contractResolver }; var json = Utilities.SafeSerialize(grid, jsonSerializerSettings); var postStartupFunction = RendererUtilities.GenerateWrappedScriptCall(grid.OnInitialized, new[] { "grid" }, out string postStartupFunctionName); context.Output.PostContent.AppendHtml( RendererUtilities.GenerateInitializerScript( context, this.OptimizationContextName, $"var grid = $('#{context.Id}').bootstrapTable({json});", string.IsNullOrWhiteSpace(grid.OnInitialized) ? null : $"{postStartupFunctionName}(grid);" ) ); if (!string.IsNullOrWhiteSpace(grid.OnInitialized)) { context.Output.PreContent.AppendHtml($"<script>{postStartupFunction}</script>"); } }
public static View Render(AdaptiveTextBlock textBlock, AdaptiveRenderContext context) { FontColorConfig fontColorConfig; var label = CreateControl(textBlock, context); switch (textBlock.Color) { case AdaptiveTextColor.Default: { fontColorConfig = context.Config.ContainerStyles.Default.ForegroundColors.Default; break; } case AdaptiveTextColor.Dark: { fontColorConfig = context.Config.ContainerStyles.Default.ForegroundColors.Dark; break; } case AdaptiveTextColor.Light: { fontColorConfig = context.Config.ContainerStyles.Default.ForegroundColors.Light; break; } case AdaptiveTextColor.Accent: { fontColorConfig = context.Config.ContainerStyles.Default.ForegroundColors.Accent; break; } case AdaptiveTextColor.Good: { fontColorConfig = context.Config.ContainerStyles.Default.ForegroundColors.Good; break; } case AdaptiveTextColor.Warning: { fontColorConfig = context.Config.ContainerStyles.Default.ForegroundColors.Warning; break; } case AdaptiveTextColor.Attention: { fontColorConfig = context.Config.ContainerStyles.Default.ForegroundColors.Attention; break; } default: { goto case AdaptiveTextColor.Default; } } if (!textBlock.IsSubtle) { label.SetColor(fontColorConfig.Default, context); } else { label.SetColor(fontColorConfig.Subtle, context); } switch (textBlock.Size) { case AdaptiveTextSize.Default: { label.FontSize = (double)context.Config.FontSizes.Default; break; } case AdaptiveTextSize.Small: { label.FontSize = (double)context.Config.FontSizes.Small; break; } case AdaptiveTextSize.Medium: { label.FontSize = (double)context.Config.FontSizes.Medium; break; } case AdaptiveTextSize.Large: { label.FontSize = (double)context.Config.FontSizes.Large; break; } case AdaptiveTextSize.ExtraLarge: { label.FontSize = (double)context.Config.FontSizes.ExtraLarge; break; } default: { goto case AdaptiveTextSize.Default; } } var text = RendererUtilities.ApplyTextFunctions(textBlock.Text); label.FormattedText = text.GetFormattedString(label.FontSize); if (textBlock.MaxLines <= 0) { return(label); } Grid grid = new Grid(); grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); grid.Children.Add(label); return(grid); }
public static FrameworkElement Render(AdaptiveChoiceSetInput input, AdaptiveRenderContext context) { var chosen = input.Value?.Split(',').Select(p => p.Trim()).Where(s => !string.IsNullOrEmpty(s)).ToList() ?? new List <string>(); if (context.Config.SupportsInteractivity) { var uiGrid = new Grid(); uiGrid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); uiGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) }); var uiComboBox = new ComboBox(); uiComboBox.Style = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.ComboBox"); uiComboBox.DataContext = input; var uiChoices = new ListBox(); ScrollViewer.SetHorizontalScrollBarVisibility(uiChoices, ScrollBarVisibility.Disabled); var itemsPanelTemplate = new ItemsPanelTemplate(); var factory = new FrameworkElementFactory(typeof(WrapPanel)); itemsPanelTemplate.VisualTree = factory; uiChoices.ItemsPanel = itemsPanelTemplate; uiChoices.DataContext = input; uiChoices.Style = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput"); foreach (var choice in input.Choices) { if (input.IsMultiSelect == true) { var uiCheckbox = new CheckBox(); uiCheckbox.Content = choice.Title; uiCheckbox.IsChecked = chosen.Contains(choice.Value); uiCheckbox.DataContext = choice; uiCheckbox.Style = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.CheckBox"); uiChoices.Items.Add(uiCheckbox); } else { if (input.Style == AdaptiveChoiceInputStyle.Compact) { var uiComboItem = new ComboBoxItem(); uiComboItem.Style = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.ComboBoxItem"); uiComboItem.Content = choice.Title; uiComboItem.DataContext = choice; uiComboBox.Items.Add(uiComboItem); if (chosen.Contains(choice.Value)) { uiComboBox.SelectedItem = uiComboItem; } } else { var uiRadio = new RadioButton(); uiRadio.Content = choice.Title; uiRadio.IsChecked = chosen.Contains(choice.Value); uiRadio.GroupName = input.Id; uiRadio.DataContext = choice; uiRadio.Style = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.Radio"); uiChoices.Items.Add(uiRadio); } } } context.InputBindings.Add(input.Id, () => { if (input.IsMultiSelect == true) { string values = string.Empty; foreach (var item in uiChoices.Items) { CheckBox checkBox = (CheckBox)item; AdaptiveChoice adaptiveChoice = checkBox.DataContext as AdaptiveChoice; if (checkBox.IsChecked == true) { values += (values == string.Empty ? "" : ",") + adaptiveChoice.Value; } } return(values); } else { if (input.Style == AdaptiveChoiceInputStyle.Compact) { ComboBoxItem item = uiComboBox.SelectedItem as ComboBoxItem; if (item != null) { AdaptiveChoice adaptiveChoice = item.DataContext as AdaptiveChoice; return(adaptiveChoice.Value); } return(null); } else { foreach (var item in uiChoices.Items) { RadioButton radioBox = (RadioButton)item; AdaptiveChoice adaptiveChoice = radioBox.DataContext as AdaptiveChoice; if (radioBox.IsChecked == true) { return(adaptiveChoice.Value); } } return(null); } } }); if (input.Style == AdaptiveChoiceInputStyle.Compact) { Grid.SetRow(uiComboBox, 1); uiGrid.Children.Add(uiComboBox); return(uiGrid); } else { Grid.SetRow(uiChoices, 1); uiGrid.Children.Add(uiChoices); return(uiGrid); } } string choiceText = XamlUtilities.GetFallbackText(input); if (choiceText == null) { List <string> choices = input.Choices.Select(choice => choice.Title).ToList(); if (input.Style == AdaptiveChoiceInputStyle.Compact) { if (input.IsMultiSelect) { choiceText = $"Choices: {RendererUtilities.JoinString(choices, ", ", " and ")}"; } else { choiceText = $"Choices: {RendererUtilities.JoinString(choices, ", ", " or ")}"; } } else // if (adaptiveChoiceSetInput.Style == ChoiceInputStyle.Expanded) { choiceText = $"* {RendererUtilities.JoinString(choices, "\n* ", "\n* ")}"; } } AdaptiveContainer container = AdaptiveTypedElementConverter.CreateElement <AdaptiveContainer>(); container.Spacing = input.Spacing; container.Separator = input.Separator; AdaptiveTextBlock textBlock = AdaptiveTypedElementConverter.CreateElement <AdaptiveTextBlock>(); textBlock.Text = choiceText; textBlock.Wrap = true; container.Items.Add(textBlock); textBlock = AdaptiveTypedElementConverter.CreateElement <AdaptiveTextBlock>(); textBlock.Text = RendererUtilities.JoinString(input.Choices.Where(c => chosen.Contains(c.Value)).Select(c => c.Title).ToList(), ", ", " and "); textBlock.Color = AdaptiveTextColor.Accent; textBlock.Wrap = true; container.Items.Add(textBlock); return(context.Render(container)); }