示例#1
0
 internal static double DecipheredFontSize(this Forms9Patch.Label label)
 {
     if (label == null)
     {
         return(DefaultFontSize());
     }
     return(ClipFontSize(label.FontSize, DecipheredMinFontSize(label)));
 }
示例#2
0
 internal static double DecipheredMinFontSize(this Forms9Patch.Label label)
 {
     if (label == null)
         return 4;
     if (label.MinFontSize <= 0)
         return 4;
     return label.MinFontSize;
 }
示例#3
0
        public HtmlLink()
        {
            var label = new Forms9Patch.Label
            {
                HtmlText = "Contact us on <a id=\"phone\" href=\"tel:+353015546889\">015546889</a> or <a id=\"email\" href=\"mailto:[email protected]\">[email protected]</a>",
                HorizontalTextAlignment = TextAlignment.Center
            };
            var label2 = new Forms9Patch.Label
            {
                HtmlText = @"08 Apr 2019 15:45:50:870 <b>HTML</b> <big>really big text</big><a href='http://somesite.gov.ua' target='_blank' title='Official site'>Official site</a>",
                HorizontalTextAlignment = TextAlignment.Center
            };

            label.ActionTagTapped += (object sender, Forms9Patch.ActionTagEventArgs e) =>
            {
                var id   = e.Id;
                var href = e.Href;
                var uri  = new Uri(e.Href);
                Device.OpenUri(uri);
            };
            label2.ActionTagTapped += (sender, e) =>
            {
                Forms9Patch.Toast.Create("Action", e.Href);
            };
            var stack = new StackLayout
            {
                VerticalOptions = LayoutOptions.Center,
                Children        =
                {
                    new Forms9Patch.Label("Forms9Patch.Label.HtmlText &lt;a&gt; example.")
                    {
                        HorizontalTextAlignment = TextAlignment.Center
                    },
                    new BoxView {
                        BackgroundColor = Color.Black, HeightRequest = 1
                    },
                    label,
                    new BoxView {
                        BackgroundColor = Color.Black, HeightRequest = 1
                    },
                    label2,
                    new BoxView {
                        BackgroundColor = Color.Black, HeightRequest = 1
                    },
                }
            };

            if (Device.RuntimePlatform == Device.iOS)
            {
                stack.Children.Add(new Forms9Patch.Label("<b><i>NOTE:</i></b> Does not work in iOS Simulator.")
                {
                    HorizontalTextAlignment = TextAlignment.Center
                });
            }

            Content = stack;
        }
示例#4
0
 internal static double DecipheredMinFontSize(this Forms9Patch.Label label)
 {
     if (label == null)
     {
         return(4);
     }
     if (label.MinFontSize <= 0)
     {
         return(4);
     }
     return(label.MinFontSize);
 }
示例#5
0
        Forms9Patch.AbsoluteLayout GenerateAbsoluteLayout()
        {
            var absoluteLayout        = new Forms9Patch.AbsoluteLayout();
            var absoluteLayoutContent = new Forms9Patch.Label("CONTENT")
            {
                TextColor = Color.Orange,
                HorizontalTextAlignment = TextAlignment.Center,
                VerticalTextAlignment   = TextAlignment.Center,
                FontAttributes          = FontAttributes.Bold
            };

            AbsoluteLayout.SetLayoutBounds(absoluteLayoutContent, new Rectangle(0.5, 0.5, 1.0, 1.0));
            AbsoluteLayout.SetLayoutFlags(absoluteLayoutContent, AbsoluteLayoutFlags.All);
            absoluteLayout.Children.Add(absoluteLayoutContent);
            return(absoluteLayout);
        }
示例#6
0
        public static void UpdateLineBreakMode(this TextBlock textBlock, Forms9Patch.Label label)
        {
            //P42.Utils.DebugExtensions.Message(Element,"ENTER");
            //_perfectSizeValid = false;

            if (textBlock != null && label != null)
            {
                switch (label.LineBreakMode)
                {
                case Xamarin.Forms.LineBreakMode.NoWrap:
                    textBlock.TextTrimming = TextTrimming.None;
                    textBlock.TextWrapping = TextWrapping.NoWrap;
                    break;

                case Xamarin.Forms.LineBreakMode.WordWrap:
                    textBlock.TextTrimming = TextTrimming.None;
                    textBlock.TextWrapping = TextWrapping.WrapWholeWords;
                    break;

                case Xamarin.Forms.LineBreakMode.CharacterWrap:
                    textBlock.TextTrimming = TextTrimming.None;
                    textBlock.TextWrapping = TextWrapping.Wrap;
                    break;

                case Xamarin.Forms.LineBreakMode.HeadTruncation:
                    // TODO: This truncates at the end.
                    textBlock.TextTrimming = TextTrimming.WordEllipsis;
                    textBlock.TextWrapping = TextWrapping.WrapWholeWords;
                    break;

                case Xamarin.Forms.LineBreakMode.TailTruncation:
                    textBlock.TextTrimming = TextTrimming.CharacterEllipsis;
                    textBlock.TextWrapping = TextWrapping.WrapWholeWords;
                    break;

                case Xamarin.Forms.LineBreakMode.MiddleTruncation:
                    // TODO: This truncates at the end.
                    textBlock.TextTrimming = TextTrimming.WordEllipsis;
                    textBlock.TextWrapping = TextWrapping.WrapWholeWords;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            //P42.Utils.DebugExtensions.Message(Element,"EXIT");
        }
示例#7
0
        Forms9Patch.RelativeLayout GenerateRelativeLayout()
        {
            var relativeLayout = new Forms9Patch.RelativeLayout();
            var cView          = new Forms9Patch.Label("C")
            {
                TextColor = Color.Orange,
                HorizontalTextAlignment = TextAlignment.Center,
                VerticalTextAlignment   = TextAlignment.Center,
                FontAttributes          = FontAttributes.Bold
            };
            var lView = new Forms9Patch.Label("L")
            {
                TextColor = Color.Orange,
                HorizontalTextAlignment = TextAlignment.Center,
                VerticalTextAlignment   = TextAlignment.Center,
                FontAttributes          = FontAttributes.Bold
            };
            var rView = new Forms9Patch.Label("R")
            {
                TextColor = Color.Orange,
                HorizontalTextAlignment = TextAlignment.Center,
                VerticalTextAlignment   = TextAlignment.Center,
                FontAttributes          = FontAttributes.Bold
            };
            var tView = new Forms9Patch.Label("T")
            {
                TextColor = Color.Orange,
                HorizontalTextAlignment = TextAlignment.Center,
                VerticalTextAlignment   = TextAlignment.Center,
                FontAttributes          = FontAttributes.Bold
            };
            var bView = new Forms9Patch.Label("T")
            {
                TextColor = Color.Orange,
                HorizontalTextAlignment = TextAlignment.Center,
                VerticalTextAlignment   = TextAlignment.Center,
                FontAttributes          = FontAttributes.Bold
            };

            relativeLayout.Children.Add(cView, Constraint.RelativeToParent((parent) => parent.Width / 2), Constraint.RelativeToParent((parent) => parent.Height / 2));
            relativeLayout.Children.Add(tView, Constraint.RelativeToParent((parent) => parent.Width / 2), Constraint.RelativeToView(cView, (parent, sibling) => sibling.Y - parent.Height / 4));
            relativeLayout.Children.Add(bView, Constraint.RelativeToParent((parent) => parent.Width / 2), Constraint.RelativeToView(cView, (parent, sibling) => sibling.Y + parent.Height / 4));
            relativeLayout.Children.Add(lView, Constraint.RelativeToView(cView, (parent, sibling) => sibling.X - parent.Width / 4), Constraint.RelativeToParent((parent) => parent.Height / 2));
            relativeLayout.Children.Add(rView, Constraint.RelativeToView(cView, (parent, sibling) => sibling.X + parent.Width / 4), Constraint.RelativeToParent((parent) => parent.Height / 2));
            return(relativeLayout);
        }
示例#8
0
        public HtmlLink()
        {
            var label = new Forms9Patch.Label
            {
                HtmlText = "Contact us on <a id=\"phone\" href=\"tel:+353015546889\">015546889</a> or <a id=\"email\" href=\"mailto:[email protected]\">[email protected]</a>",
                HorizontalTextAlignment = TextAlignment.Center
            };

            label.ActionTagTapped += (object sender, Forms9Patch.ActionTagEventArgs e) =>
            {
                var id   = e.Id;
                var href = e.Href;
                var uri  = new Uri(e.Href);
                Device.OpenUri(uri);
            };
            var stack = new StackLayout
            {
                VerticalOptions = LayoutOptions.Center,
                Children        =
                {
                    new Forms9Patch.Label("Forms9Patch.Label.HtmlText &lt;a&gt; example.")
                    {
                        HorizontalTextAlignment = TextAlignment.Center
                    },
                    new BoxView {
                        BackgroundColor = Color.Black, HeightRequest = 1
                    },
                    label,
                    new BoxView {
                        BackgroundColor = Color.Black, HeightRequest = 1
                    },
                }
            };

            if (Device.RuntimePlatform == Device.iOS)
            {
                stack.Children.Add(new Forms9Patch.Label("<b><i>NOTE:</i></b> Does not work in iOS Simulator.")
                {
                    HorizontalTextAlignment = TextAlignment.Center
                });
            }

            Content = stack;
        }
示例#9
0
        public LabelLink()
        {
            _label = new Forms9Patch.Label
            {   
            };

            _label.ActionTagTapped += (object sender, Forms9Patch.ActionTagEventArgs e) =>
            {
                var id = e.Id;
                var href = e.Href;
                var uri = new Uri(e.Href);

                try
                {
                    string prefix = "tel:";
                    if (e.Href.StartsWith(prefix))
                    {
                        PhoneDialer.Open(e.Href.Substring(prefix.Length));
                    }
                }
                catch (ArgumentNullException)
                {   
                }
                catch (FeatureNotSupportedException)
                {
                }
                catch (Exception)
                {
                }
            };

            Content = new StackLayout
            {
                VerticalOptions = LayoutOptions.Center,
                Children = {
                    _label
                }
            };

            PropertyChanged += OnLabelPropertyChanged;
        }
示例#10
0
        private void Handle_ChampionClick(Object se, EventArgs ea, string champName)
        {
            int i = 0;

            //System.Diagnostics.Debug.WriteLine("First attempt at finding the index limit");
            while (!champions[i, 0].Equals(champName) && i < Variables.champCount)
            {
                i++;
            }

            /* TODO: Im gonna keep adding stack layouts to the scrollview so you can have multiple champions,
             * this will be a team builder of sorts,
             * TODO: Create a standard StackLayout that will hold the Champion Icon, Name, Recommended items, ultIcon, Ult Description,
             * and symbols for their origin/class
             */
            StackLayout championHolder = new StackLayout()
            {
                Orientation     = StackOrientation.Vertical,
                BackgroundColor = Color.FromRgba(0.5, 0.5, 0.5, 0.5)
            };
            StackLayout infoHolder1 = new StackLayout()
            {
                Orientation = StackOrientation.Horizontal,
                Margin      = 10,
                Padding     = 5
            };
            String tempName = champName;

            tempName.Replace(" ", "");
            tempName.Replace("'", "");
            ImageButton champIcon = new ImageButton()
            {
                Source          = ImageSource.FromUri(new Uri("https://d1v0ze4r2jabid.cloudfront.net/characters/" + tempName + ".png")),
                WidthRequest    = 100,
                HeightRequest   = 100,
                BackgroundColor = Color.Transparent
            };

            champIcon.Clicked += (s, e) => Handle_InformationClick(s, e, champName, champions[i, 2], champions[i, 3], champions[i, 4], champions[i, 5], champions[i, 6]);
            infoHolder1.Children.Add(champIcon);

            StackLayout champNameType = new StackLayout()
            {
                Orientation = StackOrientation.Vertical,
                Margin      = 10,
                Padding     = 5
            };

            Forms9Patch.Label tempLabel = new Forms9Patch.Label()
            {
                Text           = champName,
                FontAttributes = FontAttributes.Bold,
                FontSize       = 28,
                MinFontSize    = 10,
                TextColor      = Color.White
            };
            Label championName = new Label()
            {
                Text           = champName,
                FontAttributes = FontAttributes.Bold,
                FontSize       = 28,
                TextColor      = Color.White
            };

            /*
             *  This is where I am testing a new NuGet library for a label text resizer and will need to modify if this is not done correctly :)
             *  If done correctly I can put Miss Forturne and Zed on the same amount of lines
             */
            tempLabel.Lines   = 1;
            tempLabel.AutoFit = Forms9Patch.AutoFit.Width;

            champNameType.Children.Add(tempLabel);

            StackLayout typeHolder = new StackLayout()
            {
                Orientation = StackOrientation.Horizontal,
                Margin      = 10,
                Padding     = 5
            };
            Image champType1 = new Image()
            {
                Source        = ImageSource.FromUri(new Uri("https://cdn.leagueofgraphs.com/img/tft/origins/" + champions[i, 2] + ".png")),
                HeightRequest = 33,
                WidthRequest  = 33
            };
            Image champType2;

            if (champions[i, 3].Equals("pirate"))
            {
                champType2 = new Image()
                {
                    Source        = ImageSource.FromUri(new Uri("https://cdn.leagueofgraphs.com/img/tft/origins/" + champions[i, 3] + ".png")),
                    HeightRequest = 33,
                    WidthRequest  = 33
                };
            }
            else
            {
                champType2 = new Image()
                {
                    Source        = ImageSource.FromUri(new Uri("https://cdn.leagueofgraphs.com/img/tft/classes/" + champions[i, 3] + ".png")),
                    HeightRequest = 33,
                    WidthRequest  = 33
                };
            }
            Image champType3 = new Image()
            {
                HeightRequest = 33,
                WidthRequest  = 33
            };

            //itemContainer.Children.Clear();

            if (champions[i, 4].Equals("None"))
            {
                champType3.Source = "";
            }
            else if (champions[i, 4].Equals("blademaster") || champions[i, 4].Equals("assassin") || champions[i, 4].Equals("brawler") || champions[i, 4].Equals("elementalist") ||
                     champions[i, 4].Equals("guardian") || champions[i, 4].Equals("gunslinger") || champions[i, 4].Equals("Knight") || champions[i, 4].Equals("ranger") ||
                     champions[i, 4].Equals("shapeshifter") || champions[i, 4].Equals("sorcerer"))
            {
                champType3.Source = ImageSource.FromUri(new Uri("https://cdn.leagueofgraphs.com/img/tft/classes/" + champions[i, 4] + ".png"));
            }
            else
            {
                champType3.Source = ImageSource.FromUri(new Uri("https://cdn.leagueofgraphs.com/img/tft/origins/" + champions[i, 4] + ".png"));
            }

            typeHolder.Children.Add(champType1);
            typeHolder.Children.Add(champType2);
            typeHolder.Children.Add(champType3);
            champNameType.Children.Add(typeHolder);

            ImageButton clearButton = new ImageButton()
            {
                Source          = "https://img.icons8.com/plasticine/2x/close-window.png",
                WidthRequest    = 30,
                HeightRequest   = 35,
                VerticalOptions = LayoutOptions.Start,
                BackgroundColor = Color.Transparent,
            };

            clearButton.Clicked += (s, e) => Handle_ClearClick(s, e, championHolder, champName);

            infoHolder1.Children.Add(champNameType);
            infoHolder1.Children.Add(clearButton);

            /*
             * StackLayout infoHolder2 = new StackLayout()
             * {
             *  Orientation = StackOrientation.Horizontal,
             *  Margin = 10,
             *  Padding = 5
             * };
             * Image abilIcon = new Image()
             * {
             *  Source = ImageSource.FromUri(new Uri("https://d1v0ze4r2jabid.cloudfront.net/abilities/" + champions[i, 5] + ".png")),
             *  WidthRequest = 50,
             *  HeightRequest = 50
             * };
             * Label abilInfo = new Label()
             * {
             *  FontSize = 16,
             *  TextColor = Color.White,
             *  Text = champions[i,6]
             * };
             * infoHolder2.Children.Add(abilIcon);
             * infoHolder2.Children.Add(abilInfo);
             */
            championHolder.Children.Add(infoHolder1);
            //championHolder.Children.Add(infoHolder2);

            compHolder.Children.Add(championHolder);
            //abilityIcon.Source = ImageSource.FromUri(new Uri("https://d1v0ze4r2jabid.cloudfront.net/abilities/" + champions[i,5] +".png"));

            /*Add the Suggested items here*/
        }
示例#11
0
 internal static double ClipFontSize(double size, Forms9Patch.Label label)
 => ClipFontSize(size, label.MinFontSize, label.FontSize);
        internal static void SetAndFormatText(this TextBlock winTextBlock, Forms9Patch.Label f9pLabel, double altFontSize = -1)
        {
            var label     = f9pLabel;
            var textBlock = winTextBlock;

            if (f9pLabel == null || textBlock == null)
            {
                return;
            }

            textBlock.Text = "";
            textBlock.Inlines.Clear();
            textBlock.FontSize = (altFontSize > 0 ? altFontSize : label.DecipheredFontSize());
            //textBlock.LineHeight = FontExtensions.LineHeightForFontSize(textBlock.FontSize);
            textBlock.LineStackingStrategy = Windows.UI.Xaml.LineStackingStrategy.BaselineToBaseline;
            textBlock.FontFamily           = FontService.GetWinFontFamily(label.FontFamily);

            if (label.Text != null)
            {
                textBlock.Text = label.Text;
                return;
            }
            if (label.FormattedText != null)
            {
                var formattedText = label.FormattedText;
                for (var i = 0; i < formattedText.Spans.Count; i++)
                {
                    textBlock.Inlines.Add(formattedText.Spans[i].ToRun());
                }
                return;
            }

            var text = label.F9PFormattedString?.Text;

            if (label.F9PFormattedString is HTMLMarkupString htmlMarkupString)
            {
                text = htmlMarkupString.UnmarkedText;
            }

            if (string.IsNullOrWhiteSpace(text) || text == label.F9PFormattedString?.Text)
            {
                // there isn't any markup!
                textBlock.Text = text ?? "";
                return;
            }

            #region Layout font-spans (MetaFonts)
            var metaFonts    = new List <MetaFont>();
            var baseMetaFont = new MetaFont(
                label.FontFamily,
                textBlock.FontSize,                                               //(altFontSize > 0 ? altFontSize : label.DecipheredFontSize()), //(label.FontSize < 0 ? (double)Windows.UI.Xaml.Application.Current.Resources["ControlContentThemeFontSize"] : label.FontSize)), //label.FontSize,
                (label.FontAttributes & Xamarin.Forms.FontAttributes.Bold) > 0,   //textBlock.FontWeight.Weight >= Windows.UI.Text.FontWeights.Bold.Weight,
                (label.FontAttributes & Xamarin.Forms.FontAttributes.Italic) > 0, // (textBlock.FontStyle & Windows.UI.Text.FontStyle.Italic) > 0,
                textColor: label.TextColor                                        //,
                                                                                  //backgroundColor: label.BackgroundColor
                );

            var MathMetaFont = new MetaFont(baseMetaFont)
            {
                Family = "STIXGeneral" //FontService.ReconcileFontFamily("Forms9Patch.Resources.Fonts.STIXGeneral.otf", P42.Utils.ReflectionExtensions.GetAssembly(typeof(Forms9Patch.Label)))
            };

            for (int i = 0; i < text.Length; i++)
            {
                if (i + 1 < text.Length && text[i] == '\ud835' && text[i + 1] >= '\udc00' && text[i + 1] <= '\udeff')
                {
                    metaFonts.Add(new MetaFont(MathMetaFont));
                    metaFonts.Add(new MetaFont(MathMetaFont));  // there are two because we're using a double byte unicode character
                    i++;
                }
                else
                {
                    metaFonts.Add(new MetaFont(baseMetaFont));
                }
            }
            #endregion


            #region Apply non-font Spans
            foreach (var span in label.F9PFormattedString._spans)
            {
                int spanStart = span.Start;
                int spanEnd   = span.End;

                //spanEnd++;
                if (spanEnd >= text.Length)
                {
                    spanEnd = text.Length - 1;
                }

                for (int i = spanStart; i <= spanEnd; i++)
                {
                    switch (span.Key)
                    {
                    case FontFamilySpan.SpanKey:     // TextElement.FontFamily
                        var fontFamily = ((FontFamilySpan)span).FontFamilyName;
                        metaFonts[i].Family = fontFamily;
                        break;

                    case FontSizeSpan.SpanKey:      // TextElement.FontSize
                        float size = ((FontSizeSpan)span).Size;
                        metaFonts[i].Size = (size < 0 ? metaFonts[i].Size * (-size) : size);
                        break;

                    case BoldSpan.SpanKey:     // Bold span // TextElement.FontWeight (Thin, ExtraLight, Light, SemiLight, Normal, Medium, SemiBold, Bold, ExtraBold, Black, ExtraBlack)
                        metaFonts[i].Bold = true;
                        break;

                    case ItalicsSpan.SpanKey:     // Italic span // TextElement.FontStyle (Normal, Italic, Oblique)
                        metaFonts[i].Italic = true;
                        break;

                    case FontColorSpan.SpanKey:     // TextElement.Foreground
                        metaFonts[i].TextColor = ((FontColorSpan)span).Color;
                        break;

                    case UnderlineSpan.SpanKey:     // Underline span  // TextElement.TextDecorations = None, Strikethought, Underline
                        metaFonts[i].Underline = true;
                        break;

                    case StrikethroughSpan.SpanKey:     // TextElement.TextDecorations = None, Strikethought, Underline
                        metaFonts[i].Strikethrough = true;
                        break;

                    case SuperscriptSpan.SpanKey:     // Run with Typographic.Variants=FontVariants.Superscript while using Cambria
                        metaFonts[i].Baseline = FontBaseline.Superscript;
                        break;

                    case SubscriptSpan.SpanKey:     // Run with Typographic.Varients=FontVariants.Subscript while using Cambria
                        metaFonts[i].Baseline = FontBaseline.Subscript;
                        break;

                    case NumeratorSpan.SpanKey:     // no UWP solution - need to use SuperScript
                        metaFonts[i].Baseline = FontBaseline.Numerator;
                        break;

                    case DenominatorSpan.SpanKey:     // no UWP solution - need to use Subscript
                        metaFonts[i].Baseline = FontBaseline.Denominator;
                        break;

                    case ActionSpan.SpanKey:      // Hyperlink span ??
                        metaFonts[i].Action = new MetaFontAction((ActionSpan)span);
                        break;

                    case BackgroundColorSpan.SpanKey:     // if Win10 fall creator's update, there is a solution: create TextHighlighter, set its BackgroundColor and add the Range (Start/End) to it's Ranges, and add to TextBlock.Highlighters
                        metaFonts[i].BackgroundColor = ((BackgroundColorSpan)span).Color;
                        break;
                    }
                }
            }
            #endregion


            #region Convert MetaFonts to InLines
            var inlineColection = new List <Inline>();

            // run through MetaFonts to see if we need to set new Font attributes
            var lastMetaFont = baseMetaFont;
            int startIndex   = 0;
            for (int i = 0; i < metaFonts.Count; i++)
            {
                var metaFont = metaFonts[i];
                if (lastMetaFont != metaFont)
                {
                    // we are at the start of a new span
                    if (i > 0) // && lastMetaFont != baseMetaFont)
                    {
                        AddInline(textBlock, label, lastMetaFont, text, startIndex, i - startIndex);
                    }
                    lastMetaFont = metaFont;
                    startIndex   = i;
                }
            }
            AddInline(textBlock, label, lastMetaFont, text, startIndex, text.Length - startIndex);
            #endregion
        }
        static void AddInline(TextBlock textBlock, Forms9Patch.Label label, MetaFont metaFont, string text, int startIndex, int length)
        {
            var run = new Run();

            run.Text       = text.Substring(startIndex, length);
            run.FontSize   = metaFont.Size;
            run.FontWeight = metaFont.Bold ? Windows.UI.Text.FontWeights.Bold : Windows.UI.Text.FontWeights.Normal;
            run.FontStyle  = metaFont.Italic ? Windows.UI.Text.FontStyle.Italic : Windows.UI.Text.FontStyle.Normal;


            if (TextDecorationsPresent && metaFont.Strikethrough)
            {
                ApplyTextDecorations(run, Decoration.Strikethrough);
            }

            switch (metaFont.Baseline)
            {
            case FontBaseline.Numerator:
                run.FontFamily = new Windows.UI.Xaml.Media.FontFamily("Cambria");
                Typography.SetVariants(run, Windows.UI.Xaml.FontVariants.Superscript);
                break;

            case FontBaseline.Superscript:
                run.FontFamily = new Windows.UI.Xaml.Media.FontFamily("Cambria");
                Typography.SetVariants(run, Windows.UI.Xaml.FontVariants.Superscript);
                break;

            case FontBaseline.Denominator:
                run.FontFamily = new Windows.UI.Xaml.Media.FontFamily("Cambria");
                Typography.SetVariants(run, Windows.UI.Xaml.FontVariants.Subscript);
                break;

            case FontBaseline.Subscript:
                run.FontFamily = new Windows.UI.Xaml.Media.FontFamily("Cambria");
                Typography.SetVariants(run, Windows.UI.Xaml.FontVariants.Subscript);
                break;

            default:
                if (metaFont.Family != null)
                {
                    run.FontFamily = new Windows.UI.Xaml.Media.FontFamily(FontService.ReconcileFontFamily(metaFont.Family));
                }
                break;
            }

            if (!metaFont.BackgroundColor.IsDefaultOrTransparent())
            {
                try
                {
                    textBlock.ApplyBackgroundColor(metaFont.BackgroundColor, startIndex, length);
                }
                catch (Exception)
                {
                    //throw new Exception("It appears that this Xamarin.Forms.UWP app was built with a Windows TargetVersion < 10.0.16299.0 (Windows 10 Fall Creators Update).  10.0.16299.0 is needed to support Forms9Patch.Label.HtmlText background color attributes.", e);
                }
            }

            if (metaFont.IsActionEmpty())
            {
                run.Foreground = new Windows.UI.Xaml.Media.SolidColorBrush(metaFont.TextColor.ToWindowsColor());
                if (TextDecorationsPresent && metaFont.Underline)
                {
                    ApplyTextDecorations(run, Decoration.Underline);
                }
                textBlock.Inlines.Add(run);
            }
            else
            {
                run.Foreground = new Windows.UI.Xaml.Media.SolidColorBrush(Xamarin.Forms.Color.Blue.ToWindowsColor());
                if (TextDecorationsPresent)
                {
                    ApplyTextDecorations(run, Decoration.Underline);
                }
                var hyperlink = new Hyperlink();
                hyperlink.Inlines.Add(run);
                hyperlink.Click += (Hyperlink sender, HyperlinkClickEventArgs args) => label.Tap(metaFont.Action.Id, metaFont.Action.Href);
                textBlock.Inlines.Add(hyperlink);
            }
        }
示例#14
0
        public LabelAutoFitPage()
        {
            LinesSlider.Effects.Add(new Forms9Patch.SliderStepSizeEffect(1.0));

            BackgroundColor = Color.LightGray;
            Padding         = 10;

            #region Editor
            var editor = new Editor
            {
                Text            = text1,
                TextColor       = Color.Black,
                BackgroundColor = Color.White,
                HeightRequest   = 130,
                FontSize        = 15,
            };

            #endregion


            #region Xamarin Forms label
            var effect = Effect.Resolve("Forms9Patch.EmbeddedResourceFontEffect");
            //xfLabel.Effects.Add(effect);
            #endregion


            #region Forms9Patch Label
            var listener = FormsGestures.Listener.For(f9pLabel);
            listener.Tapped += (object sender, FormsGestures.TapEventArgs e) =>
            {
                System.Diagnostics.Debug.WriteLine("Point=[" + e.ElementTouches[0] + "] Index=[" + f9pLabel.IndexAtPoint(e.ElementTouches[0]) + "]");
            };
            #endregion


            #region Mode
            var modeSwitch = new Switch
            {
                IsToggled         = false,
                HorizontalOptions = LayoutOptions.End,
            };
            modeSwitch.Toggled += (sender, e) =>
            {
                if (modeSwitch.IsToggled)
                {
                    f9pLabel.HtmlText = editor.Text;
                }
                else
                {
                    f9pLabel.Text = editor.Text;
                }
            };
            #endregion


            #region Sync text between Editor and Labels

            editor.TextChanged += (sender, e) =>
            {
                xfLabel.Text = editor.Text;
                if (modeSwitch.IsToggled)
                {
                    f9pLabel.HtmlText = editor.Text;
                }
                else
                {
                    f9pLabel.Text = editor.Text;
                }
            };
            #endregion


            #region Frames for Labels
            var frameForF9P = new Frame
            {
                HeightRequest = 100,
                //WidthRequest = 200,
                Padding      = 0,
                Content      = f9pLabel,
                CornerRadius = 0
            };

            var frameForXF = new Frame
            {
                HeightRequest = 100,
                //WidthRequest = 200,
                Padding      = 0,
                Content      = xfLabel,
                CornerRadius = 0
            };
            #endregion


            #region Impose Height
            var imposeHeightSwitch = new Switch {
                IsToggled = true
            };
            var heightRequestSlider = new Slider(0, 800, 100);
            heightRequestSlider.Effects.Add(new Forms9Patch.SliderStepSizeEffect(0.5));
            var imposedHeightGrid = new Grid
            {
                RowDefinitions = new RowDefinitionCollection
                {
                    new RowDefinition {
                        Height = GridLength.Star
                    },
                    new RowDefinition {
                        Height = GridLength.Star
                    }
                },
                ColumnDefinitions = new ColumnDefinitionCollection
                {
                    new ColumnDefinition {
                        Width = GridLength.Auto
                    },
                    new ColumnDefinition {
                        Width = GridLength.Star
                    },
                },
            };
            var heightRequestLabel = new Forms9Patch.Label("HeightRequest: " + 100);
            imposedHeightGrid.Children.Add(new Forms9Patch.Label("Impose Height?"), 0, 0);
            imposedHeightGrid.Children.Add(heightRequestLabel, 1, 0);
            imposedHeightGrid.Children.Add(imposeHeightSwitch, 0, 1);
            imposedHeightGrid.Children.Add(heightRequestSlider, 1, 1);

            imposeHeightSwitch.Toggled += (ihs, ihsArgs) =>
            {
                double heightRequest = imposeHeightSwitch.IsToggled ? heightRequestSlider.Value : -1;
                frameForXF.HeightRequest           = heightRequest;
                frameForF9P.HeightRequest          = heightRequest;
                heightRequestSlider.IsVisible      = imposeHeightSwitch.IsToggled;
                heightRequestLabel.IsVisible       = imposeHeightSwitch.IsToggled;
                vtAlignmentSelector.IsVisible      = imposeHeightSwitch.IsToggled;
                vtAlignmentSelectorLabel.IsVisible = imposeHeightSwitch.IsToggled;
            };

            heightRequestSlider.ValueChanged += (hrs, hrsArgs) =>
            {
                double heightRequest = imposeHeightSwitch.IsToggled ? heightRequestSlider.Value : -1;
                frameForXF.HeightRequest  = heightRequest;
                frameForF9P.HeightRequest = heightRequest;
                heightRequestLabel.Text   = "HeightRequest: " + heightRequestSlider.Value.ToString("####.###");
            };
            #endregion


            #region Font Size selection
            fontSizeSlider.ValueChanged   += OnFontSizeSliderValueChanged;
            LineHeightSlider.ValueChanged += OnLineHeightSlider_ValueChanged;

            f9pLabel.FittedFontSizeChanged += (object sender, double e) =>
            {
                fittedFontSizeLabel.Text = "FittedFontSize: " + e;
            };
            #endregion


            #region Lines selection
            var linesLabel = new Label
            {
                Text = "Lines: 5"
            };

            LinesSlider.ValueChanged += (sender, e) =>
            {
                linesLabel.Text = "Lines: " + ((int)Math.Round(LinesSlider.Value));
                f9pLabel.Lines  = ((int)Math.Round(LinesSlider.Value));
            };
            #endregion


            #region AutoFit Selection
            var fitSelector = new Forms9Patch.SegmentedControl();
            fitSelector.Segments.Add(new Forms9Patch.Segment
            {
                Text    = "None",
                Command = new Command(x => { f9pLabel.AutoFit = Forms9Patch.AutoFit.None; })
            });
            var widthSegment = new Forms9Patch.Segment
            {
                Text    = "Width",
                Command = new Command(x => { f9pLabel.AutoFit = Forms9Patch.AutoFit.Width; }),
                //IsEnabled = f9pLabel.HasImposedSize,
                //BindingContext = f9pLabel
            };
            //widthSegment.SetBinding(Forms9Patch.Segment.IsEnabledProperty, "HasImposedSize");
            fitSelector.Segments.Add(widthSegment);
            var linesSegment = new Forms9Patch.Segment
            {
                Text    = "Lines",
                Command = new Command(x => { f9pLabel.AutoFit = Forms9Patch.AutoFit.Lines; }),
                //IsEnabled = f9pLabel.HasImposedSize,
                //BindingContext = f9pLabel
            };
            //linesSegment.SetBinding(Forms9Patch.Segment.IsEnabledProperty, "HasImposedSize");
            fitSelector.Segments.Add(linesSegment);
            fitSelector.SelectIndex(0);
            #endregion


            #region Alignment Selection
            hzAlignmentSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "Start",
                Command = new Command(x =>
                {
                    f9pLabel.HorizontalTextAlignment = TextAlignment.Start;
                    xfLabel.HorizontalTextAlignment  = TextAlignment.Start;
                })
            }
                );
            hzAlignmentSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "Center",
                Command = new Command(x =>
                {
                    f9pLabel.HorizontalTextAlignment = TextAlignment.Center;
                    xfLabel.HorizontalTextAlignment  = TextAlignment.Center;
                })
            }
                );
            hzAlignmentSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "End",
                Command = new Command(x =>
                {
                    f9pLabel.HorizontalTextAlignment = TextAlignment.End;
                    xfLabel.HorizontalTextAlignment  = TextAlignment.End;
                })
            }
                );
            vtAlignmentSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "Start",
                Command = new Command(x =>
                {
                    f9pLabel.VerticalTextAlignment = TextAlignment.Start;
                    xfLabel.VerticalTextAlignment  = TextAlignment.Start;
                })
            }
                );
            vtAlignmentSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "Center",
                Command = new Command(x =>
                {
                    f9pLabel.VerticalTextAlignment = TextAlignment.Center;
                    xfLabel.VerticalTextAlignment  = TextAlignment.Center;
                })
            }
                );
            vtAlignmentSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "End",
                Command = new Command(x =>
                {
                    f9pLabel.VerticalTextAlignment = TextAlignment.End;
                    xfLabel.VerticalTextAlignment  = TextAlignment.End;
                })
            }
                );
            hzAlignmentSelector.SelectIndex(0);
            vtAlignmentSelector.SelectIndex(0);
            #endregion


            #region BreakMode selection
            var breakModeSelector = new Forms9Patch.SegmentedControl();
            breakModeSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "NoWrap",
                Command = new Command(x =>
                {
                    f9pLabel.LineBreakMode = LineBreakMode.NoWrap;
                    xfLabel.LineBreakMode  = LineBreakMode.NoWrap;
                })
            }
                );
            breakModeSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "Char",
                Command = new Command(x =>
                {
                    f9pLabel.LineBreakMode = LineBreakMode.CharacterWrap;
                    xfLabel.LineBreakMode  = LineBreakMode.CharacterWrap;
                })
            }
                );
            breakModeSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "Word",
                Command = new Command(x =>
                {
                    f9pLabel.LineBreakMode = LineBreakMode.WordWrap;
                    xfLabel.LineBreakMode  = LineBreakMode.WordWrap;
                })
            }
                );
            breakModeSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "Head",
                Command = new Command(x =>
                {
                    f9pLabel.LineBreakMode = LineBreakMode.HeadTruncation;
                    xfLabel.LineBreakMode  = LineBreakMode.HeadTruncation;
                })
            }
                );
            breakModeSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "Mid",
                Command = new Command(x =>
                {
                    f9pLabel.LineBreakMode = LineBreakMode.MiddleTruncation;
                    xfLabel.LineBreakMode  = LineBreakMode.MiddleTruncation;
                })
            }
                );
            breakModeSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "Tail",
                Command = new Command(x =>
                {
                    f9pLabel.LineBreakMode = LineBreakMode.TailTruncation;
                    xfLabel.LineBreakMode  = LineBreakMode.TailTruncation
                    ;
                })
            }
                );
            breakModeSelector.SelectIndex(2);
            #endregion


            #region FontSelection
            Picker fontPicker = new Picker
            {
                Title             = "Default",
                HorizontalOptions = LayoutOptions.EndAndExpand,
            };
            var fontFamilies = Forms9Patch.FontExtensions.LoadedFontFamilies();
            foreach (var fontFamily in fontFamilies)
            {
                fontPicker.Items.Add(fontFamily);
            }
            fontPicker.SelectedIndexChanged += (sender, e) =>
            {
                if (fontPicker.SelectedIndex > -1 && fontPicker.SelectedIndex < fontFamilies.Count)
                {
                    f9pLabel.FontFamily = fontFamilies[fontPicker.SelectedIndex];
                    xfLabel.FontFamily  = fontFamilies[fontPicker.SelectedIndex];
                }
            };
            #endregion



            Content = new ScrollView
            {
                Padding = 0,
                Content = new StackLayout
                {
                    Padding  = 10,
                    Children =
                    {
                        /*
                         * new Label { Text = "Text:" },
                         * editor,
                         */

                        new StackLayout
                        {
                            Orientation = StackOrientation.Horizontal,
                            Children    =
                            {
                                new Label {
                                    Text = "HTML Formatted:",
                                    HorizontalOptions = LayoutOptions.StartAndExpand,
                                },
                                modeSwitch
                            },
                        },

                        /*
                         * new Label { Text = "Xamarin.Forms.Label:" },
                         * frameForXF,
                         */
                        new Label         {
                            Text = "Forms9Patch.Label:"
                        },
                        frameForF9P,
                        LabelSizeLabel,
                        new StackLayout   {
                            Orientation = StackOrientation.Horizontal,
                            Children    = { new Label {
                                                Text = "Font:", HorizontalOptions = LayoutOptions.Start
                                            }, fontPicker, }
                        },

                        fontSizeLabel,
                        fontSizeSlider,

                        lineHeightLabel,
                        LineHeightSlider,

                        fittedFontSizeLabel,

                        new Label         {
                            Text = "AutoFit:"
                        },
                        fitSelector,

                        linesLabel,
                        LinesSlider,

                        imposedHeightGrid,


                        vtAlignmentSelectorLabel,
                        vtAlignmentSelector,
                        new Label         {
                            Text = "Horizontal Alignment:"
                        },
                        hzAlignmentSelector,
                        new Label         {
                            Text = "Truncation Mode:"
                        },
                        breakModeSelector,
                    }
                }
            };

            SizeChanged             += LabelAutoFitPage_SizeChanged;
            frameForF9P.SizeChanged += LabelAutoFitPage_SizeChanged;
        }
示例#15
0
        public HtmlLabelPage()
        {
            double result;
            string input = "9.5px";

            if (double.TryParse(input, out result))
            {
                System.Diagnostics.Debug.WriteLine("result = [" + result + "]");
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("fail");
            }


            var aTagLabel = new Forms9Patch.Label
            {
                HtmlText = "This is a test of the &lt;a&gt; tag.  Tap <a id=\"the id attribute\" href=\"the href attribute\">here</a> to try it.",
            };

            aTagLabel.ActionTagTapped += (sender, e) =>
            {
                Forms9Patch.Toast.Create("&lt;a&gt; tagged label", "<b>id:</b> " + e.Id + ";\n<b>href:</b>" + e.Href + ";");
            };


            Padding = new Thickness(5, 20, 5, 5);
            Content = new ScrollView
            {
                Content = new StackLayout
                {
                    Children =
                    {
                        new Label             {
                            Text = "Hello HtmlLabelPage"
                        },

                        aTagLabel,

                        new Forms9Patch.Label {
                            HtmlText = "<b>\nEMBEDDED (resource) CUSTOM FONT:</b>"
                        },
                        new Forms9Patch.Label {
                            Text       = "",
                            FontFamily = "Forms9PatchDemo.Resources.Fonts.MaterialIcons-Regular.ttf",
                        },

                        new Forms9Patch.Label {
                            HtmlText = "<b>\nSUPPORTED HTML TAGS:</b>"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "plain: no tags"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;b&gt;: <b>Bold</b> plain"
                        },

                        new Forms9Patch.Label {
                            HtmlText       = "&lt;Bold&gt;: <b>Bold</b> w/ serif italic serif base font",
                            FontFamily     = "Serif",
                            FontAttributes = FontAttributes.Italic,
                            TextColor      = Color.Blue,
                        },

                        new Forms9Patch.Label {
                            HtmlText = "&lt;strong&gt;: <strong>strong</strong> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;i&gt;: <i>Italic</i> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;em&gt;: <em>emphesis</em> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;b&gt;&lt;i&gt;: <b><i>Bold+Italic</i></b> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;sub&gt;: H<sub>2</sub>0 H₂0 plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;sup&gt;: 42<sup>2</sup> 42² plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;u&gt;: <u>underlined</u> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;ins&gt;: <ins>inserted</ins> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;font color=&quot;blue&quot;&gt;: <font color=\"blue\">Blue</font> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;font color=&quot;#FF0000&quot;&gt;: <font color=\"#FF0000\">Red</font> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;font color=&quot;rgb(0,255,0)&quot;&gt;: <font color=\"rgb(0,255,0)\">Green</font> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;font size=&quot;1&quot;&gt;: <font size=\"1\">size 1</font> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;font size=&quot;2&quot;&gt;: <font size=\"2\">size 2</font> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;font size=&quot;3&quot;&gt;: <font size=\"3\">size 3</font> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;font size=&quot;4&quot;&gt;: <font size=\"4\">size 4</font> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;font size=&quot;5&quot;&gt;: <font size=\"5\">size 5</font> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;font size=&quot;6&quot;&gt;: <font size=\"6\">size 6</font> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;font size=&quot;7&quot;&gt;: <font size=\"7\">size 7</font> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;font face=&quot;Monospace&quot;&gt;: <font face=\"Monospace\">Monspace</font> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;font face=&quot;Serif&quot;&gt;: <font face=\"Serif\">Serif</font> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;font face=&quot;Sans-serif&quot;&gt;: <font face=\"Sans-serif\">Sans-serif</font> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;font face=(resource)&gt;: <font face=\"Forms9PatchDemo.Resources.Fonts.MaterialIcons-Regular.ttf\"></font> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;pre&gt;: <pre>preformatted  text</pre> plain  \ttext"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;tt&gt;: <tt>teletype</tt> plain"
                        },

                        new Forms9Patch.Label {
                            HtmlText        = @"<font color=""red""><u><tt>This is a <i>very</i> <b>long block</b> of text which should wrap to the next line.</tt></b></font>",
                            BackgroundColor = Color.FromRgba(128, 128, 128, 50),
                        },

                        new Forms9Patch.Label {
                            HtmlText        = @"<font color=""red""><u><i><tt>AG Lynch refuses to answer questions over 74 times...</tt></i></u></font>",
                            BackgroundColor = Color.FromRgba(128, 128, 128, 50),
                        },



                        new Forms9Patch.Label {
                            HtmlText = "&lt;strike&gt;: <strike>strikethrough</strike> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;s&gt;: <s>strikethrough</s> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;del&gt;: <del>deleted text</del> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;big&gt;: <big>BIG text</big> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;small&gt;: <small>SMALL text</small> plain"
                        },

                        new Forms9Patch.Label {
                            HtmlText = "\n<b>SUPPORTTED HTML ATTRIBUTES:</b>"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "background-color: <div style=\"background-color:LightGrey\">LightGrey background</div> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "color: <div style=\"color:Sienna\">Sienna Text</div> plain"
                        },

                        new Forms9Patch.Label {
                            HtmlText = "font-family (resource): <div style=\"font-family:Forms9PatchDemo.Resources.Fonts.MaterialIcons-Regular.ttf\"></div> plain"
                        },

                        new Forms9Patch.Label {
                            HtmlText = "font-size: <div style=\"font-size:50%\">50% Text</div> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "font-size: <div style=\"font-size:9.0px\">8.5px Text</div> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "font-size: <div style=\"font-size:100%\">100% Text</div> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "font-size: <div style=\"font-size:17px\">17px Text</div> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "font-size: <div style=\"font-size:200%\">200% Text</div> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "font-size: <div style=\"font-size:34px\">34px Text</div> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "font-weight: <div style=\"font-weight:Bold;font-style:Italic\">Bold+Italic Text</div> plain"
                        },
                    }
                }
            };
        }
        public UnconstrainedLabelFitPage()
        {
            BackgroundColor = Color.Gray;
            Padding = 0;

            #region Editor
            var editor = new Editor
            {
                //Text = "Żorem ipsum dolor sit amet, consectetur adięiscing ełit",
                Text = text1,
                TextColor = Color.White,
                BackgroundColor = Color.Black,
                HeightRequest = 130,
                FontSize = 15,
            };
            editor.Effects.Add(Effect.Resolve("Forms9Patch.CustomFontEffect"));
            #endregion

            #region Xamarin Forms label
            var xfLabel = new Label
            {
                FontSize = 15,
                TextColor = Color.White,
                BackgroundColor = Color.Black,
                Text = editor.Text
            };
            #endregion

            #region Forms9Patch Label
            var f9pLabel = new Forms9Patch.Label
            {
                //HeightRequest = 50,
                Lines = 3,
                FontSize = 15,
                TextColor = Color.White,
                Fit = Forms9Patch.LabelFit.None,
                BackgroundColor = Color.Black,
                Text = editor.Text
            };
            #endregion

            #region Mode
            var modeSwitch = new Switch
            {
                IsToggled = false,
                HorizontalOptions = LayoutOptions.End,
            };
            modeSwitch.Toggled += (sender, e) =>
            {
                if (modeSwitch.IsToggled)
                    f9pLabel.HtmlText = editor.Text;
                else
                    f9pLabel.Text = editor.Text;
            };
            #endregion

            #region Sync text between Editor and Labels

            editor.TextChanged += (sender, e) =>
            {
                xfLabel.Text = editor.Text;
                f9pLabel.HtmlText = editor.Text;
            };
            #endregion

            #region Font Size selection
            var fontSizeSlider = new Slider
            {
                Maximum = 104,
                Minimum = 4,
                Value = 15
            };

            var fontSizeLabel = new Label
            {
                Text = "Font Size: 15"
            };
            fontSizeSlider.ValueChanged += (sender, e) =>
            {
                fontSizeLabel.Text = "Font Size: " + fontSizeSlider.Value;
                f9pLabel.FontSize = fontSizeSlider.Value;
                if (!rendering)
                {
                    rendering = true;
                    xfLabel.FontSize = fontSizeSlider.Value;
                    Device.StartTimer(TimeSpan.FromMilliseconds(50), () =>
                    {
                        if (Math.Abs(xfLabel.FontSize - lastFontSize) > double.Epsilon * 5)
                        {
                            xfLabel.FontSize = lastFontSize;
                            return true;
                        }
                        rendering = false;
                        return false;
                    });
                }
                lastFontSize = fontSizeSlider.Value;
            };
            var actualFontSizeLabel = new Label
            {
                Text = "Actual Font Size: 15"
            };

            f9pLabel.PropertyChanged += (sender, e) =>
            {
                if (e.PropertyName == Forms9Patch.Label.ActualFontSizeProperty.PropertyName)
                    actualFontSizeLabel.Text = "ActualFontSize: " + f9pLabel.ActualFontSize;
            };
            #endregion

            #region Lines selection
            var linesLabel = new Label
            {
                Text = "Lines: 3"
            };
            var linesSlider = new Slider
            {
                Minimum = 0,
                Maximum = 8,
                Value = 3
            };
            linesSlider.ValueChanged += (sender, e) =>
            {
                linesLabel.Text = "Lines: " + ((int)Math.Round(linesSlider.Value));
                f9pLabel.Lines = ((int)Math.Round(linesSlider.Value));
            };
            #endregion

            #region Fit Selection
            var fitSelector = new Forms9Patch.MaterialSegmentedControl();
            fitSelector.Segments.Add(new Forms9Patch.Segment
            {
                Text = "None",
                Command = new Command(x =>
                {
                    f9pLabel.Fit = Forms9Patch.LabelFit.None;
                })
            });
            var widthSegment = new Forms9Patch.Segment
            {
                Text = "Width",
                Command = new Command(x => { f9pLabel.Fit = Forms9Patch.LabelFit.Width; }),
                //IsEnabled = f9pLabel.HasImposedSize,
                BindingContext = f9pLabel,
                //IsEnabled = false
            };
            //widthSegment.SetBinding(Forms9Patch.Segment.IsEnabledProperty, "HasImposedSize");
            fitSelector.Segments.Add(widthSegment);
            var linesSegment = new Forms9Patch.Segment
            {
                Text = "Lines",
                Command = new Command(x => { f9pLabel.Fit = Forms9Patch.LabelFit.Lines; }),
                //IsEnabled = f9pLabel.HasImposedSize,
                BindingContext = f9pLabel
            };
            //linesSegment.SetBinding(Forms9Patch.Segment.IsEnabledProperty, "HasImposedSize");
            fitSelector.Segments.Add(linesSegment);
            fitSelector.SelectIndex(0);

            #endregion

            #region Alignment Selection
            var hzAlignmentSelector = new Forms9Patch.MaterialSegmentedControl();
            var vtAlignmentSelector = new Forms9Patch.MaterialSegmentedControl();
            hzAlignmentSelector.Segments.Add(
                new Forms9Patch.Segment
                {
                    Text = "Start",
                    Command = new Command(x =>
                    {
                        f9pLabel.HorizontalTextAlignment = TextAlignment.Start;
                        xfLabel.HorizontalTextAlignment = TextAlignment.Start;
                    })
                }
            );
            hzAlignmentSelector.Segments.Add(
                new Forms9Patch.Segment
                {
                    Text = "Center",
                    Command = new Command(x =>
                    {
                        f9pLabel.HorizontalTextAlignment = TextAlignment.Center;
                        xfLabel.HorizontalTextAlignment = TextAlignment.Center;
                    })
                }
            );
            hzAlignmentSelector.Segments.Add(
                new Forms9Patch.Segment
                {
                    Text = "End",
                    Command = new Command(x =>
                    {
                        f9pLabel.HorizontalTextAlignment = TextAlignment.End;
                        xfLabel.HorizontalTextAlignment = TextAlignment.End;
                    })
                }
            );
            vtAlignmentSelector.Segments.Add(
                new Forms9Patch.Segment
                {
                    Text = "Start",
                    Command = new Command(x =>
                    {
                        f9pLabel.VerticalTextAlignment = TextAlignment.Start;
                        xfLabel.VerticalTextAlignment = TextAlignment.Start;
                    })
                }
            );
            vtAlignmentSelector.Segments.Add(
                new Forms9Patch.Segment
                {
                    Text = "Center",
                    Command = new Command(x =>
                    {
                        f9pLabel.VerticalTextAlignment = TextAlignment.Center;
                        xfLabel.VerticalTextAlignment = TextAlignment.Center;
                    })
                }
            );
            vtAlignmentSelector.Segments.Add(
                new Forms9Patch.Segment
                {
                    Text = "End",
                    Command = new Command(x =>
                    {
                        f9pLabel.VerticalTextAlignment = TextAlignment.End;
                        xfLabel.VerticalTextAlignment = TextAlignment.End;
                    })
                }
            );
            hzAlignmentSelector.SelectIndex(0);
            vtAlignmentSelector.SelectIndex(0);
            #endregion

            #region BreakMode selection
            var breakModeSelector = new Forms9Patch.MaterialSegmentedControl();
            breakModeSelector.Segments.Add(
                new Forms9Patch.Segment
                {
                    Text = "NoWrap",
                    Command = new Command(x =>
                    {
                        f9pLabel.LineBreakMode = LineBreakMode.NoWrap;
                        xfLabel.LineBreakMode = LineBreakMode.NoWrap;
                    })
                }
            );
            breakModeSelector.Segments.Add(
                new Forms9Patch.Segment
                {
                    Text = "Char",
                    Command = new Command(x =>
                    {
                        f9pLabel.LineBreakMode = LineBreakMode.CharacterWrap;
                        xfLabel.LineBreakMode = LineBreakMode.CharacterWrap;
                    })
                }
            );
            breakModeSelector.Segments.Add(
                new Forms9Patch.Segment
                {
                    Text = "Word",
                    Command = new Command(x =>
                    {
                        f9pLabel.LineBreakMode = LineBreakMode.WordWrap;
                        xfLabel.LineBreakMode = LineBreakMode.WordWrap;
                    })
                }
            );
            breakModeSelector.Segments.Add(
                new Forms9Patch.Segment
                {
                    Text = "Head",
                    Command = new Command(x =>
                    {
                        f9pLabel.LineBreakMode = LineBreakMode.HeadTruncation;
                        xfLabel.LineBreakMode = LineBreakMode.HeadTruncation;
                    })
                }
            );
            breakModeSelector.Segments.Add(
                new Forms9Patch.Segment
                {
                    Text = "Mid",
                    Command = new Command(x =>
                    {
                        f9pLabel.LineBreakMode = LineBreakMode.MiddleTruncation;
                        xfLabel.LineBreakMode = LineBreakMode.MiddleTruncation;
                    })
                }
            );
            breakModeSelector.Segments.Add(
                new Forms9Patch.Segment
                {
                    Text = "Tail",
                    Command = new Command(x =>
                    {
                        f9pLabel.LineBreakMode = LineBreakMode.TailTruncation;
                        xfLabel.LineBreakMode = LineBreakMode.TailTruncation
                        ;
                    })
                }
            );
            breakModeSelector.SelectIndex(2);
            #endregion

            #region FontSelection
            Picker fontPicker = new Picker
            {
                Title = "Default",
                //HeightRequest = 300,
                //VerticalOptions = LayoutOptions.CenterAndExpand,
                HorizontalOptions = LayoutOptions.EndAndExpand,

            };
            var fontFamilies = Forms9Patch.FontExtensions.LoadedFontFamilies();
            foreach (var fontFamily in fontFamilies)
                fontPicker.Items.Add(fontFamily);
            fontPicker.SelectedIndexChanged += (sender, e) =>
            {
                string family = null;
                if (fontPicker.SelectedIndex > -1 && fontPicker.SelectedIndex < fontFamilies.Count)
                {
                    f9pLabel.FontFamily = fontFamilies[fontPicker.SelectedIndex];
                    xfLabel.FontFamily = fontFamilies[fontPicker.SelectedIndex];
                    editor.FontFamily = fontFamilies[fontPicker.SelectedIndex];
                }
            };
            #endregion

            Content = new ScrollView
            {
                Padding = 0,
                Content = new StackLayout
                {
                    Padding = 20,
                    Children = {
                        new Label { Text = "Text:" },
                        editor,
                        new StackLayout
                        {
                            Orientation = StackOrientation.Horizontal,
                            Children = {
                                new Label {
                                    Text = "HTML Formatted:",
                                    HorizontalOptions = LayoutOptions.StartAndExpand,
                                },
                                modeSwitch
                            },
                        },
                        new Label { Text = "Forms9Patch.Label:" },
                        f9pLabel,

                        new Label {
                            Text = "Font Family:",
                            HorizontalOptions = LayoutOptions.Start
                        },
                        fontPicker,

                        fontSizeLabel,
                        fontSizeSlider,
                        actualFontSizeLabel,
                        new Label { Text = "Fit:" },
                        fitSelector,
                        linesLabel,
                        linesSlider,

                        new Label { Text = "Horizontal Alignment:" },
                        hzAlignmentSelector,
                        new Label { Text = "Vertical Alignment:" },
                        vtAlignmentSelector,
                        new Label { Text = "Truncation Mode:" },
                        breakModeSelector,

                    }
                }
            };
        }
示例#17
0
        public ChrisEmbeddedResourceFontEffectPage()
        {
            var label = new Xamarin.Forms.Label
            {
                Text       = "Xamarin.Forms.Label",
                FontFamily = "Forms9PatchDemo.Resources.Fonts.Pacifico.ttf"
            };

            Forms9Patch.EmbeddedResourceFontEffect.ApplyTo(label);

            var editor = new Xamarin.Forms.Editor
            {
                Text       = "Xamarin.Forms.Editor",
                FontFamily = "Forms9PatchDemo.Resources.Fonts.Pacifico.ttf"
            };

            Forms9Patch.EmbeddedResourceFontEffect.ApplyTo(editor);

            var entry = new Xamarin.Forms.Entry
            {
                Text       = "Xamarin.Forms.Entry",
                FontFamily = "Forms9PatchDemo.Resources.Fonts.Pacifico.ttf"
            };

            Forms9Patch.EmbeddedResourceFontEffect.ApplyTo(entry);

            var button = new Xamarin.Forms.Button
            {
                Text       = "Xamarin.Forms.Button",
                FontFamily = "Forms9PatchDemo.Resources.Fonts.Pacifico.ttf"
            };

            Forms9Patch.EmbeddedResourceFontEffect.ApplyTo(button);

            var F9Plabel1 = new Forms9Patch.Label
            {
                Text       = "Forms9Patch.Label - luximb",
                FontFamily = "Forms9PatchDemo.Resources.Fonts.luximb.ttf",
                //TextColor = Color.Black
            };

            var F9Plabel2 = new Forms9Patch.Label
            {
                Text       = "Forms9Patch.Label - CPMono",
                FontFamily = "Forms9PatchDemo.Resources.Fonts.CPMono_v07_Bold.otf",
                //TextColor = Color.Black
            };

            var F9Plabel3 = new Forms9Patch.Label
            {
                Text = "Forms9Patch.Label - default FontFamily",
                // FontFamily = "Forms9PatchDemo.Resources.Fonts.CPMono_v07 Bold.otf"
                //TextColor = Color.Black
            };


            Content = new StackLayout
            {
                Children =
                {
                    label,
                    editor,
                    entry,
                    button,
                    F9Plabel1,
                    F9Plabel2,
                    F9Plabel3
                }
            };
        }
        public ChrisEmbeddedResourceFontEffectPage()
        {
            var label = new Xamarin.Forms.Label
            {
                Text       = "Xamarin.Forms.Label",
                FontFamily = "Forms9PatchDemo.Resources.Fonts.Pacifico.ttf"
            };

            label.Effects.Add(Effect.Resolve("Forms9Patch.EmbeddedResourceFontEffect"));

            var editor = new Xamarin.Forms.Editor
            {
                Text       = "Xamarin.Forms.Editor",
                FontFamily = "Forms9PatchDemo.Resources.Fonts.Pacifico.ttf"
            };

            editor.Effects.Add(Effect.Resolve("Forms9Patch.EmbeddedResourceFontEffect"));

            var entry = new Xamarin.Forms.Entry
            {
                Text       = "Xamarin.Forms.Entry",
                FontFamily = "Forms9PatchDemo.Resources.Fonts.Pacifico.ttf"
            };

            entry.Effects.Add(Effect.Resolve("Forms9Patch.EmbeddedResourceFontEffect"));

            var button = new Xamarin.Forms.Button
            {
                Text       = "Xamarin.Forms.Button",
                FontFamily = "Forms9PatchDemo.Resources.Fonts.Pacifico.ttf"
            };

            button.Effects.Add(Effect.Resolve("Forms9Patch.EmbeddedResourceFontEffect"));

            var F9Plabel1 = new Forms9Patch.Label
            {
                Text       = "Forms9Patch.Label - luximb",
                FontFamily = "Forms9PatchDemo.Resources.Fonts.luximb.ttf"
            };

            var F9Plabel2 = new Forms9Patch.Label
            {
                Text       = "Forms9Patch.Label - CPMono",
                FontFamily = "Forms9PatchDemo.Resources.Fonts.CPMono_v07_Bold.otf"
            };

            var F9Plabel3 = new Forms9Patch.Label
            {
                Text = "Forms9Patch.Label - default FontFamily",
                // FontFamily = "Forms9PatchDemo.Resources.Fonts.CPMono_v07 Bold.otf"
            };


            Content = new StackLayout
            {
                Children =
                {
                    label,
                    editor,
                    entry,
                    button,
                    F9Plabel1,
                    F9Plabel2,
                    F9Plabel3
                }
            };
        }
示例#19
0
        public HtmlLabelPage()
        {
            var aTagLabel = new Forms9Patch.Label
            {
                HtmlText = "This is a test of the &lt;a&gt; tag.  Tap <a id=\"the id attribute\" href=\"the href attribute\">here</a> to try it.",
            };

            aTagLabel.ActionTagTapped += (sender, e) =>
            {
                Forms9Patch.Toast.Create("&lt;a&gt; tagged label", "<b>id:</b> " + e.Id + ";\n<b>href:</b>" + e.Href + ";");
            };

            var assembly  = GetType().GetTypeInfo().Assembly;
            var resources = assembly.GetManifestResourceNames();

            //var resourceInfo = assembly.GetManifestResourceInfo("Forms9PatchDemo.Resources.Fonts.MaterialIcons-Regular.ttf");
            //var resourceStream = assembly.GetManifestResourceStream("Forms9PatchDemo.Resources.Fonts.MaterialIcons-Regular.ttf");

            //var canRead = resourceStream.CanRead;

            //var x = resourceStream.Length;
            BackgroundColor = Color.AliceBlue;
            Padding         = new Thickness(5, 20, 5, 5);
            Content         = new ScrollView
            {
                Content = new StackLayout
                {
                    Children =
                    {
                        new Label             {
                            Text = "Hello HtmlLabelPage"
                        },

                        aTagLabel,

                        new Forms9Patch.Label {
                            HtmlText = "<b>\nEMBEDDED (resource) CUSTOM FONT:</b>"
                        },
                        new Forms9Patch.Label {
                            Text       = "",
                            FontFamily = "Forms9PatchDemo.Resources.Fonts.MaterialIcons-Regular.ttf",
                        },

                        new Forms9Patch.Label("ColorFonts: ☺⛄☂♨⛅"),


                        new Forms9Patch.Label {
                            HtmlText = "<b>\nSUPPORTED HTML TAGS:</b>"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "plain: no tags"
                        },
                        new Forms9Patch.Label {
                            Text = "non-html and very long.  Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;b&gt;: <b>Bold</b> plain"
                        },


                        new Forms9Patch.Label {
                            HtmlText       = "&lt;Bold&gt;: <b>Bold</b> w/ serif italic <div style=\"color:red\">s</div><div style=\"color:green\">e</div>rif base font",
                            FontFamily     = "Serif",
                            FontAttributes = FontAttributes.Italic,
                            TextColor      = Color.Blue,
                        },

                        new Forms9Patch.Label {
                            HtmlText = "&lt;strong&gt;: <strong>strong</strong> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;i&gt;: <i>Italic</i> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;em&gt;: <em>emphesis</em> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;b&gt;&lt;i&gt;: <b><i>Bold+Italic</i></b> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;sub&gt;: H<sub>2</sub>0 H₂0 plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;sup&gt;: 42<sup>2</sup> 42² plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "1- <num>1234567890</num>/<den>1234567890</den>"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;u&gt;: <u>underlined</u> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;ins&gt;: <ins>inserted</ins> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;font color=&quot;blue&quot;&gt;: <font color=\"blue\">Blue</font> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;font color=&quot;#FF0000&quot;&gt;: <font color=\"#FF0000\">Red</font> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "\twith underline: <u><font color=\"#FF0000\">Red</font></u> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "\twith underline: <font color=\"#FF0000\"><u>Red</u></font> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;font color=&quot;rgb(0,255,0)&quot;&gt;: <font color=\"rgb(0,255,0)\">Green</font> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;font size=&quot;1&quot;&gt;: <font size=\"1\">size 1</font> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;font size=&quot;2&quot;&gt;: <font size=\"2\">size 2</font> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;font size=&quot;3&quot;&gt;: <font size=\"3\">size 3</font> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;font size=&quot;4&quot;&gt;: <font size=\"4\">size 4</font> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;font size=&quot;5&quot;&gt;: <font size=\"5\">size 5</font> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;font size=&quot;6&quot;&gt;: <font size=\"6\">size 6</font> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;font size=&quot;7&quot;&gt;: <font size=\"7\">size 7</font> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;font face=&quot;Monospace&quot;&gt;: <font face=\"Monospace\">Monspace</font> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;font face=&quot;Serif&quot;&gt;: <font face=\"Serif\">Serif</font> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;font face=&quot;Sans-serif&quot;&gt;: <font face=\"Sans-serif\">Sans-serif</font> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;font face=(resource)&gt;: <font face=\"Forms9PatchDemo.Resources.Fonts.MaterialIcons-Regular.ttf\"></font> plain"
                        },


                        new Forms9Patch.Label {
                            HtmlText = "&lt;pre&gt;: <pre>preformatted  text</pre> plain  \ttext"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;tt&gt;: <tt>teletype</tt> plain"
                        },


                        new Forms9Patch.Label {
                            HtmlText        = @"<font color=""red""><u><tt>This is a <i>very</i> <b>long block</b> of text which should wrap to the next line.</tt></b></font>",
                            BackgroundColor = Color.FromRgba(128, 128, 128, 50),
                            VerticalOptions = LayoutOptions.Center
                        },

                        new Forms9Patch.Label {
                            HtmlText        = @"<font color=""red""><u><i><tt>AG Lynch refuses to answer questions over 74 times...</tt></i></u></font>",
                            BackgroundColor = Color.FromRgba(128, 128, 128, 50),
                            VerticalOptions = LayoutOptions.Center
                        },

                        new Forms9Patch.Label {
                            HtmlText = "&lt;strike&gt;: <strike>strikethrough</strike> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;s&gt;: <s>strikethrough</s> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;del&gt;: <del>deleted text</del> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;big&gt;: <big>BIG text</big> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "&lt;small&gt;: <small>SMALL text</small> plain"
                        },

                        new Forms9Patch.Label {
                            HtmlText = "\n<b>SUPPORTTED HTML ATTRIBUTES:</b>"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "background-color: <div style=\"background-color:LightGrey\">LightGrey background</div> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "color: <div style=\"color:Sienna\">Sienna Text</div> plain"
                        },

                        new Forms9Patch.Label {
                            HtmlText = "font-family (resource): <div style=\"font-family:Forms9PatchDemo.Resources.Fonts.MaterialIcons-Regular.ttf\"></div> plain"
                        },

                        new Forms9Patch.Label {
                            HtmlText = "font-size: <div style=\"font-size:50%\">50% Text</div> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "font-size: <div style=\"font-size:8.5px\">8.5px Text</div> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "font-size: <div style=\"font-size:100%\">100% Text</div> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "font-size: <div style=\"font-size:17px\">17px Text</div> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "font-size: <div style=\"font-size:200%\">200% Text</div> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "font-size: <div style=\"font-size:34px\">34px Text</div> plain"
                        },
                        new Forms9Patch.Label {
                            HtmlText = "font-weight: <div style=\"font-weight:Bold;font-style:Italic\">Bold+Italic Text</div> plain"
                        },
                    }
                }
            };
        }
示例#20
0
        public LayoutWithLabel()
        {
            /*
             * Forms9Patch.Label leftLabel = new Forms9Patch.Label {
             *      Text = "left",
             *      HorizontalOptions = LayoutOptions.StartAndExpand,
             *      BackgroundColor = Color.Blue,
             *      TextColor = Color.Red,
             *      AutoFit = Forms9Patch.LabelFit.Lines,
             *      Lines = 1,
             * };
             * Forms9Patch.Label rightLabel = new Forms9Patch.Label {
             *      Text = "right",
             *      HorizontalOptions = LayoutOptions.EndAndExpand,
             *      BackgroundColor = Color.Red,
             *      TextColor = Color.Blue,
             *      AutoFit = Forms9Patch.LabelFit.Lines,
             *      HorizontalTextAlignment = TextAlignment.End,
             *      Lines=1,
             * };
             */
            StackLayout stackLayout = new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                Children    =
                {
                    //leftLabel,
                    //rightLabel
                }
            };


            //Content = stackLayout;

            Forms9Patch.Label textLabel = new Forms9Patch.Label
            {
                //HtmlText = "⌫",
                //HtmlText = "*",
                //HtmlText = "&#xE14A;",
                HtmlText = "pizza cheese",
                //HorizontalOptions = LayoutOptions.Center,
                VerticalTextAlignment = TextAlignment.Center,
                BackgroundColor       = Color.Green,
                TextColor             = Color.White,
                AutoFit = Forms9Patch.AutoFit.Width,
                HorizontalTextAlignment = TextAlignment.Center,
                Lines          = 1,
                FontSize       = 200,
                FontAttributes = FontAttributes.Italic,
                //FontFamily = "Forms9PatchDemo.Resources.Fonts.MaterialIcons-Regular.ttf",
                FontFamily = "AppleSDGothicNeo-Thin",
            };


            AbsoluteLayout absLayout = new AbsoluteLayout {
                BackgroundColor = Color.Gray
            };

            AbsoluteLayout.SetLayoutBounds(stackLayout, new Rectangle(0.5, 0.0, 0.95, 0.1));
            AbsoluteLayout.SetLayoutFlags(stackLayout, AbsoluteLayoutFlags.All);
            absLayout.Children.Add(stackLayout);

            AbsoluteLayout.SetLayoutBounds(textLabel, new Rectangle(0.5, 0.5, 0.8, 0.8));
            AbsoluteLayout.SetLayoutFlags(textLabel, AbsoluteLayoutFlags.All);
            absLayout.Children.Add(textLabel);

            //Content = absLayout;

            Grid grid = new Grid
            {
                RowDefinitions = new RowDefinitionCollection
                {
                    new RowDefinition {
                        Height = new GridLength(1, GridUnitType.Star)
                    },
                    new RowDefinition {
                        Height = new GridLength(1.35, GridUnitType.Star)
                    },
                    new RowDefinition {
                        Height = new GridLength(1.35, GridUnitType.Star)
                    },
                    new RowDefinition {
                        Height = new GridLength(1.35, GridUnitType.Star)
                    },
                    new RowDefinition {
                        Height = new GridLength(1.35, GridUnitType.Star)
                    },
                    new RowDefinition {
                        Height = new GridLength(1.35, GridUnitType.Star)
                    },
                    //new RowDefinition { Height = new GridLength(1.35, GridUnitType.Star) },
                },
                ColumnDefinitions = new ColumnDefinitionCollection
                {
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Star)
                    },
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Star)
                    },
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Star)
                    },
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Star)
                    },
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Star)
                    },
                },
                ColumnSpacing = 1,
                RowSpacing    = 1,
            };

            grid.Children.Add(absLayout, 1, 1);

            Content = grid;
        }
示例#21
0
        public JHGamerPage()
        {
            #region Page creation
            #region Not related to Forms9Patch
            Image item1 = new Image
            {
                Source = ImageSource.FromFile("blkbox_small.jpg")
            };
            Image item2 = new Image
            {
                Source = ImageSource.FromFile("blkbox_large.jpg")
            };
            StackLayout stackLayout = new StackLayout
            {
                Orientation       = StackOrientation.Vertical,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand
            };
            Button btnWelcome = new Button
            {
                Text = "Welcome! Click me",
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand
            };
            btnWelcome.Clicked += BtnWelcome_Clicked;
            stackLayout.Children.Add(btnWelcome);
            #endregion

            _lblTest = new Forms9Patch.Label
            {
                Text              = _strText,
                TextColor         = Color.Black,
                BackgroundColor   = Color.Transparent,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.Center,
                FontSize          = 40,
                Lines             = 1,
                AutoFit           = Forms9Patch.AutoFit.Width,
            };

            Grid gridTest = new Grid
            {
                RowDefinitions =
                {
                    new RowDefinition {
                        Height = new GridLength(1, GridUnitType.Star)
                    },
                },
                ColumnDefinitions =
                {
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Auto)
                    },
                    new ColumnDefinition {
                        Width = new GridLength(10, GridUnitType.Star)
                    },
                    new ColumnDefinition {
                        Width = new GridLength(2, GridUnitType.Auto)
                    },
                },
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.Start,
                BackgroundColor   = Color.White,
                Padding           = new Thickness(10, 0),
            };
            gridTest.Children.Add(item1, 0, 0);
            gridTest.Children.Add(_lblTest, 1, 0);
            gridTest.Children.Add(item2, 2, 0);

            Grid gridPage = new Grid
            {
                BackgroundColor   = Color.White,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                RowSpacing        = 0,
            };
            gridPage.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(.07, GridUnitType.Star)
            });
            gridPage.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(.9, GridUnitType.Star)
            });
            gridPage.Children.Add(gridTest, 0, 0);
            gridPage.Children.Add(stackLayout, 0, 1);

#if __IOS__
            gridPage.Padding = new Thickness(0, 30, 0, 0);
#elif __ANDROID__
            gridPage.Padding = new Thickness(0);
#endif
            gridPage.Padding = new Thickness(0);
            #endregion

            Content = gridPage;
        }
示例#22
0
 internal static double ClipFontSize(double size, Forms9Patch.Label label)
 {
     return(ClipFontSize(size, label.MinFontSize, label.FontSize));
 }
        public UnconstrainedLabelAutoFitPage()
        {
            BackgroundColor = Color.Gray;
            Padding         = 0;

            #region Editor
            var editor = new Editor
            {
                //Text = "Żorem ipsum dolor sit amet, consectetur adięiscing ełit",
                Text            = text1,
                TextColor       = Color.White,
                BackgroundColor = Color.Black,
                HeightRequest   = 130,
                FontSize        = 15,
            };
            #endregion


            #region Xamarin Forms label
            var xfLabel = new Label
            {
                FontSize        = 15,
                TextColor       = Color.White,
                BackgroundColor = Color.Black,
                Text            = editor.Text
            };
            #endregion


            #region Forms9Patch Label
            var f9pLabel = new Forms9Patch.Label
            {
                //HeightRequest = 50,
                Lines           = 3,
                FontSize        = 15,
                TextColor       = Color.White,
                AutoFit         = Forms9Patch.AutoFit.None,
                BackgroundColor = Color.Black,
                Text            = editor.Text
            };
            #endregion

            #region Mode
            var modeSwitch = new Switch
            {
                IsToggled         = false,
                HorizontalOptions = LayoutOptions.End,
            };
            modeSwitch.Toggled += (sender, e) =>
            {
                if (modeSwitch.IsToggled)
                {
                    f9pLabel.HtmlText = editor.Text;
                }
                else
                {
                    f9pLabel.Text = editor.Text;
                }
            };
            #endregion


            #region Sync text between Editor and Labels

            editor.TextChanged += (sender, e) =>
            {
                xfLabel.Text      = editor.Text;
                f9pLabel.HtmlText = editor.Text;
            };
            #endregion

            /*
             #region Frames for Labels
             *          var frameForF9P = new Frame
             *          {
             *                  HeightRequest = 100,
             *                  WidthRequest = 200,
             *                  Padding = 0,
             *                  Content = f9pLabel
             *          };
             *
             *          var frameForXF = new Frame
             *          {
             *                  HeightRequest = 100,
             *                  WidthRequest = 200,
             *                  Padding = 0,
             *                  Content = xfLabel
             *          };
             #endregion
             */

            #region Font Size selection
            var fontSizeSlider = new Slider
            {
                Maximum = 104,
                Minimum = 4,
                Value   = 15
            };

            var fontSizeLabel = new Label
            {
                Text = "Font Size: 15"
            };
            fontSizeSlider.ValueChanged += (sender, e) =>
            {
                fontSizeLabel.Text = "Font Size: " + fontSizeSlider.Value;
                f9pLabel.FontSize  = fontSizeSlider.Value;
                if (!rendering)
                {
                    rendering        = true;
                    xfLabel.FontSize = fontSizeSlider.Value;
                    Device.StartTimer(TimeSpan.FromMilliseconds(50), () =>
                    {
                        if (Math.Abs(xfLabel.FontSize - lastFontSize) > double.Epsilon * 5)
                        {
                            xfLabel.FontSize = lastFontSize;
                            return(true);
                        }
                        rendering = false;
                        return(false);
                    });
                }
                lastFontSize = fontSizeSlider.Value;
            };
            var actualFontSizeLabel = new Label
            {
                Text = "Actual Font Size: 15"
            };

            f9pLabel.PropertyChanged += (sender, e) =>
            {
                if (e.PropertyName == Forms9Patch.Label.FittedFontSizeProperty.PropertyName)
                {
                    actualFontSizeLabel.Text = "FittedFontSize: " + f9pLabel.FittedFontSize;
                }
            };

            #endregion


            #region Lines selection
            var linesLabel = new Label
            {
                Text = "Lines: 3"
            };
            var linesSlider = new Slider
            {
                Minimum = 0,
                Maximum = 8,
                Value   = 3
            };
            linesSlider.ValueChanged += (sender, e) =>
            {
                linesLabel.Text = "Lines: " + ((int)Math.Round(linesSlider.Value));
                f9pLabel.Lines  = ((int)Math.Round(linesSlider.Value));
            };
            #endregion


            #region AutoFit Selection
            var fitSelector = new Forms9Patch.SegmentedControl();
            fitSelector.Segments.Add(new Forms9Patch.Segment
            {
                Text    = "None",
                Command = new Command(x =>
                {
                    f9pLabel.AutoFit = Forms9Patch.AutoFit.None;
                })
            });
            var widthSegment = new Forms9Patch.Segment
            {
                Text    = "Width",
                Command = new Command(x => { f9pLabel.AutoFit = Forms9Patch.AutoFit.Width; }),
                //IsEnabled = f9pLabel.HasImposedSize,
                BindingContext = f9pLabel,
                //IsEnabled = false
            };
            //widthSegment.SetBinding(Forms9Patch.Segment.IsEnabledProperty, "HasImposedSize");
            fitSelector.Segments.Add(widthSegment);
            var linesSegment = new Forms9Patch.Segment
            {
                Text    = "Lines",
                Command = new Command(x => { f9pLabel.AutoFit = Forms9Patch.AutoFit.Lines; }),
                //IsEnabled = f9pLabel.HasImposedSize,
                BindingContext = f9pLabel
            };
            //linesSegment.SetBinding(Forms9Patch.Segment.IsEnabledProperty, "HasImposedSize");
            fitSelector.Segments.Add(linesSegment);
            fitSelector.SelectIndex(0);

            #endregion


            #region Alignment Selection
            var hzAlignmentSelector = new Forms9Patch.SegmentedControl();
            var vtAlignmentSelector = new Forms9Patch.SegmentedControl();
            hzAlignmentSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "Start",
                Command = new Command(x =>
                {
                    f9pLabel.HorizontalTextAlignment = TextAlignment.Start;
                    xfLabel.HorizontalTextAlignment  = TextAlignment.Start;
                })
            }
                );
            hzAlignmentSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "Center",
                Command = new Command(x =>
                {
                    f9pLabel.HorizontalTextAlignment = TextAlignment.Center;
                    xfLabel.HorizontalTextAlignment  = TextAlignment.Center;
                })
            }
                );
            hzAlignmentSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "End",
                Command = new Command(x =>
                {
                    f9pLabel.HorizontalTextAlignment = TextAlignment.End;
                    xfLabel.HorizontalTextAlignment  = TextAlignment.End;
                })
            }
                );
            vtAlignmentSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "Start",
                Command = new Command(x =>
                {
                    f9pLabel.VerticalTextAlignment = TextAlignment.Start;
                    xfLabel.VerticalTextAlignment  = TextAlignment.Start;
                })
            }
                );
            vtAlignmentSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "Center",
                Command = new Command(x =>
                {
                    f9pLabel.VerticalTextAlignment = TextAlignment.Center;
                    xfLabel.VerticalTextAlignment  = TextAlignment.Center;
                })
            }
                );
            vtAlignmentSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "End",
                Command = new Command(x =>
                {
                    f9pLabel.VerticalTextAlignment = TextAlignment.End;
                    xfLabel.VerticalTextAlignment  = TextAlignment.End;
                })
            }
                );
            hzAlignmentSelector.SelectIndex(0);
            vtAlignmentSelector.SelectIndex(0);
            #endregion


            #region BreakMode selection
            var breakModeSelector = new Forms9Patch.SegmentedControl();
            breakModeSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "NoWrap",
                Command = new Command(x =>
                {
                    f9pLabel.LineBreakMode = LineBreakMode.NoWrap;
                    xfLabel.LineBreakMode  = LineBreakMode.NoWrap;
                })
            }
                );
            breakModeSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "Char",
                Command = new Command(x =>
                {
                    f9pLabel.LineBreakMode = LineBreakMode.CharacterWrap;
                    xfLabel.LineBreakMode  = LineBreakMode.CharacterWrap;
                })
            }
                );
            breakModeSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "Word",
                Command = new Command(x =>
                {
                    f9pLabel.LineBreakMode = LineBreakMode.WordWrap;
                    xfLabel.LineBreakMode  = LineBreakMode.WordWrap;
                })
            }
                );
            breakModeSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "Head",
                Command = new Command(x =>
                {
                    f9pLabel.LineBreakMode = LineBreakMode.HeadTruncation;
                    xfLabel.LineBreakMode  = LineBreakMode.HeadTruncation;
                })
            }
                );
            breakModeSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "Mid",
                Command = new Command(x =>
                {
                    f9pLabel.LineBreakMode = LineBreakMode.MiddleTruncation;
                    xfLabel.LineBreakMode  = LineBreakMode.MiddleTruncation;
                })
            }
                );
            breakModeSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "Tail",
                Command = new Command(x =>
                {
                    f9pLabel.LineBreakMode = LineBreakMode.TailTruncation;
                    xfLabel.LineBreakMode  = LineBreakMode.TailTruncation
                    ;
                })
            }
                );
            breakModeSelector.SelectIndex(2);
            #endregion


            xfLabel.PropertyChanged += (sender, e) =>
            {
                if (e.PropertyName == HeightProperty.PropertyName)
                {
                    System.Diagnostics.Debug.WriteLine("xfLabel.Height=[" + xfLabel.Height + "]\n");
                }
            };

            #region FontSelection
            Picker fontPicker = new Picker
            {
                Title = "Default",
                //HeightRequest = 300,
                //VerticalOptions = LayoutOptions.CenterAndExpand,
                HorizontalOptions = LayoutOptions.EndAndExpand,
            };
            var fontFamilies = Forms9Patch.FontExtensions.LoadedFontFamilies();
            foreach (var fontFamily in fontFamilies)
            {
                fontPicker.Items.Add(fontFamily);
            }
            fontPicker.SelectedIndexChanged += (sender, e) =>
            {
                //string family = null;
                if (fontPicker.SelectedIndex > -1 && fontPicker.SelectedIndex < fontFamilies.Count)
                {
                    f9pLabel.FontFamily = fontFamilies[fontPicker.SelectedIndex];
                    xfLabel.FontFamily  = fontFamilies[fontPicker.SelectedIndex];
                }
            };
            #endregion



            Content = new ScrollView
            {
                Padding = 0,
                Content = new StackLayout
                {
                    Padding  = 20,
                    Children =
                    {
                        new Label         {
                            Text = "Text:"
                        },
                        editor,
                        new StackLayout
                        {
                            Orientation = StackOrientation.Horizontal,
                            Children    =
                            {
                                new Label {
                                    Text = "HTML Formatted:",
                                    HorizontalOptions = LayoutOptions.StartAndExpand,
                                },
                                modeSwitch
                            },
                        },

                        new Label         {
                            Text = "Xamarin.Forms.Label:"
                        },
                        xfLabel,
                        new Label         {
                            Text = "Forms9Patch.Label:"
                        },
                        f9pLabel,
                        new StackLayout
                        {
                            Orientation = StackOrientation.Horizontal,
                            Children    =
                            {
                                new Label {
                                    Text = "Font Family:",
                                    HorizontalOptions = LayoutOptions.Start
                                },
                                fontPicker
                            }
                        },

                        fontSizeLabel,
                        fontSizeSlider,
                        actualFontSizeLabel,
                        new Label         {
                            Text = "AutoFit:"
                        },
                        fitSelector,
                        linesLabel,
                        linesSlider,

                        new Label         {
                            Text = "Horizontal Alignment:"
                        },
                        hzAlignmentSelector,
                        new Label         {
                            Text = "Vertical Alignment:"
                        },
                        vtAlignmentSelector,
                        new Label         {
                            Text = "Truncation Mode:"
                        },
                        breakModeSelector,
                    }
                }
            };
        }
示例#24
0
        public LabelFitPage()
        {
            BackgroundColor = Color.Gray;
            Padding         = 0;

            #region Editor
            var editor = new Editor
            {
                //Text = "Żorem ipsum dolor sit amet, consectetur adięiscing ełit",
                Text            = text1,
                TextColor       = Color.White,
                BackgroundColor = Color.Black,
                HeightRequest   = 130,
                FontSize        = 15,
            };
            editor.Effects.Add(Effect.Resolve("Forms9Patch.CustomFontEffect"));

            #endregion


            #region Xamarin Forms label
            var xfLabel = new Label
            {
                FontSize        = 15,
                TextColor       = Color.White,
                BackgroundColor = Color.Black,
                Text            = editor.Text
            };
            #endregion


            #region Forms9Patch Label
            var f9pLabel = new Forms9Patch.Label
            {
                //HeightRequest = 50,
                Lines           = 5,
                FontSize        = 15,
                TextColor       = Color.White,
                Fit             = Forms9Patch.LabelFit.None,
                BackgroundColor = Color.Black,
                Text            = editor.Text
            };
            #endregion

            #region Mode
            var modeSwitch = new Switch
            {
                IsToggled         = false,
                HorizontalOptions = LayoutOptions.End,
            };
            modeSwitch.Toggled += (sender, e) =>
            {
                if (modeSwitch.IsToggled)
                {
                    f9pLabel.HtmlText = editor.Text;
                }
                else
                {
                    f9pLabel.Text = editor.Text;
                }
            };
            #endregion


            #region Sync text between Editor and Labels

            editor.TextChanged += (sender, e) =>
            {
                xfLabel.Text      = editor.Text;
                f9pLabel.HtmlText = editor.Text;
            };
            #endregion


            #region Frames for Labels
            var frameForF9P = new Frame
            {
                HeightRequest = 100,
                WidthRequest  = 200,
                Padding       = 0,
                Content       = f9pLabel
            };

            var frameForXF = new Frame
            {
                HeightRequest = 100,
                WidthRequest  = 200,
                Padding       = 0,
                Content       = xfLabel
            };
            #endregion


            #region Font Size selection
            var fontSizeSlider = new Slider
            {
                Maximum = 104,
                Minimum = 4,
                Value   = 15
            };

            var fontSizeLabel = new Label
            {
                Text = "Font Size: 15"
            };
            fontSizeSlider.ValueChanged += (sender, e) => {
                fontSizeLabel.Text = "Font Size: " + fontSizeSlider.Value;
                f9pLabel.FontSize  = fontSizeSlider.Value;
                if (!rendering)
                {
                    rendering        = true;
                    xfLabel.FontSize = fontSizeSlider.Value;
                    Device.StartTimer(TimeSpan.FromMilliseconds(50), () =>
                    {
                        if (Math.Abs(xfLabel.FontSize - lastFontSize) > double.Epsilon * 5)
                        {
                            xfLabel.FontSize = lastFontSize;
                            return(true);
                        }
                        rendering = false;
                        return(false);
                    });
                }
                lastFontSize = fontSizeSlider.Value;
            };
            var actualFontSizeLabel = new Label
            {
                Text = "Actual Font Size: 15"
            };

            f9pLabel.PropertyChanged += (sender, e) =>
            {
                if (e.PropertyName == Forms9Patch.Label.ActualFontSizeProperty.PropertyName)
                {
                    actualFontSizeLabel.Text = "ActualFontSize: " + f9pLabel.ActualFontSize;
                }
            };
            #endregion


            #region Lines selection
            var linesLabel = new Label
            {
                Text = "Lines: 5"
            };
            var linesSlider = new Slider
            {
                Minimum = 0,
                Maximum = 8,
                Value   = 5
            };
            linesSlider.ValueChanged += (sender, e) => {
                linesLabel.Text = "Lines: " + ((int)Math.Round(linesSlider.Value));
                f9pLabel.Lines  = ((int)Math.Round(linesSlider.Value));
            };
            #endregion


            #region Fit Selection
            var fitSelector = new Forms9Patch.MaterialSegmentedControl();
            fitSelector.Segments.Add(new Forms9Patch.Segment {
                Text    = "None",
                Command = new Command(x => {
                    f9pLabel.Fit = Forms9Patch.LabelFit.None;
                })
            });
            var widthSegment = new Forms9Patch.Segment
            {
                Text    = "Width",
                Command = new Command(x => { f9pLabel.Fit = Forms9Patch.LabelFit.Width; }),
                //IsEnabled = f9pLabel.HasImposedSize,
                BindingContext = f9pLabel
            };
            widthSegment.SetBinding(Forms9Patch.Segment.IsEnabledProperty, "HasImposedSize");
            fitSelector.Segments.Add(widthSegment);
            var linesSegment = new Forms9Patch.Segment
            {
                Text    = "Lines",
                Command = new Command(x => { f9pLabel.Fit = Forms9Patch.LabelFit.Lines; }),
                //IsEnabled = f9pLabel.HasImposedSize,
                BindingContext = f9pLabel
            };
            linesSegment.SetBinding(Forms9Patch.Segment.IsEnabledProperty, "HasImposedSize");
            fitSelector.Segments.Add(linesSegment);
            fitSelector.SelectIndex(0);
            #endregion


            #region Alignment Selection
            var hzAlignmentSelector = new Forms9Patch.MaterialSegmentedControl();
            var vtAlignmentSelector = new Forms9Patch.MaterialSegmentedControl();
            hzAlignmentSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "Start",
                Command = new Command(x => {
                    f9pLabel.HorizontalTextAlignment = TextAlignment.Start;
                    xfLabel.HorizontalTextAlignment  = TextAlignment.Start;
                })
            }
                );
            hzAlignmentSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "Center",
                Command = new Command(x => {
                    f9pLabel.HorizontalTextAlignment = TextAlignment.Center;
                    xfLabel.HorizontalTextAlignment  = TextAlignment.Center;
                })
            }
                );
            hzAlignmentSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "End",
                Command = new Command(x => {
                    f9pLabel.HorizontalTextAlignment = TextAlignment.End;
                    xfLabel.HorizontalTextAlignment  = TextAlignment.End;
                })
            }
                );
            vtAlignmentSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "Start",
                Command = new Command(x => {
                    f9pLabel.VerticalTextAlignment = TextAlignment.Start;
                    xfLabel.VerticalTextAlignment  = TextAlignment.Start;
                })
            }
                );
            vtAlignmentSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "Center",
                Command = new Command(x => {
                    f9pLabel.VerticalTextAlignment = TextAlignment.Center;
                    xfLabel.VerticalTextAlignment  = TextAlignment.Center;
                })
            }
                );
            vtAlignmentSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "End",
                Command = new Command(x => {
                    f9pLabel.VerticalTextAlignment = TextAlignment.End;
                    xfLabel.VerticalTextAlignment  = TextAlignment.End;
                })
            }
                );
            hzAlignmentSelector.SelectIndex(0);
            vtAlignmentSelector.SelectIndex(0);
            #endregion


            #region BreakMode selection
            var breakModeSelector = new Forms9Patch.MaterialSegmentedControl();
            breakModeSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "NoWrap",
                Command = new Command(x =>
                {
                    f9pLabel.LineBreakMode = LineBreakMode.NoWrap;
                    xfLabel.LineBreakMode  = LineBreakMode.NoWrap;
                })
            }
                );
            breakModeSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "Char",
                Command = new Command(x => {
                    f9pLabel.LineBreakMode = LineBreakMode.CharacterWrap;
                    xfLabel.LineBreakMode  = LineBreakMode.CharacterWrap;
                })
            }
                );
            breakModeSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "Word",
                Command = new Command(x =>
                {
                    f9pLabel.LineBreakMode = LineBreakMode.WordWrap;
                    xfLabel.LineBreakMode  = LineBreakMode.WordWrap;
                })
            }
                );
            breakModeSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "Head",
                Command = new Command(x =>
                {
                    f9pLabel.LineBreakMode = LineBreakMode.HeadTruncation;
                    xfLabel.LineBreakMode  = LineBreakMode.HeadTruncation;
                })
            }
                );
            breakModeSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "Mid",
                Command = new Command(x =>
                {
                    f9pLabel.LineBreakMode = LineBreakMode.MiddleTruncation;
                    xfLabel.LineBreakMode  = LineBreakMode.MiddleTruncation;
                })
            }
                );
            breakModeSelector.Segments.Add(
                new Forms9Patch.Segment
            {
                Text    = "Tail",
                Command = new Command(x =>
                {
                    f9pLabel.LineBreakMode = LineBreakMode.TailTruncation;
                    xfLabel.LineBreakMode  = LineBreakMode.TailTruncation
                    ;
                })
            }
                );
            breakModeSelector.SelectIndex(2);
            #endregion


            #region FontSelection

            /*
             * var fontSelector = new Forms9Patch.MaterialSegmentedControl();
             * fontSelector.Segments.Add(
             *      new Forms9Patch.Segment
             *      {
             *      Text = "System",
             *      Command = new Command(x =>
             *      {
             *              f9pLabel.FontFamily = null;
             *              xfLabel.FontFamily = null;
             *      })
             *      }
             * );
             * fontSelector.Segments.Add(
             *      new Forms9Patch.Segment
             *      {
             *              Text = Device.OnPlatform("Menlo","thin",""),
             *              Command = new Command(x =>
             *              {
             *                      f9pLabel.FontFamily = Device.OnPlatform("Menlo", "sans-serif-thin", "");
             *                      xfLabel.FontFamily = Device.OnPlatform("Menlo", "sans-serif-thin", "");
             *              })
             *      }
             * );
             * fontSelector.Segments.Add(
             *      new Forms9Patch.Segment
             *      {
             *              Text = Device.OnPlatform("Typewriter", "light", ""),
             *              Command = new Command(x =>
             *              {
             *              f9pLabel.FontFamily = Device.OnPlatform("American Typewriter","sans-serif-light","");
             *                      xfLabel.FontFamily = Device.OnPlatform("American Typewriter", "sans-serif-light", "");
             *              })
             *      }
             * );
             * fontSelector.Segments.Add(
             *      new Forms9Patch.Segment
             *      {
             *      Text = Device.OnPlatform("Chalkboard","condensed",""),
             *              Command = new Command(x =>
             *              {
             *              f9pLabel.FontFamily = Device.OnPlatform("Chalkboard SE","sans-serif-condensed","");
             *                      xfLabel.FontFamily = Device.OnPlatform("Chalkboard SE", "sans-serif-condensed", "");
             *              })
             *      }
             * );
             * fontSelector.Segments.Add(
             *      new Forms9Patch.Segment
             *      {
             *              Text = Device.OnPlatform("Zapfino", "medium", ""),
             *              Command = new Command(x =>
             *                                      {
             *              f9pLabel.FontFamily = Device.OnPlatform("Zapfino","sans-serif-medium","");
             *              xfLabel.FontFamily = Device.OnPlatform("Zapfino", "sans-serif-medium", "");
             *      })
             *      }
             * );
             * fontSelector.SelectIndex(0);
             */
            Picker fontPicker = new Picker
            {
                Title = "Default",
                //HeightRequest = 300,
                //VerticalOptions = LayoutOptions.CenterAndExpand,
                HorizontalOptions = LayoutOptions.EndAndExpand,
            };
            var fontFamilies = Forms9Patch.FontExtensions.LoadedFontFamilies();
            foreach (var fontFamily in fontFamilies)
            {
                fontPicker.Items.Add(fontFamily);
            }
            fontPicker.SelectedIndexChanged += (sender, e) =>
            {
                string family = null;
                if (fontPicker.SelectedIndex > -1 && fontPicker.SelectedIndex < fontFamilies.Count)
                {
                    f9pLabel.FontFamily = fontFamilies[fontPicker.SelectedIndex];
                    xfLabel.FontFamily  = fontFamilies[fontPicker.SelectedIndex];
                    editor.FontFamily   = fontFamilies[fontPicker.SelectedIndex];
                }
            };
            #endregion



            Content = new ScrollView
            {
                Padding = 0,
                Content = new StackLayout
                {
                    Padding  = 20,
                    Children =
                    {
                        new Label         {
                            Text = "Text:"
                        },
                        editor,
                        new StackLayout
                        {
                            Orientation = StackOrientation.Horizontal,
                            Children    =
                            {
                                new Label {
                                    Text = "HTML Formatted:",
                                    HorizontalOptions = LayoutOptions.StartAndExpand,
                                },
                                modeSwitch
                            },
                        },

                        //new Label { Text = "Xamarin.Forms.Label:" },
                        //frameForXF,
                        new Label         {
                            Text = "Forms9Patch.Label:"
                        },
                        //label,
                        frameForF9P,

                        new Label         {
                            Text = "Font Family:",
                            HorizontalOptions = LayoutOptions.Start
                        },
                        fontPicker,

                        fontSizeLabel,
                        fontSizeSlider,
                        actualFontSizeLabel,
                        new Label         {
                            Text = "Fit:"
                        },
                        fitSelector,
                        linesLabel,
                        linesSlider,

                        new Label         {
                            Text = "Horizontal Alignment:"
                        },
                        hzAlignmentSelector,
                        new Label         {
                            Text = "Vertical Alignment:"
                        },
                        vtAlignmentSelector,
                        new Label         {
                            Text = "Truncation Mode:"
                        },
                        breakModeSelector,
                    }
                }
            };
        }