Пример #1
0
        EvasObject GetContent(object data, string part)
        {
            ShellSection section = data as ShellSection;

            var box = new EBox(Forms.NativeParent);

            box.Show();

            EImage icon = null;

            if (section.Icon != null)
            {
                icon = new EImage(Forms.NativeParent);
                icon.Show();
                box.PackEnd(icon);
                _ = icon.LoadFromImageSourceAsync(section.Icon);
            }

            var title = new Native.Label(Forms.NativeParent)
            {
                Text     = section.Title,
                FontSize = Forms.ConvertToEflFontPoint(14),
                HorizontalTextAlignment = Native.TextAlignment.Start,
                VerticalTextAlignment   = Native.TextAlignment.Center,
            };

            title.Show();
            box.PackEnd(title);
            int iconPadding = Forms.ConvertToScaledPixel(this.GetIconPadding());
            int iconSize    = Forms.ConvertToScaledPixel(this.GetIconSize());
            int cellHeight  = iconPadding * 2 + iconSize;

            box.SetLayoutCallback(() =>
            {
                var bound      = box.Geometry;
                int leftMargin = iconPadding;

                if (icon != null)
                {
                    var iconBound    = bound;
                    iconBound.X     += iconPadding;
                    iconBound.Y     += iconPadding;
                    iconBound.Width  = iconSize;
                    iconBound.Height = iconSize;
                    icon.Geometry    = iconBound;
                    leftMargin       = (2 * iconPadding + iconSize);
                }

                bound.X       += leftMargin;
                bound.Width   -= leftMargin;
                title.Geometry = bound;
            });

            box.MinimumHeight = cellHeight;
            return(box);
        }
Пример #2
0
        StringBuilder PrepareFormattingString(StringBuilder _formattingString)
        {
            if (!ForegroundColor.IsDefault)
            {
                _formattingString.AppendFormat("color={0} ", ForegroundColor.ToHex());
            }

            if (!BackgroundColor.IsDefault)
            {
                _formattingString.AppendFormat("backing_color={0} backing=on ", BackgroundColor.ToHex());
            }

            if (!string.IsNullOrEmpty(FontFamily))
            {
                _formattingString.AppendFormat("font={0} ", FontFamily);
            }

            if (FontSize != -1)
            {
                _formattingString.AppendFormat("font_size={0} ", Forms.ConvertToEflFontPoint(FontSize));
            }

            if ((FontAttributes & FontAttributes.Bold) != 0)
            {
                _formattingString.Append("font_weight=Bold ");
            }
            else
            {
                // FontWeight is only available in case of FontAttributes.Bold is not used.
                if (FontWeight != Specific.FontWeight.None)
                {
                    _formattingString.AppendFormat("font_weight={0} ", FontWeight);
                }
            }

            if ((FontAttributes & FontAttributes.Italic) != 0)
            {
                _formattingString.Append("font_style=italic ");
            }

            if (Underline)
            {
                _formattingString.AppendFormat("underline=on underline_color={0} ",
                                               ForegroundColor.IsDefault ? ThemeConstants.Span.ColorClass.DefaultUnderLineColor.ToHex() : ForegroundColor.ToHex());
            }

            if (Strikethrough)
            {
                _formattingString.AppendFormat("strikethrough=on strikethrough_color={0} ",
                                               ForegroundColor.IsDefault ? ThemeConstants.Span.ColorClass.DefaultUnderLineColor.ToHex() : ForegroundColor.ToHex());
            }

            switch (HorizontalTextAlignment)
            {
            case TextAlignment.Auto:
                _formattingString.Append("align=auto ");
                break;

            case TextAlignment.Start:
                _formattingString.Append("align=left ");
                break;

            case TextAlignment.End:
                _formattingString.Append("align=right ");
                break;

            case TextAlignment.Center:
                _formattingString.Append("align=center ");
                break;

            case TextAlignment.None:
                break;
            }

            if (LineHeight != -1.0d)
            {
                _formattingString.Append($"linerelsize={(int)(LineHeight * 100)}%");
            }

            switch (LineBreakMode)
            {
            case LineBreakMode.HeadTruncation:
                _formattingString.Append("ellipsis=0.0");
                break;

            case LineBreakMode.MiddleTruncation:
                _formattingString.Append("ellipsis=0.5");
                break;

            case LineBreakMode.TailTruncation:
                _formattingString.Append("ellipsis=1.0");
                break;

            case LineBreakMode.None:
                break;
            }

            return(_formattingString);
        }