コード例 #1
0
        public static void AddSeperator(RenderContext context, CardElement element, Grid uiContainer)
        {
            if (element.Spacing == Spacing.None && !element.Separator)
            {
                return;
            }

            var uiSep = new Grid();

            uiSep.Style = context.GetStyle($"Adaptive.Separator");
            int spacing = context.Config.GetSpacing(element.Spacing);

            SeparatorConfig sepStyle = context.Config.Separator;

            uiSep.Margin = new Thickness(0, (spacing - sepStyle.LineThickness) / 2, 0, (spacing - sepStyle.LineThickness) / 2);
            uiSep.SetHeight(sepStyle.LineThickness);
            if (!string.IsNullOrWhiteSpace(sepStyle.LineColor))
            {
                uiSep.SetBackgroundColor(sepStyle.LineColor, context);
            }
            uiContainer.RowDefinitions.Add(new RowDefinition()
            {
                Height = GridLength.Auto
            });
            Grid.SetRow(uiSep, uiContainer.RowDefinitions.Count - 1);
            uiContainer.Children.Add(uiSep);
        }
コード例 #2
0
        protected static void AddSeparator(HtmlTag uiContainer, CardElement cardElement, RenderContext context)
        {
            if (!cardElement.Separator && cardElement.Spacing == Spacing.None)
            {
                return;
            }

            int spacing = context.Config.GetSpacing(cardElement.Spacing);

            if (cardElement.Separator)
            {
                SeparatorConfig sep   = context.Config.Separator;
                var             uiSep = new DivTag()
                                        .AddClass("ac-separator")
                                        .Style("padding-top", $"{spacing}px")
                                        .Style("margin-top", $"{spacing}px")
                                        .Style("border-top-color", $"{context.GetRGBColor(sep.LineColor)}")
                                        .Style("border-top-width", $"{sep.LineThickness}px")
                                        .Style("border-top-style", "solid")
                ;
                uiContainer.Children.Add(uiSep);
            }
            else
            {
                var uiSep = new DivTag()
                            .AddClass("ac-separator")
                            .Style("height", $"{spacing}px");
                uiContainer.Children.Add(uiSep);
            }
        }
コード例 #3
0
        protected static HtmlTag ColumnSetRender(ColumnSet columnSet, RenderContext context)
        {
            var uiColumnSet = new DivTag()
                              .AddClass($"ac-{columnSet.Type.Replace(".", "").ToLower()}")
                              .Style("overflow", "hidden")
                              .Style("display", "flex");

            if (context.Config.SupportsInteractivity && columnSet.SelectAction != null)
            {
                uiColumnSet.AddClass("ac-tap");
            }

            var max = Math.Max(1.0, columnSet.Columns.Select(col =>
            {
                if (col.Width != null && double.TryParse(col.Width, out double widthVal))
                {
                    return(widthVal);
                }
#pragma warning disable CS0618 // Type or member is obsolete
                if (double.TryParse(col.Size ?? "0", out double val))
#pragma warning restore CS0618 // Type or member is obsolete
                {
                    return(val);
                }
                return(0);
            }).Sum());

            foreach (var column in columnSet.Columns)
            {
                var uiColumn = context.Render(column);

                // Add horizontal Seperator
                if (uiColumnSet.Children.Any() && (column.Separator || column.Spacing != Spacing.None))
                {
                    SeparatorConfig sep = context.Config.Separator;

                    int spacing       = context.Config.GetSpacing(column.Spacing);
                    int lineThickness = column.Separator ? sep.LineThickness : 0;

                    if (sep != null)
                    {
                        uiColumnSet.Children.Add(new DivTag()
                                                 .AddClass($"ac-columnseparator")
                                                 .Style("flex", "0 0 auto")
                                                 .Style("padding-left", $"{spacing}px")
                                                 .Style("margin-left", $"{spacing}px")
                                                 .Style("border-left-color", $"{context.GetRGBColor(sep.LineColor)}")
                                                 .Style("border-left-width", $"{lineThickness}px")
                                                 .Style("border-left-style", $"solid"));
                    }
                }

                // do some sizing magic
                var width = column.Width?.ToLower();
                if (string.IsNullOrEmpty(width))
#pragma warning disable CS0618 // Type or member is obsolete
                {
                    width = column.Size?.ToLower();
                }
#pragma warning restore CS0618 // Type or member is obsolete
                if (width == null || width == ColumnWidth.Stretch.ToLower())
                {
                    uiColumn = uiColumn.Style("flex", "1 1 auto");
                }
                else if (width == ColumnWidth.Auto.ToLower())
                {
                    uiColumn = uiColumn.Style("flex", "0 1 auto");
                }
                else
                {
                    double val;
                    if (double.TryParse(width, out val))
                    {
                        var percent = Convert.ToInt32(100 * (val / max));
                        uiColumn = uiColumn.Style("flex", $"1 1 {percent}%");
                    }
                    else
                    {
                        uiColumn = uiColumn.Style("flex", "0 0 auto");
                    }
                }

                uiColumnSet.Children.Add(uiColumn);
            }

            return(uiColumnSet);
        }