예제 #1
0
        public FlyoutDemo()
        {
            BackgroundColor = Color.Blue;
            Padding         = 30;
            Content         = new StackLayout
            {
                Children =
                {
                    new Label {
                        Text = "Orientation:", TextColor = Color.White
                    },
                    _orientationControl,
                    new Label {
                        Text = "Alignment:", TextColor = Color.White
                    },
                    _alignmentControl,
                    new Label {
                        Text = "Options:", TextColor = Color.White
                    },
                    _optionsControl
                }
            };

            _orientationControl.SelectIndex(0);
            _alignmentControl.SelectIndex(0);
            _optionsControl.SelectIndex(1);

            _orientationControl.SegmentTapped += (sender, e) =>
            {
                _flyout.Orientation = e.Segment.Text == "Horizontal"
                    ? StackOrientation.Horizontal
                    : StackOrientation.Vertical;
                _flyout.IsVisible = true;
            };

            _alignmentControl.SegmentTapped += (sender, e) =>
            {
                _flyout.Alignment = e.Segment.Text == "Start"
                    ? Forms9Patch.FlyoutAlignment.Start
                    : Forms9Patch.FlyoutAlignment.End;
                _flyout.IsVisible = true;
            };

            _optionsControl.SegmentTapped += (sender, e) =>
            {
                _flyout.Margin        = _optionsControl.Segments[0].IsSelected ? 30 : 0;
                _flyout.OutlineRadius = _optionsControl.Segments[1].IsSelected ? 5 : 0;
            };
        }
예제 #2
0
 public SvgInCell()
 {
     _grid.Children.Add(_segmentControl);
     _grid.Children.Add(_listView, 0, 1);
     _segmentControl.SegmentSelected += OnSegmentSelected;
     _segmentControl.SelectIndex(1);
     Content = _grid;
     _listView.ItemSelected += (sender, e) =>
     {
         if (e.SelectedItem != null)
         {
             System.Diagnostics.Debug.WriteLine("e.SelectedItem: " + e.SelectedItem);
             Navigation.PushAsync(new EmbeddedResourceImagePage {
                 BindingContext = e.SelectedItem
             });
             _listView.SelectedItem = null;
         }
     };
 }
        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,
                    }
                }
            };
        }
예제 #4
0
        public ButtonCodePage()
        {
            _f9pButton.BackgroundImage = _f9pImage;

            Title       = "StateButtonCodePage";
            IsPresented = true;

            #region Local Elements
            hzOptionSegmentedControl.SelectIndex(3);
            hzOptionSegmentedControl.SegmentTapped += HzOptionSegmentedControl_SegmentTapped;

            vtOptionSegmentedControl.SelectIndex(3);
            vtOptionSegmentedControl.SegmentTapped += VtOptionSegmentedControl_SegmentTapped;


            var heightRequestSlider = new Slider(-1, 300, -1);
            heightRequestSlider.Effects.Add(new Forms9Patch.SliderStepSizeEffect(1));
            heightRequestSlider.ValueChanged += HeightRequestSlider_ValueChanged;

            var fillSegmentedControl = new Forms9Patch.SegmentedControl
            {
                Segments =
                {
                    //new Forms9Patch.Segment("NONE"),
                    new Forms9Patch.Segment("TILE"),
                    new Forms9Patch.Segment("ASPECTFILL"),
                    new Forms9Patch.Segment("ASPECTFIT"),
                    new Forms9Patch.Segment("FILL")
                }
            };
            fillSegmentedControl.SelectIndex(3);
            fillSegmentedControl.SegmentTapped += FillSegmentedControl_SegmentTapped;

            Forms9Patch.SegmentedControl shapesSelector = new Forms9Patch.SegmentedControl
            {
                Segments =
                {
                    new Forms9Patch.Segment {
                        Text = Rectangle
                    },
                    new Forms9Patch.Segment {
                        Text = Square
                    },
                    new Forms9Patch.Segment {
                        Text = Circle
                    },
                    new Forms9Patch.Segment {
                        Text = Ellipse
                    },
                    new Forms9Patch.Segment {
                        Text = "OBROUND"
                    }
                }
            };
            shapesSelector.SelectIndex(0);
            shapesSelector.SegmentTapped += ShapesSelector_SegmentTapped;

            var outlineWidthSlider = new Xamarin.Forms.Slider
            {
                Minimum = 0,
                Maximum = 15,
                Value   = 2
            };
            outlineWidthSlider.Effects.Add(new Forms9Patch.SliderStepSizeEffect(1.0 / Forms9Patch.Display.Scale));
            outlineWidthSlider.ValueChanged += OutlineWidthSlider_ValueChanged;

            outlineRadiusSlider.Effects.Add(new Forms9Patch.SliderStepSizeEffect(1));
            outlineRadiusSlider.ValueChanged += OutlineRadiusSlider_ValueChanged;

            var shapeAttributesSelector = new Forms9Patch.SegmentedControl
            {
                GroupToggleBehavior = Forms9Patch.GroupToggleBehavior.Multiselect,
                Segments            =
                {
                    new Forms9Patch.Segment("BACKGROUND"),
                    new Forms9Patch.Segment("OUTLINE"),
                    new Forms9Patch.Segment("SHADOW"),
                    new Forms9Patch.Segment("INVERTED")
                }
            };
            shapeAttributesSelector.SegmentTapped += ShapeAttributesSelector_SegmentTapped;

            var seg1 = new Forms9Patch.Segment("");
            var seg2 = new Forms9Patch.Segment(null, "Forms9PatchDemo.Resources.redGridBox");
            var seg3 = new Forms9Patch.Segment(null, "Forms9PatchDemo.Resources.button");
            var seg4 = new Forms9Patch.Segment(null, new Forms9Patch.Image {
                Source = ImageSource.FromFile("cat.jpg"), Fill = Forms9Patch.Fill.AspectFit
            });
            var seg5 = new Forms9Patch.Segment(null, new Forms9Patch.Image {
                Source = ImageSource.FromFile("balloons.jpg"), Fill = Forms9Patch.Fill.AspectFit
            });
            var seg6 = new Forms9Patch.Segment(null, "Forms9PatchDemo.Resources.image");
            var seg7 = new Forms9Patch.Segment(null, "Forms9PatchDemo.Resources.redribbon");
            var seg8 = new Forms9Patch.Segment(null, "Forms9PatchDemo.Resources.bubble");
            var seg9 = new Forms9Patch.Segment(null, "Forms9PatchDemo.Resources.bluebutton");

            var backgroundImageSelector = new Forms9Patch.SegmentedControl
            {
                HeightRequest           = 40,
                HasTightSpacing         = true,
                HorizontalTextAlignment = TextAlignment.Center,
                VerticalTextAlignment   = TextAlignment.Center,
                TintIcon = false,
                Segments =
                {
                    seg1,
                    seg2,
                    seg3,
                    seg4,
                    seg5,
                    seg6,
                    seg7,
                    seg8,
                    seg9
                }
            };

            /*
             * backgroundImageSelector.Segments.Add(seg1);
             * backgroundImageSelector.Segments.Add(seg2);
             * backgroundImageSelector.Segments.Add(seg3);
             * backgroundImageSelector.Segments.Add(seg4);
             * backgroundImageSelector.Segments.Add(seg5);
             * backgroundImageSelector.Segments.Add(seg6);
             * backgroundImageSelector.Segments.Add(seg7);
             * backgroundImageSelector.Segments.Add(seg8);
             * backgroundImageSelector.Segments.Add(seg9);
             */
            backgroundImageSelector.SelectIndex(1);
            backgroundImageSelector.SegmentTapped += BackgroundImageSelector_SegmentTapped;

            capsInsetsTopSlider.Effects.Add(capsInsetsTStepSizeEffect);
            capsInsetsTopSlider.ValueChanged += CapsInsetsSlider_ValueChanged;
            capsInsetsLeftSlider.Effects.Add(capsInsetsLStepSizeEffect);
            capsInsetsLeftSlider.ValueChanged += CapsInsetsSlider_ValueChanged;
            capsInsetsRightSlider.Effects.Add(capsInsetsRStepSizeEffect);
            capsInsetsRightSlider.Rotation      = 180;
            capsInsetsRightSlider.ValueChanged += CapsInsetsSlider_ValueChanged;
            capsInsetsBottomSlider.Effects.Add(capsInsetsBStepSizeEffect);
            capsInsetsBottomSlider.ValueChanged += CapsInsetsSlider_ValueChanged;
            capsInsetsBottomSlider.Rotation      = 180;

            var outlineGrid = new Xamarin.Forms.Grid
            {
                RowDefinitions = new RowDefinitionCollection
                {
                    new RowDefinition()
                    {
                        Height = new GridLength(1, GridUnitType.Auto)
                    },
                    new RowDefinition()
                    {
                        Height = new GridLength(1, GridUnitType.Auto)
                    },
                },
                ColumnDefinitions = new ColumnDefinitionCollection
                {
                    new ColumnDefinition()
                    {
                        Width = new GridLength(1, GridUnitType.Star)
                    },
                    new ColumnDefinition()
                    {
                        Width = new GridLength(1, GridUnitType.Star)
                    },
                },
            };
            outlineGrid.Children.Add(new Forms9Patch.Label("Forms9Patch.Image.OutlineWidth:"), 0, 0);
            outlineGrid.Children.Add(outlineWidthSlider, 0, 1);
            outlineGrid.Children.Add(new Forms9Patch.Label("Forms9Patch.Image.OutlineRadius:"), 1, 0);
            outlineGrid.Children.Add(outlineRadiusSlider, 1, 1);

            //pixelCapsSwitch.Toggled += PixelCapsSwitch_Toggled;

            var capsInsetsGrid = new Xamarin.Forms.Grid
            {
                RowDefinitions = new RowDefinitionCollection
                {
                    new RowDefinition()
                    {
                        Height = new GridLength(1, GridUnitType.Auto)
                    },
                    new RowDefinition()
                    {
                        Height = new GridLength(1, GridUnitType.Auto)
                    },
                    new RowDefinition()
                    {
                        Height = new GridLength(1, GridUnitType.Auto)
                    },
                    new RowDefinition()
                    {
                        Height = new GridLength(1, GridUnitType.Auto)
                    },
                },
                ColumnDefinitions = new ColumnDefinitionCollection
                {
                    new ColumnDefinition()
                    {
                        Width = new GridLength(1, GridUnitType.Star)
                    },
                    new ColumnDefinition()
                    {
                        Width = new GridLength(1, GridUnitType.Star)
                    },
                },
            };
            capsInsetsGrid.Children.Add(new Forms9Patch.Label("CapsInsets.Top:"), 0, 0);
            capsInsetsGrid.Children.Add(capsInsetsTopSlider, 0, 1);
            capsInsetsGrid.Children.Add(new Forms9Patch.Label("CapsInsets.Bottom:"), 0, 2);
            capsInsetsGrid.Children.Add(capsInsetsBottomSlider, 0, 3);
            capsInsetsGrid.Children.Add(new Forms9Patch.Label("CapsInsets.Left:"), 1, 0);
            capsInsetsGrid.Children.Add(capsInsetsLeftSlider, 1, 1);
            capsInsetsGrid.Children.Add(new Forms9Patch.Label("CapsInsets.Right:"), 1, 2);
            capsInsetsGrid.Children.Add(capsInsetsRightSlider, 1, 3);

            capsUnitsSegmentedControl.SelectIndex(0);
            capsUnitsSegmentedControl.SegmentTapped += CapsUnitsSegmentedControl_SegmentTapped;
            antiAliasSwitch.Toggled += AntiAliasSwitch_Toggled;
            var capsInsetsAndAntiAliasGrid = new Grid
            {
                RowDefinitions = new RowDefinitionCollection
                {
                    new RowDefinition()
                    {
                        Height = new GridLength(1, GridUnitType.Auto)
                    },
                    new RowDefinition()
                    {
                        Height = new GridLength(1, GridUnitType.Auto)
                    },
                },
                ColumnDefinitions = new ColumnDefinitionCollection
                {
                    new ColumnDefinition()
                    {
                        Width = new GridLength(1, GridUnitType.Star)
                    },
                    new ColumnDefinition()
                    {
                        Width = new GridLength(1, GridUnitType.Star)
                    },
                },
            };
            capsInsetsAndAntiAliasGrid.Children.Add(new Forms9Patch.Label("CapsInsets Units:"), 0, 0);
            capsInsetsAndAntiAliasGrid.Children.Add(capsUnitsSegmentedControl, 0, 1);
            capsInsetsAndAntiAliasGrid.Children.Add(new Forms9Patch.Label("AntiAlias:"), 1, 0);
            capsInsetsAndAntiAliasGrid.Children.Add(antiAliasSwitch, 1, 1);

            #endregion

            #region Content
            Master = new ContentPage
            {
                Title           = "Controls",
                BackgroundColor = Color.LightGray,
                Content         = new ScrollView
                {
                    Content = new StackLayout
                    {
                        Padding  = new Thickness(10, 10, 20, 10),
                        Children =
                        {
                            new Forms9Patch.Label("HorizontalOptions:"),
                            hzOptionSegmentedControl,
                            new Forms9Patch.Label("VerticalOptions:"),
                            vtOptionSegmentedControl,
                            new Forms9Patch.Label("Fill / Aspect:"),
                            fillSegmentedControl,
                            new Forms9Patch.Label("ElementShape:"),
                            shapesSelector,
                            new Forms9Patch.Label("Shape attributes:"),
                            shapeAttributesSelector,
                            outlineGrid,

                            new Forms9Patch.Label("ImageSource:"),
                            backgroundImageSelector,

                            capsInsetsAndAntiAliasGrid,
                            capsInsetsGrid,

                            new Forms9Patch.Label("HeightRequest:"),
                            heightRequestSlider,


                            new Xamarin.Forms.Label {
                                Text = "Display.Scale=[" + Forms9Patch.Display.Scale + "]"
                            }
                        },
                    },
                }
            };
            Detail = new ContentPage
            {
                Title = "Images",

                Content = new ScrollView
                {
                    Content = new StackLayout
                    {
                        Children =
                        {
                            new BoxView {
                                Color = Color.Black, HeightRequest = 1
                            },
                            new Forms9Patch.Label("Forms9Patch.Button:"),
                            new BoxView {
                                Color = Color.Black, HeightRequest = 1
                            },
                            _f9pButton,
                            new BoxView {
                                Color = Color.Black, HeightRequest = 1
                            },
                            new BoxView {
                                Color = Color.Black, HeightRequest = 1
                            },
                            new Forms9Patch.Label("Xamarin.Forms.Button:"),
                            new BoxView {
                                Color = Color.Black, HeightRequest = 1
                            },
                            _xfButton,
                            new BoxView {
                                Color = Color.Black, HeightRequest = 1
                            },
                        }
                    }
                }
            };

            #endregion
        }
예제 #5
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;
        }
예제 #6
0
        public LayoutCodePage()
        {
            hzOptionSegmentedControl.SelectIndex(3);
            hzOptionSegmentedControl.SegmentTapped += SetHzLayoutOptions;

            vtOptionSegmentedControl.SelectIndex(3);
            vtOptionSegmentedControl.SegmentTapped += SetVtLayoutOptions;

            heightRequestSlider.Effects.Add(new Forms9Patch.SliderStepSizeEffect(1));
            heightRequestSlider.ValueChanged += SetHeightRequest;

            fillSegmentedControl.SelectIndex(3);
            fillSegmentedControl.SegmentTapped += SetFill;

            shapesSelector.SelectIndex(0);
            shapesSelector.SegmentTapped += SetShape;

            outlineWidthSlider.Effects.Add(new Forms9Patch.SliderStepSizeEffect(1.0 / Forms9Patch.Display.Scale));
            outlineWidthSlider.ValueChanged += SetOutlineWidth;

            outlineRadiusSlider.Effects.Add(new Forms9Patch.SliderStepSizeEffect(1));
            outlineRadiusSlider.ValueChanged += SetOutlineRadius;

            shapeAttributesSelector.SegmentTapped += SetShapeAttributes;

            backgroundImageSelector.SelectIndex(1);
            backgroundImageSelector.SegmentTapped += SetBackgroundImage;

            capsInsetsTopSlider.Effects.Add(capsInsetsTStepSizeEffect);
            capsInsetsTopSlider.ValueChanged += SetCapsInsets;
            capsInsetsLeftSlider.Effects.Add(capsInsetsTStepSizeEffect);
            capsInsetsLeftSlider.ValueChanged += SetCapsInsets;
            capsInsetsRightSlider.Effects.Add(capsInsetsTStepSizeEffect);
            capsInsetsRightSlider.Rotation      = 180;
            capsInsetsRightSlider.ValueChanged += SetCapsInsets;
            capsInsetsBottomSlider.Effects.Add(capsInsetsTStepSizeEffect);
            capsInsetsBottomSlider.ValueChanged += SetCapsInsets;
            capsInsetsBottomSlider.Rotation      = 180;

            var outlineGrid = new Xamarin.Forms.Grid
            {
                RowDefinitions = new RowDefinitionCollection
                {
                    new RowDefinition()
                    {
                        Height = new GridLength(1, GridUnitType.Auto)
                    },
                    new RowDefinition()
                    {
                        Height = new GridLength(1, GridUnitType.Auto)
                    },
                },
                ColumnDefinitions = new ColumnDefinitionCollection
                {
                    new ColumnDefinition()
                    {
                        Width = new GridLength(1, GridUnitType.Star)
                    },
                    new ColumnDefinition()
                    {
                        Width = new GridLength(1, GridUnitType.Star)
                    },
                },
            };

            outlineGrid.Children.Add(new Forms9Patch.Label("OutlineWidth:"), 0, 0);
            outlineGrid.Children.Add(outlineWidthSlider, 0, 1);
            outlineGrid.Children.Add(new Forms9Patch.Label("OutlineRadius:"), 1, 0);
            outlineGrid.Children.Add(outlineRadiusSlider, 1, 1);

            var capsInsetsGrid = new Xamarin.Forms.Grid
            {
                RowDefinitions = new RowDefinitionCollection
                {
                    new RowDefinition()
                    {
                        Height = new GridLength(1, GridUnitType.Auto)
                    },
                    new RowDefinition()
                    {
                        Height = new GridLength(1, GridUnitType.Auto)
                    },
                    new RowDefinition()
                    {
                        Height = new GridLength(1, GridUnitType.Auto)
                    },
                    new RowDefinition()
                    {
                        Height = new GridLength(1, GridUnitType.Auto)
                    },
                },
                ColumnDefinitions = new ColumnDefinitionCollection
                {
                    new ColumnDefinition()
                    {
                        Width = new GridLength(1, GridUnitType.Star)
                    },
                    new ColumnDefinition()
                    {
                        Width = new GridLength(1, GridUnitType.Star)
                    },
                },
            };

            capsInsetsGrid.Children.Add(new Forms9Patch.Label("CapsInsets.Top:"), 0, 0);
            capsInsetsGrid.Children.Add(capsInsetsTopSlider, 0, 1);
            capsInsetsGrid.Children.Add(new Forms9Patch.Label("CapsInsets.Bottom:"), 0, 2);
            capsInsetsGrid.Children.Add(capsInsetsBottomSlider, 0, 3);
            capsInsetsGrid.Children.Add(new Forms9Patch.Label("CapsInsets.Left:"), 1, 0);
            capsInsetsGrid.Children.Add(capsInsetsLeftSlider, 1, 1);
            capsInsetsGrid.Children.Add(new Forms9Patch.Label("CapsInsets.Right:"), 1, 2);
            capsInsetsGrid.Children.Add(capsInsetsRightSlider, 1, 3);

            capsUnitsSegmentedControl.SelectIndex(0);
            capsUnitsSegmentedControl.SegmentTapped += SetCapsUnits;
            antiAliasSwitch.Toggled += SetAntiAlias;
            var capsInsetsAndAntiAliasGrid = new Grid
            {
                RowDefinitions = new RowDefinitionCollection
                {
                    new RowDefinition()
                    {
                        Height = new GridLength(1, GridUnitType.Auto)
                    },
                    new RowDefinition()
                    {
                        Height = new GridLength(1, GridUnitType.Auto)
                    },
                },
                ColumnDefinitions = new ColumnDefinitionCollection
                {
                    new ColumnDefinition()
                    {
                        Width = new GridLength(1, GridUnitType.Star)
                    },
                    new ColumnDefinition()
                    {
                        Width = new GridLength(1, GridUnitType.Star)
                    },
                },
            };

            capsInsetsAndAntiAliasGrid.Children.Add(new Forms9Patch.Label("CapsInsets Units:"), 0, 0);
            capsInsetsAndAntiAliasGrid.Children.Add(capsUnitsSegmentedControl, 0, 1);
            capsInsetsAndAntiAliasGrid.Children.Add(new Forms9Patch.Label("AntiAlias:"), 1, 0);
            capsInsetsAndAntiAliasGrid.Children.Add(antiAliasSwitch, 1, 1);



            var layoutTypeSegmentedController = new Forms9Patch.SegmentedControl
            {
                Segments =
                {
                    new Forms9Patch.Segment("ABSOLUTE"),
                    new Forms9Patch.Segment("FRAME"),
                    new Forms9Patch.Segment("GRID"),
                    new Forms9Patch.Segment("RELATIVE"),
                    new Forms9Patch.Segment("STACK")
                }
            };

            layoutTypeSegmentedController.SegmentTapped += (sender, e) =>
            {
                Layout layout = null;
                switch (e.Segment.Text)
                {
                case "ABSOLUTE": layout = GenerateAbsoluteLayout(); break;

                case "FRAME": layout = GenerateFrame(); break;

                case "GRID": layout = GenerateGrid(); break;

                case "RELATIVE": layout = GenerateRelativeLayout(); break;

                case "STACK": layout = GenerateStackLayout(); break;
                }
                ((ContentPage)Detail).Content = layout;
                SetLayoutProperties();
                ((ContentPage)Detail).Title = e.Segment.Text;
            };

            //Padding = new Thickness(20, 20, 0, 20);
            Master = new ContentPage
            {
                Title           = "Layout Settings",
                BackgroundColor = Color.LightGray,
                Content         = new ScrollView
                {
                    Content = new StackLayout
                    {
                        Padding  = 20,
                        Children =
                        {
                            new Forms9Patch.Label("Layout type:"),
                            layoutTypeSegmentedController,

                            new BoxView {
                                HeightRequest = 1,                                                              BackgroundColor  = Color.Black
                            },

                            new Forms9Patch.Label("Xamarin.Forms.VisualElement.HorizontalOptions (Alignment):"),
                            hzOptionSegmentedControl,
                            new Forms9Patch.Label("Xamarin.Forms.VisualElement.VerticalOptions (Alignment):"),
                            vtOptionSegmentedControl,

                            new BoxView {
                                HeightRequest = 1,                                                              BackgroundColor  = Color.Black
                            },

                            new Forms9Patch.Label("Forms9Patch.Image.Fill:"),
                            fillSegmentedControl,

                            new BoxView {
                                HeightRequest = 1,                                                              BackgroundColor  = Color.Black
                            },

                            new Forms9Patch.Label("Forms9Patch.Image.ElementShape:"),
                            shapesSelector,
                            new Forms9Patch.Label("Shape attributes (some value vs. default value)"),
                            shapeAttributesSelector,
                            outlineGrid,

                            new BoxView {
                                HeightRequest = 1,                                                              BackgroundColor  = Color.Black
                            },

                            new Forms9Patch.Label("Forms9Patch.Image.Source:"),
                            backgroundImageSelector,

                            new BoxView {
                                HeightRequest = 1,                                                              BackgroundColor  = Color.Black
                            },

                            capsInsetsAndAntiAliasGrid,
                            capsInsetsGrid,

                            new BoxView {
                                HeightRequest = 1,                                                              BackgroundColor  = Color.Black
                            },

                            new Forms9Patch.Label("Xamarin.Forms.VisualElement.HeightRequest:"),
                            heightRequestSlider,
                            new Xamarin.Forms.Label {
                                Text = "Display.Scale=[" + Forms9Patch.Display.Scale + "]"
                            }
                        },
                    },
                }
            };
            Detail = new ContentPage
            {
                Title   = "ABSOLUTE",
                Content = GenerateAbsoluteLayout()
            };
            SetLayoutProperties();

            IsPresented    = true;
            MasterBehavior = MasterBehavior.Default;
        }