public VariableWidthButtonPage()
        {
            Title = "Variable Width Button Page";

            _layoutTypeControl.SelectIndex(0);
            _touchType1.SelectIndex(0);

            _slider.ValueChanged += (s, e) =>
            {
                _xfButton.WidthRequest  = _slider.Value;
                _f9pButton.WidthRequest = _slider.Value;
            };
            _xfButton.WidthRequest  = _slider.Value;
            _f9pButton.WidthRequest = _slider.Value;


            _xfButton.Clicked       += (s, e) => FlashBox(Color.Green);
            _f9pButton.Clicked      += (s, e) => FlashBox(Color.Green);
            _f9pButton.LongPressing += (s, e) => FlashBox(Color.Yellow);
            _f9pButton.LongPressed  += (s, e) => FlashBox(Color.Red);

            _f9pButton.IsLongPressEnabled    = _longPressEnabledSwitch.IsToggled;
            _longPressEnabledSwitch.Toggled += (s, e) => _f9pButton.IsLongPressEnabled = _longPressEnabledSwitch.IsToggled;

            UpdateButtonsBackgroundColor();
            _darkBackgroundSwitch.Toggled += (s, e) => UpdateButtonsBackgroundColor();

            SetContent();
            _layoutTypeControl.SegmentSelected += (s, e) => SetContent();

            _inScrollViewSwitch.Toggled += (s, e) =>
            {
                Task.Run(() => SetScrollViewEmbed());
            };

            SetPagePadding();
            _pagePadding.Toggled += (s, e) => SetPagePadding();
        }
        public MaterialButtonAndSegmentAlignments()
        {
            BackgroundColor = Color.White;

            _grid1.Children.Add(new Xamarin.Forms.Label {
                Text = "HZ", VerticalTextAlignment = TextAlignment.Center, FontSize = 9, TextColor = Color.Black
            }, 0, 0);
            _grid1.Children.Add(_hzAlignmentElement, 1, 0);
            _grid1.Children.Add(new Xamarin.Forms.Label {
                Text = "VT", VerticalTextAlignment = TextAlignment.Center, FontSize = 9, TextColor = Color.Black
            }, 0, 1);
            _grid1.Children.Add(_vtAlignmentElement, 1, 1);
            _grid1.Children.Add(new Xamarin.Forms.Label {
                Text = "Opt", VerticalTextAlignment = TextAlignment.Center, FontSize = 9, TextColor = Color.Black
            }, 0, 2);
            _grid1.Children.Add(_optionsElement, 1, 2);
            _grid1.Children.Add(new Xamarin.Forms.Label {
                Text = "Icon", VerticalTextAlignment = TextAlignment.Center, FontSize = 9, TextColor = Color.Black
            }, 0, 3);
            _grid1.Children.Add(_iconElement, 1, 3);

            _grid2.Children.Add(new Xamarin.Forms.Label {
                Text = "Spacing:", TextColor = Color.Black
            }, 0, 0);
            _grid2.Children.Add(_spacingSlider, 0, 1);
            _grid2.Children.Add(new Xamarin.Forms.Label {
                Text = "Imposed Ht:", TextColor = Color.Black
            }, 1, 0);
            _grid2.Children.Add(_imposedHeightSwitch, 1, 1);



            Padding = new Thickness(40, 20, 20, 20);
            Content = new Xamarin.Forms.ScrollView
            {
                Content = new Xamarin.Forms.StackLayout
                {
                    Children =
                    {
                        _grid1,
                        _grid2,


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

                        _iconTextAndTextButton,
                        _hzSegmentsElement,
                        _vtSegmentsElement
                    }
                }
            };

            _hzAlignmentElement.SegmentTapped += (sender, e) =>
            {
                TextAlignment alignment;
                var           buttonText = string.Concat(e.Segment.Text.ToUpper().Substring(0, 1), e.Segment.Text.ToLower().Substring(1));
                if (!Enum.TryParse <TextAlignment>(buttonText, out alignment))
                {
                    throw new Exception("doh");
                }
                _labelElement.HorizontalTextAlignment          = alignment;
                _iconTextAndTextButton.HorizontalTextAlignment = alignment;
                _hzSegmentsElement.HorizontalTextAlignment     = alignment;
                _vtSegmentsElement.HorizontalTextAlignment     = alignment;
            };

            _vtAlignmentElement.SegmentTapped += (sender, e) =>
            {
                TextAlignment alignment;
                var           buttonText = string.Concat(e.Segment.Text.ToUpper().Substring(0, 1), e.Segment.Text.ToLower().Substring(1));
                if (!Enum.TryParse <TextAlignment>(buttonText, out alignment))
                {
                    throw new Exception("doh");
                }
                _labelElement.VerticalTextAlignment          = alignment;
                _iconTextAndTextButton.VerticalTextAlignment = alignment;
                _hzSegmentsElement.VerticalTextAlignment     = alignment;
                _vtSegmentsElement.VerticalTextAlignment     = alignment;
            };

            _optionsElement.SegmentTapped += (sender, e) =>
            {
                var options = new List <string>();
                foreach (var segment in _optionsElement.SelectedSegments)
                {
                    options.Add(segment.Text.ToUpper());
                }
                var hasTightSpacing = options.Contains("TIGHT");
                var trailingImage   = options.Contains("TRAILING");
                var orientation     = options.Contains("VERTICAL") ? StackOrientation.Vertical : StackOrientation.Horizontal;


                _iconTextAndTextButton.HasTightSpacing = hasTightSpacing;
                _iconTextAndTextButton.TrailingIcon    = trailingImage;
                _iconTextAndTextButton.Orientation     = orientation;

                _hzSegmentsElement.HasTightSpacing         = hasTightSpacing;
                _hzSegmentsElement.TrailingIcon            = trailingImage;
                _hzSegmentsElement.IntraSegmentOrientation = orientation;

                _vtSegmentsElement.HasTightSpacing         = hasTightSpacing;
                _vtSegmentsElement.TrailingIcon            = trailingImage;
                _vtSegmentsElement.IntraSegmentOrientation = orientation;
            };

            _iconElement.SegmentTapped += (sender, e) =>
            {
                if (e.Segment.IconImage != null)
                {
                    _iconTextAndTextButton.IconImage = new Forms9Patch.Image("Forms9PatchDemo.Resources.Info");
                    foreach (var segment in _hzSegmentsElement.Segments)
                    {
                        segment.IconImage = new Forms9Patch.Image("Forms9PatchDemo.Resources.Info");
                    }
                    foreach (var segment in _vtSegmentsElement.Segments)
                    {
                        segment.IconImage = new Forms9Patch.Image("Forms9PatchDemo.Resources.Info");
                    }
                }
                else
                {
                    SetIconText(e.Segment.HtmlText);
                }
            };

            _spacingSlider.ValueChanged += (sender, e) =>
            {
                _iconTextAndTextButton.Spacing         = _spacingSlider.Value;
                _hzSegmentsElement.IntraSegmentSpacing = _spacingSlider.Value;
                _vtSegmentsElement.IntraSegmentSpacing = _spacingSlider.Value;
            };

            _imposedHeightSwitch.Toggled += (sender, e) =>
            {
                _iconTextAndTextButton.HeightRequest = _imposedHeightSwitch.IsToggled ? 60 : -1;
                _hzSegmentsElement.HeightRequest     = _imposedHeightSwitch.IsToggled ? 60 : -1;
                _vtSegmentsElement.HeightRequest     = _imposedHeightSwitch.IsToggled ? 180 : -1;

                _vtAlignmentElement.IsEnabled = _imposedHeightSwitch.IsToggled;
                if (!_vtAlignmentElement.IsEnabled)
                {
                    _vtAlignmentElement.DeselectAll();
                }
            };

            var defaultHzAlignment = _iconTextAndTextButton.HorizontalTextAlignment;

            if (defaultHzAlignment == TextAlignment.Start)
            {
                _hzAlignmentElement.SelectIndex(0);
            }
            else if (defaultHzAlignment == TextAlignment.Center)
            {
                _hzAlignmentElement.SelectIndex(1);
            }
            else
            {
                _hzAlignmentElement.SelectIndex(2);
            }


            _iconElement.SelectIndex(0);
            _vtAlignmentElement.IsEnabled = false;
        }
Exemple #3
0
        public PopupsPage()
        {
            Padding = 20;
            _hzLayoutOptions.SelectIndex(1);
            _vtLayoutOptions.SelectIndex(1);

            #region ModalPopup
            cancelModalButton.Clicked += async(sender, e) => await _modalPopup.CancelAsync();

            popPushModalButton.Clicked += (sender, e) =>
            {
                _modalPopup.IsVisible = false;
                _modalPopup.IsVisible = true;
            };
            showModalButton.Clicked += (sender, e) =>
            {
                _modalPopup.HasShadow         = _hasShadow;
                _modalPopup.ShadowInverted    = _shadowInverted;
                _modalPopup.OutlineWidth      = _blueOutline ? 1 : 0;
                _modalPopup.IsVisible         = true;
                _modalPopup.HorizontalOptions = LayoutOption(_hzLayoutOptions);
                _modalPopup.VerticalOptions   = LayoutOption(_vtLayoutOptions);
            };
            #endregion


            #region BubblePopups


            var showBubbleLeftButton = new Forms9Patch.Button(bubbleLeftText)
            {
                BackgroundColor = Color.White, HorizontalOptions = LayoutOptions.Center
            };
            var showBubbleRightButton = new Forms9Patch.Button(bubbleRightText)
            {
                BackgroundColor = Color.White, HorizontalOptions = LayoutOptions.Center
            };
            var showBubbleUpButton = new Forms9Patch.Button(bubbleUpText)
            {
                BackgroundColor = Color.White, HorizontalOptions = LayoutOptions.Center
            };
            var showBubbleDownButton = new Forms9Patch.Button(bubbleDownText)
            {
                BackgroundColor = Color.White, HorizontalOptions = LayoutOptions.Center
            };
            var showBubbleHzButton = new Forms9Patch.Button(bubbleHzText)
            {
                BackgroundColor = Color.White, HorizontalOptions = LayoutOptions.Center
            };
            var showBubbleVtButton = new Forms9Patch.Button(bubbleVtText)
            {
                BackgroundColor = Color.White, HorizontalOptions = LayoutOptions.Center
            };
            var showBubbleAnyButton = new Forms9Patch.Button(bubbleAnyText)
            {
                BackgroundColor = Color.White, HorizontalOptions = LayoutOptions.Center
            };
            var showBubbleNoneButton = new Forms9Patch.Button(bubbleNoneText)
            {
                BackgroundColor = Color.White, HorizontalOptions = LayoutOptions.Center
            };

            var bubblePointerDirectionControl = new SegmentedControl
            {
                Segments =
                {
                    new Segment("←"),
                    new Segment("↑"),
                    new Segment("→"),
                    new Segment("↓"),
                    new Segment("↔"),
                    new Segment("↕"),
                    new Segment("↔ ↕"),
                    new Segment(" ")
                },
                SyncSegmentFontSizes = false,
            };

            var cancelBubbleButton = new Forms9Patch.Button("CANCEL");

            var bubbleTarget = new Forms9Patch.Frame
            {
                OutlineWidth      = 1,
                OutlineColor      = Color.Black,
                OutlineRadius     = 4,
                Content           = new Forms9Patch.Label("BUBBLE TARGET"),
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center,
            };

            bubble = new BubblePopup(bubbleTarget)
            {
                Content = new Xamarin.Forms.StackLayout
                {
                    Children =
                    {
                        new Forms9Patch.Label("BubblePopup")
                        {
                            FontAttributes = FontAttributes.Bold
                        },
                        bubblePointerDirectionControl,
                        cancelBubbleButton
                    },
                },
            };

            bubblePointerDirectionControl.SegmentTapped += (sender, e) =>
            {
                switch (e.Segment.Text)
                {
                case "←": bubble.PointerDirection = PointerDirection.Left; break;

                case "↑": bubble.PointerDirection = PointerDirection.Up; break;

                case "→": bubble.PointerDirection = PointerDirection.Right; break;

                case "↓": bubble.PointerDirection = PointerDirection.Down; break;

                case "↔": bubble.PointerDirection = PointerDirection.Horizontal; break;

                case "↕": bubble.PointerDirection = PointerDirection.Vertical; break;

                case "↔↕": bubble.PointerDirection = PointerDirection.Any; break;

                case " ": bubble.PointerDirection = PointerDirection.None; break;
                }
            };

            cancelBubbleButton.Clicked += async(sender, e) => await bubble.CancelAsync();

            showBubbleLeftButton.Clicked  += OnBubbleButtonClicked;
            showBubbleRightButton.Clicked += OnBubbleButtonClicked;
            showBubbleUpButton.Clicked    += OnBubbleButtonClicked;
            showBubbleDownButton.Clicked  += OnBubbleButtonClicked;
            showBubbleHzButton.Clicked    += OnBubbleButtonClicked;
            showBubbleVtButton.Clicked    += OnBubbleButtonClicked;
            showBubbleAnyButton.Clicked   += OnBubbleButtonClicked;
            showBubbleNoneButton.Clicked  += OnBubbleButtonClicked;
            #endregion


            #region ActivityPopup
            Forms9Patch.Button showActivityPopupButton = new Forms9Patch.Button("ActivityIndicatorPopup")
            {
                BackgroundColor = Color.White
            };
            showActivityPopupButton.Clicked += (sender, e) =>
            {
                //var activity = Forms9Patch.ActivityIndicatorPopup.Create();
                _activity.CancelOnPageOverlayTouch = true;
                _activity.IsVisible = true;
            };
            #endregion


            #region PermissionPopup
            var showPermissionButton = new Forms9Patch.Button("PermissionPopup")
            {
                BackgroundColor = Color.White
            };
            showPermissionButton.Clicked += (sender, e) =>
            {
                var permission = PermissionPopup.Create("PermissionPopup", "Do you agree?");
                permission.HorizontalOptions = LayoutOption(_hzLayoutOptions);
                permission.VerticalOptions   = LayoutOption(_vtLayoutOptions);
                permission.OutlineColor      = Color.Blue;
                permission.HasShadow         = _hasShadow;
                permission.ShadowInverted    = _shadowInverted;
                permission.OutlineWidth      = _blueOutline ? 1 : 0;
            };
            #endregion


            #region Toast
            var showToastButton = new Forms9Patch.Button("Toast")
            {
                BackgroundColor = Color.White
            };
            showToastButton.Clicked += (sender, e) =>
            {
                var toast = Toast.Create("Toast", "... of the town!");
                toast.OutlineColor      = Color.Blue;
                toast.HasShadow         = _hasShadow;
                toast.ShadowInverted    = _shadowInverted;
                toast.OutlineWidth      = _blueOutline ? 1 : 0;
                toast.HorizontalOptions = LayoutOption(_hzLayoutOptions);
                toast.VerticalOptions   = LayoutOption(_vtLayoutOptions);
            };
            #endregion


            #region TargetedToast
            var showTargetedToash = new Forms9Patch.Button("TargetedToast")
            {
                BackgroundColor = Color.White
            };
            showTargetedToash.Clicked += (sender, e) =>
            {
                var toast = TargetedToast.Create(showTargetedToash, "TargetedToast", "... has the far getted most!");
                toast.OutlineColor      = Color.Blue;
                toast.HasShadow         = _hasShadow;
                toast.ShadowInverted    = _shadowInverted;
                toast.OutlineWidth      = _blueOutline ? 1 : 0;
                toast.HorizontalOptions = LayoutOption(_hzLayoutOptions);
                toast.VerticalOptions   = LayoutOption(_vtLayoutOptions);
            };
            #endregion


            #region TargetedMenu
            showTargetedMenu = new Forms9Patch.Button("TargetedMenu")
            {
                BackgroundColor = Color.White
            };
            var targetedMenu = new Forms9Patch.TargetedMenu(showTargetedMenu)
            {
                Segments =
                {
                    new Segment("Copy",       "<font face=\"Forms9PatchDemo.Resources.Fonts.MaterialIcons-Regular.ttf\">&#xE14D;</font>"),
                    new Segment("Cut",        "<font face=\"Forms9PatchDemo.Resources.Fonts.MaterialIcons-Regular.ttf\">&#xE14E;</font>"),
                    new Segment("Paste",      "<font face=\"Forms9PatchDemo.Resources.Fonts.MaterialIcons-Regular.ttf\">&#xE14F;</font>"),
                    new Segment("Segment A"),
                    new Segment("Segment B"),
                    new Segment("Segment C"),
                    new Segment("Segment D"),
                    new Segment("Segment E"),
                    new Segment("Segment F"),
                    new Segment("Segment G"),
                    new Segment("Segment H"),
                },
                TextColor = Color.White
            };
            showTargetedMenu.Clicked += (s, e) =>
            {
                targetedMenu.IsVisible      = true;
                targetedMenu.HasShadow      = _hasShadow;
                targetedMenu.ShadowInverted = _shadowInverted;
                targetedMenu.IsVisible      = true;
            };
            targetedMenu.SegmentTapped += (s, e) => System.Diagnostics.Debug.WriteLine("TargetedMenu.SegmentTapped: " + e.Segment.Text);
            #endregion


            #region Vertical TargetedMenu
            var showVerticalTargetedMenu = new Forms9Patch.Button("Vertical TargetedMenu")
            {
                BackgroundColor = Color.White
            };
            var verticalTargetedMenu = new Forms9Patch.TargetedMenu(showVerticalTargetedMenu)
            {
                Orientation = StackOrientation.Vertical,
                Segments    =
                {
                    new Segment("Copy",       "<font face=\"Forms9PatchDemo.Resources.Fonts.MaterialIcons-Regular.ttf\">&#xE14D;</font>"),
                    new Segment("Cut",        "<font face=\"Forms9PatchDemo.Resources.Fonts.MaterialIcons-Regular.ttf\">&#xE14E;</font>"),
                    new Segment("Paste",      "<font face=\"Forms9PatchDemo.Resources.Fonts.MaterialIcons-Regular.ttf\">&#xE14F;</font>"),
                    new Segment("Segment A"),
                    new Segment("Segment B"),
                    new Segment("Segment C"),
                    new Segment("Segment D"),
                    new Segment("Segment E"),
                    new Segment("Segment F"),
                    new Segment("Segment G"),
                    new Segment("Segment H"),
                },
            };
            showVerticalTargetedMenu.Clicked += (s, e) =>
            {
                //verticalTargetedMenu.OutlineColor = Color.Blue;
                verticalTargetedMenu.IsVisible      = true;
                verticalTargetedMenu.HasShadow      = _hasShadow;
                verticalTargetedMenu.ShadowInverted = _shadowInverted;
                verticalTargetedMenu.IsVisible      = true;
            };
            verticalTargetedMenu.SegmentTapped += (s, e) => System.Diagnostics.Debug.WriteLine("TargetedMenu.SegmentTapped: " + e.Segment.Text);
            #endregion


            #region SoftwareKeyboardTest

            var yearPicker = new Xamarin.Forms.Picker
            {
                Title       = "SELECT YEAR",
                ItemsSource = new List <string> {
                    "SELECT YEAR", "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2006", "2008", "2009", "2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020"
                },
                SelectedItem  = "SELECT YEAR",
                SelectedIndex = 0,
                TextColor     = Color.LightGray,
            };
            yearPicker.SelectedIndexChanged += (s, e) => yearPicker.TextColor = yearPicker.SelectedIndex == 0 ? Color.LightGray : Color.Blue;

            var monthPicker = new Xamarin.Forms.Picker
            {
                Title       = "SELECT MONTH",
                ItemsSource = new List <string> {
                    "SELECT MONTH", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
                },
                SelectedItem = "SELECT MONTH",
                TextColor    = Color.LightGray,
            };
            monthPicker.SelectedIndexChanged += (s, e) => monthPicker.TextColor = monthPicker.SelectedIndex == 0 ? Color.LightGray : Color.Blue;


            var softwareKeyboardTestButton = new Forms9Patch.Button("Software Keyboard Test")
            {
                BackgroundColor = Color.White
            };
            var softwareKeyboardTestPopup = new ModalPopup
            {
                HorizontalOptions = LayoutOption(_hzLayoutOptions),
                VerticalOptions   = LayoutOption(_vtLayoutOptions),
                Content           =
                    new Xamarin.Forms.StackLayout
                {
                    Children =
                    {
                        yearPicker,
                        monthPicker,
                        new Xamarin.Forms.Entry
                        {
                            Placeholder      = "ENTER FIRST NAME",
                            TextColor        = Color.Blue,
                            PlaceholderColor = Color.LightGray,
                        },
                        new Xamarin.Forms.Entry
                        {
                            Placeholder      = "ENTER LAST NAME",
                            TextColor        = Color.Blue,
                            PlaceholderColor = Color.LightGray,
                        },
                    }
                }
            };
            softwareKeyboardTestButton.Clicked += (s, e) =>
            {
                softwareKeyboardTestPopup.OutlineColor      = Color.Blue;
                softwareKeyboardTestPopup.HasShadow         = _hasShadow;
                softwareKeyboardTestPopup.ShadowInverted    = _shadowInverted;
                softwareKeyboardTestPopup.OutlineWidth      = _blueOutline ? 1 : 0;
                softwareKeyboardTestPopup.IsVisible         = true;
                softwareKeyboardTestPopup.HorizontalOptions = LayoutOption(_hzLayoutOptions);
                softwareKeyboardTestPopup.VerticalOptions   = LayoutOption(_vtLayoutOptions);
            };
            #endregion

            Content = new Xamarin.Forms.ScrollView
            {
                Content = new Xamarin.Forms.StackLayout
                {
                    Children =
                    {
                        new BoxView {
                            HeightRequest = 1
                        },
                        _decoration,
                        new Forms9Patch.Label("HZ LAYOUT ALIGNMENT:"),
                        _hzLayoutOptions,
                        new Forms9Patch.Label("VT LAYOUT ALIGNMENT:"),
                        _vtLayoutOptions,
                        new BoxView {
                            HeightRequest = 1
                        },
                        showModalButton,
                        showBubbleLeftButton,
                        showBubbleRightButton,
                        showBubbleUpButton,
                        showBubbleDownButton,
                        showBubbleHzButton,
                        showBubbleVtButton,
                        showBubbleAnyButton,
                        showBubbleNoneButton,
                        bubbleTarget,
                        showActivityPopupButton,
                        showPermissionButton,
                        showToastButton,
                        showTargetedToash,
                        showTargetedMenu,
                        showVerticalTargetedMenu,
                        softwareKeyboardTestButton,
                        new BoxView {
                            HeightRequest = 1
                        },
                    }
                }
            };

            _decoration.SegmentTapped += (s, e) =>
            {
                switch (e.Segment.Text)
                {
                case _hasShadowText:
                    _hasShadow = !_hasShadow;
                    break;

                case _shadowInvertedText:
                    _shadowInverted = !_shadowInverted;
                    break;

                case _blueOutlineText:
                    _blueOutline = !_blueOutline;
                    break;
                }
            };

            BackgroundColor = Color.LightSlateGray;
        }
        public ButtonAndSegmentAlignments()
        {
            _grid1.Children.Add(new Xamarin.Forms.Label {
                Text = "HZ", VerticalTextAlignment = TextAlignment.Center, FontSize = 9
            }, 0, 0);
            _grid1.Children.Add(_hzAlignmentElement, 1, 0);
            _grid1.Children.Add(new Xamarin.Forms.Label {
                Text = "VT", VerticalTextAlignment = TextAlignment.Center, FontSize = 9
            }, 0, 1);
            _grid1.Children.Add(_vtAlignmentElement, 1, 1);
            _grid1.Children.Add(new Xamarin.Forms.Label {
                Text = "Opt", VerticalTextAlignment = TextAlignment.Center, FontSize = 9
            }, 0, 2);
            _grid1.Children.Add(_optionsElement, 1, 2);
            _grid1.Children.Add(new Xamarin.Forms.Label {
                Text = "Icon", VerticalTextAlignment = TextAlignment.Center, FontSize = 9
            }, 0, 3);
            _grid1.Children.Add(_iconElement, 1, 3);

            _grid2.Children.Add(new Xamarin.Forms.Label {
                Text = "Spacing:"
            }, 0, 0);
            _grid2.Children.Add(_spacingSlider, 0, 1);
            _grid2.Children.Add(new Xamarin.Forms.Label {
                Text = "Imposed Ht:"
            }, 1, 0);
            _grid2.Children.Add(_imposedHeightSwitch, 1, 1);
            _grid2.Children.Add(_outlineWidthLabel, 2, 0);
            _grid2.Children.Add(_outlineWidthSlider, 2, 1);
            _grid2.Children.Add(_outlineRadiusLabel, 3, 0);
            _grid2.Children.Add(_outlineRadiusSlider, 3, 1);

            _grid3.Children.Add(new Xamarin.Forms.Label {
                Text = "HasShadow:"
            }, 0, 0);
            _grid3.Children.Add(_hasShadowSwitch, 0, 1);

            Padding = new Thickness(40, 20, 20, 20);
            Content = new Xamarin.Forms.ScrollView
            {
                Content = new Xamarin.Forms.StackLayout
                {
                    Children =
                    {
                        new Xamarin.Forms.Label {
                            Text = "version 0.9.15.1"
                        },
                        new BoxView             {
                            HeightRequest = 1, Color = Color.Gray
                        },
                        _grid1,
                        new BoxView             {
                            HeightRequest = 1, Color = Color.Gray
                        },
                        _grid2,
                        new BoxView             {
                            HeightRequest = 1, Color = Color.Gray
                        },
                        _grid3,

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

                        _stateButton,
                        new BoxView             {
                            HeightRequest = 1, Color = Color.Gray
                        },
                        _button,
                        new BoxView             {
                            HeightRequest = 1, Color = Color.Gray
                        },
                        _hzSegmentsElement,
                        new BoxView             {
                            HeightRequest = 1, Color = Color.Gray
                        },
                        _vtSegmentsElement,
                        new BoxView             {
                            HeightRequest = 1, Color = Color.Gray
                        },
                        new Xamarin.Forms.Label {
                            Text = "Display.Scale=[" + Display.Scale + "]"
                        }
                    }
                }
            };

            _hasShadowSwitch.Toggled += (sender, e) =>
            {
                _hzAlignmentElement.HasShadow       = _hasShadowSwitch.IsToggled;
                _vtAlignmentElement.HasShadow       = _hasShadowSwitch.IsToggled;
                _optionsElement.HasShadow           = _hasShadowSwitch.IsToggled;
                _iconElement.HasShadow              = _hasShadowSwitch.IsToggled;
                _button.HasShadow                   = _hasShadowSwitch.IsToggled;
                _stateButton.DefaultState.HasShadow = _hasShadowSwitch.IsToggled;
                _hzSegmentsElement.HasShadow        = _hasShadowSwitch.IsToggled;
                _vtSegmentsElement.HasShadow        = _hasShadowSwitch.IsToggled;
            };

            _hzAlignmentElement.SegmentTapped += (sender, e) =>
            {
                var buttonText = string.Concat(e.Segment.Text.ToUpper().Substring(0, 1), e.Segment.Text.ToLower().Substring(1));
                if (!Enum.TryParse <TextAlignment>(buttonText, out TextAlignment alignment))
                {
                    throw new Exception("doh");
                }
                _labelElement.HorizontalTextAlignment             = alignment;
                _button.HorizontalTextAlignment                   = alignment;
                _stateButton.DefaultState.HorizontalTextAlignment = alignment;
                _hzSegmentsElement.HorizontalTextAlignment        = alignment;
                _vtSegmentsElement.HorizontalTextAlignment        = alignment;
            };

            _vtAlignmentElement.SegmentTapped += (sender, e) =>
            {
                var buttonText = string.Concat(e.Segment.Text.ToUpper().Substring(0, 1), e.Segment.Text.ToLower().Substring(1));
                if (!Enum.TryParse <TextAlignment>(buttonText, out TextAlignment alignment))
                {
                    throw new Exception("doh");
                }
                _labelElement.VerticalTextAlignment             = alignment;
                _button.VerticalTextAlignment                   = alignment;
                _stateButton.DefaultState.VerticalTextAlignment = alignment;
                _hzSegmentsElement.VerticalTextAlignment        = alignment;
                _vtSegmentsElement.VerticalTextAlignment        = alignment;
            };

            _optionsElement.SegmentTapped += (sender, e) =>
            {
                var options = new List <string>();
                foreach (var segment in _optionsElement.SelectedSegments)
                {
                    options.Add(segment.Text.ToUpper());
                }
                var hasTightSpacing = options.Contains("TIGHT");
                var trailingIcon    = options.Contains("TRAILING");
                var orientation     = options.Contains("VERTICAL") ? StackOrientation.Vertical : StackOrientation.Horizontal;


                _button.HasTightSpacing = hasTightSpacing;
                _button.TrailingIcon    = trailingIcon;
                _button.Orientation     = orientation;

                _stateButton.DefaultState.HasTightSpacing = hasTightSpacing;
                _stateButton.DefaultState.TrailingIcon    = trailingIcon;
                _stateButton.DefaultState.Orientation     = orientation;

                _hzSegmentsElement.HasTightSpacing         = hasTightSpacing;
                _hzSegmentsElement.TrailingIcon            = trailingIcon;
                _hzSegmentsElement.IntraSegmentOrientation = orientation;

                _vtSegmentsElement.HasTightSpacing         = hasTightSpacing;
                _vtSegmentsElement.TrailingIcon            = trailingIcon;
                _vtSegmentsElement.IntraSegmentOrientation = orientation;
            };

            _iconElement.SegmentTapped += (sender, e) =>
            {
                //if (e.Segment.IconImage != null)
                //{

                /*
                 * _iconTextAndTextButton.IconImage = new Forms9Patch.Image { Source = Forms9Patch.ImageSource.FromMultiResource("Forms9PatchDemo.Resources.Info") };
                 * foreach (var segment in _hzSegmentsElement.Segments)
                 *  segment.IconImage = new Forms9Patch.Image { Source = Forms9Patch.ImageSource.FromMultiResource("Forms9PatchDemo.Resources.Info") };
                 * foreach (var segment in _vtSegmentsElement.Segments)
                 *  segment.IconImage = new Forms9Patch.Image { Source = Forms9Patch.ImageSource.FromMultiResource("Forms9PatchDemo.Resources.Info") };
                 */
                SetIconImage(e.Segment.IconImage);
                //}
                //else
                SetIconText(e.Segment.HtmlText ?? e.Segment.Text);
            };

            _spacingSlider.ValueChanged += (sender, e) =>
            {
                _button.Spacing = _spacingSlider.Value;
                //_stateButton.Spacing = _spacingSlider.Value;
                _stateButton.DefaultState.Spacing      = _spacingSlider.Value;
                _hzSegmentsElement.IntraSegmentSpacing = _spacingSlider.Value;
                _vtSegmentsElement.IntraSegmentSpacing = _spacingSlider.Value;
            };

            _imposedHeightSwitch.Toggled += (sender, e) =>
            {
                _button.HeightRequest            = _imposedHeightSwitch.IsToggled ? 60 : -1;
                _stateButton.HeightRequest       = _imposedHeightSwitch.IsToggled ? 60 : -1;
                _hzSegmentsElement.HeightRequest = _imposedHeightSwitch.IsToggled ? 60 : -1;
                _vtSegmentsElement.HeightRequest = _imposedHeightSwitch.IsToggled ? 180 : -1;

                _vtAlignmentElement.IsEnabled = _imposedHeightSwitch.IsToggled;
                if (!_vtAlignmentElement.IsEnabled)
                {
                    _vtAlignmentElement.DeselectAll();
                }
            };

            _outlineRadiusSlider.ValueChanged += (sender, e) =>
            {
                int value = (int)_outlineRadiusSlider.Value;
                _hzAlignmentElement.OutlineRadius       = value;
                _vtAlignmentElement.OutlineRadius       = value;
                _button.OutlineRadius                   = value;
                _stateButton.DefaultState.OutlineRadius = value;
                _optionsElement.OutlineRadius           = value;
                _iconElement.OutlineRadius              = value;
                _hzSegmentsElement.OutlineRadius        = value;
                _vtSegmentsElement.OutlineRadius        = value;
                _outlineRadiusLabel.Text                = "line R: " + value;
            };

            _outlineWidthSlider.Effects.Add(new Forms9Patch.SliderStepSizeEffect(0.5));
            _outlineWidthSlider.ValueChanged += (sender, e) =>
            {
                float value = (float)_outlineWidthSlider.Value; // (float)(Math.Round(_outlineWidthSlider.Value*2.0)/2.0);
                _hzAlignmentElement.OutlineWidth       = value;
                _vtAlignmentElement.OutlineWidth       = value;
                _button.OutlineWidth                   = value;
                _stateButton.DefaultState.OutlineWidth = value;
                _optionsElement.OutlineWidth           = value;
                _iconElement.OutlineWidth              = value;
                _hzSegmentsElement.OutlineWidth        = value;
                _vtSegmentsElement.OutlineWidth        = value;
                _outlineWidthLabel.Text                = "line W: " + _outlineWidthSlider.Value;// + value;
            };

            var defaultHzAlignment = _button.HorizontalTextAlignment;

            if (defaultHzAlignment == TextAlignment.Start)
            {
                _hzAlignmentElement.SelectIndex(0);
            }
            else if (defaultHzAlignment == TextAlignment.Center)
            {
                _hzAlignmentElement.SelectIndex(1);
            }
            else
            {
                _hzAlignmentElement.SelectIndex(2);
            }


            _iconElement.SelectIndex(0);
            _vtAlignmentElement.IsEnabled = false;
        }
        public EmbeddedResourceFontEffectPage()
        {
            Forms9Patch.EmbeddedResourceFontEffect.ApplyTo(_label);
            _editor.Effects.Add(new Forms9Patch.EmbeddedResourceFontEffect());
            _entry.Effects.Add(new Forms9Patch.EmbeddedResourceFontEffect());

            Forms9Patch.SegmentedControl segmentedControl = new SegmentedControl
            {
                Margin     = new Thickness(10, 0),
                FontFamily = "Forms9PatchDemo.Resources.Fonts.Pacifico.ttf",
                Segments   =
                {
                    new Forms9Patch.Segment("label"),
                    new Forms9Patch.Segment("editor"),
                    new Forms9Patch.Segment("entry"),
                }
            };

            Content = new Xamarin.Forms.StackLayout
            {
                Children =
                {
                    _label,
                    _editor,
                    _entry,
                    new Xamarin.Forms.Label {
                        Text = "Focus:"
                    },
                    segmentedControl
                }
            };

            segmentedControl.SegmentTapped += (sender, e) =>
            {
                switch (e.Segment.Text)
                {
                case "label": _label.HardwareKeyFocus(); break;

                case "editor": _editor.HardwareKeyFocus(); break;

                case "entry": _entry.HardwareKeyFocus(); break;
                }
            };

            HardwareKeyPage.FocusedElementChanged += (sender, e) =>
            {
                if (sender == _label)
                {
                    segmentedControl.SelectIndex(0);
                }
                else if (sender == _editor)
                {
                    segmentedControl.SelectIndex(1);
                }
                else if (sender == _entry)
                {
                    segmentedControl.SelectIndex(2);
                }
                else
                {
                    segmentedControl.DeselectAll();
                }
            };

            _label.Focused  += (sender, e) => System.Diagnostics.Debug.WriteLine("label.Focused " + e.IsFocused);
            _editor.Focused += (sender, e) => System.Diagnostics.Debug.WriteLine("editor.Focused " + e.IsFocused);
            _entry.Focused  += (sender, e) => System.Diagnostics.Debug.WriteLine("entry.Focused " + e.IsFocused);

            _label.Unfocused  += (sender, e) => System.Diagnostics.Debug.WriteLine("label.Unfocused " + e.IsFocused);
            _editor.Unfocused += (sender, e) => System.Diagnostics.Debug.WriteLine("editor.Unfocused " + e.IsFocused);
            _entry.Unfocused  += (sender, e) => System.Diagnostics.Debug.WriteLine("entry.Unfocused " + e.IsFocused);

            _label.FocusChangeRequested  += (object sender, FocusRequestArgs e) => System.Diagnostics.Debug.WriteLine("label.FocusChangeRequested ");
            _editor.FocusChangeRequested += (object sender, FocusRequestArgs e) => System.Diagnostics.Debug.WriteLine("editor.FocusChangeRequested ");
            _entry.FocusChangeRequested  += (object sender, FocusRequestArgs e) => System.Diagnostics.Debug.WriteLine("entry.FocusChangeRequested ");

            this.AddHardwareKeyListener("ç", OnHardwareKeyPressed);
            this.AddHardwareKeyListener("é", OnHardwareKeyPressed);
            this.AddHardwareKeyListener("ф", OnHardwareKeyPressed);

            this.AddHardwareKeyListener("A", OnHardwareKeyPressed);
            this.AddHardwareKeyListener("a", HardwareKeyModifierKeys.PlatformKey, OnHardwareKeyPressed);
            this.AddHardwareKeyListener("a", HardwareKeyModifierKeys.Control, OnHardwareKeyPressed);
            this.AddHardwareKeyListener("a", HardwareKeyModifierKeys.Alternate, OnHardwareKeyPressed);
            this.AddHardwareKeyListener("a", HardwareKeyModifierKeys.CapsLock, OnHardwareKeyPressed);
            this.AddHardwareKeyListener("a", HardwareKeyModifierKeys.FunctionKey, OnHardwareKeyPressed);
            this.AddHardwareKeyListener("a", HardwareKeyModifierKeys.Shift, OnHardwareKeyPressed);
            this.AddHardwareKeyListener("a", HardwareKeyModifierKeys.Shift | HardwareKeyModifierKeys.Alternate, OnHardwareKeyPressed);
            this.AddHardwareKeyListener("a", HardwareKeyModifierKeys.Shift | HardwareKeyModifierKeys.Control, OnHardwareKeyPressed);
            this.AddHardwareKeyListener("a", HardwareKeyModifierKeys.Shift | HardwareKeyModifierKeys.PlatformKey, OnHardwareKeyPressed);
            this.AddHardwareKeyListener("a", HardwareKeyModifierKeys.Control | HardwareKeyModifierKeys.Alternate, OnHardwareKeyPressed);
            this.AddHardwareKeyListener("a", HardwareKeyModifierKeys.Control | HardwareKeyModifierKeys.PlatformKey, OnHardwareKeyPressed);


            this.AddHardwareKeyListener("5", OnHardwareKeyPressed);
            this.AddHardwareKeyListener("5", HardwareKeyModifierKeys.NumericPadKey, OnHardwareKeyPressed);
            this.AddHardwareKeyListener("5", HardwareKeyModifierKeys.PlatformKey, OnHardwareKeyPressed);
            this.AddHardwareKeyListener("5", HardwareKeyModifierKeys.Control, OnHardwareKeyPressed);
            this.AddHardwareKeyListener("5", HardwareKeyModifierKeys.Alternate, OnHardwareKeyPressed);
            this.AddHardwareKeyListener("5", HardwareKeyModifierKeys.CapsLock, OnHardwareKeyPressed);
            this.AddHardwareKeyListener("5", HardwareKeyModifierKeys.FunctionKey, OnHardwareKeyPressed);
            this.AddHardwareKeyListener("5", HardwareKeyModifierKeys.Shift, OnHardwareKeyPressed);



            this.AddHardwareKeyListener("/", OnHardwareKeyPressed);
            this.AddHardwareKeyListener("/", HardwareKeyModifierKeys.Alternate, OnHardwareKeyPressed);

            this.AddHardwareKeyListener(HardwareKey.UpArrowKeyInput, OnHardwareKeyPressed);
            this.AddHardwareKeyListener(HardwareKey.DownArrowKeyInput, OnHardwareKeyPressed);
            this.AddHardwareKeyListener(HardwareKey.LeftArrowKeyInput, OnHardwareKeyPressed);
            this.AddHardwareKeyListener(HardwareKey.RightArrowKeyInput, OnHardwareKeyPressed);
            this.AddHardwareKeyListener(HardwareKey.EscapeKeyInput, OnHardwareKeyPressed);
            this.AddHardwareKeyListener(HardwareKey.BackspaceDeleteKeyInput, OnHardwareKeyPressed);
            this.AddHardwareKeyListener(HardwareKey.ForwardDeleteKeyInput, OnHardwareKeyPressed);
            this.AddHardwareKeyListener(HardwareKey.InsertKeyInput, OnHardwareKeyPressed);
            this.AddHardwareKeyListener(HardwareKey.TabKeyInput, OnHardwareKeyPressed);
            this.AddHardwareKeyListener(HardwareKey.EnterReturnKeyInput, OnHardwareKeyPressed);
            this.AddHardwareKeyListener(HardwareKey.PageUpKeyInput, OnHardwareKeyPressed);
            this.AddHardwareKeyListener(HardwareKey.PageDownKeyInput, OnHardwareKeyPressed);
            this.AddHardwareKeyListener(HardwareKey.HomeKeyInput, OnHardwareKeyPressed);
            this.AddHardwareKeyListener(HardwareKey.EndKeyInput, OnHardwareKeyPressed);

            _entry.AddHardwareKeyListener(HardwareKey.UpArrowKeyInput, OnHardwareKeyPressed);
            _entry.AddHardwareKeyListener(HardwareKey.DownArrowKeyInput, OnHardwareKeyPressed);
            _entry.AddHardwareKeyListener(HardwareKey.LeftArrowKeyInput, OnHardwareKeyPressed);
            _entry.AddHardwareKeyListener(HardwareKey.RightArrowKeyInput, OnHardwareKeyPressed);
            _entry.AddHardwareKeyListener(HardwareKey.EscapeKeyInput, OnHardwareKeyPressed);

            _editor.AddHardwareKeyListener(HardwareKey.UpArrowKeyInput, OnHardwareKeyPressed);
            _editor.AddHardwareKeyListener(HardwareKey.DownArrowKeyInput, OnHardwareKeyPressed);
            _editor.AddHardwareKeyListener(HardwareKey.LeftArrowKeyInput, OnHardwareKeyPressed);
            _editor.AddHardwareKeyListener(HardwareKey.RightArrowKeyInput, OnHardwareKeyPressed);
            _editor.AddHardwareKeyListener(HardwareKey.EscapeKeyInput, OnHardwareKeyPressed);

            _label.AddHardwareKeyListener(HardwareKey.UpArrowKeyInput, OnHardwareKeyPressed);
            _label.AddHardwareKeyListener(HardwareKey.DownArrowKeyInput, OnHardwareKeyPressed);
            _label.AddHardwareKeyListener(HardwareKey.LeftArrowKeyInput, OnHardwareKeyPressed);
            _label.AddHardwareKeyListener(HardwareKey.RightArrowKeyInput, OnHardwareKeyPressed);
            _label.AddHardwareKeyListener(HardwareKey.EscapeKeyInput, OnHardwareKeyPressed);
        }
Exemple #6
0
        public ImageButtonAlignments()
        {
            _grid1.Children.Add(new Xamarin.Forms.Label {
                Text = "HZ", VerticalTextAlignment = TextAlignment.Center, FontSize = 9
            }, 0, 0);
            _grid1.Children.Add(_hzAlignmentElement, 1, 0);
            _grid1.Children.Add(new Xamarin.Forms.Label {
                Text = "VT", VerticalTextAlignment = TextAlignment.Center, FontSize = 9
            }, 0, 1);
            _grid1.Children.Add(_vtAlignmentElement, 1, 1);
            _grid1.Children.Add(new Xamarin.Forms.Label {
                Text = "Opt", VerticalTextAlignment = TextAlignment.Center, FontSize = 9
            }, 0, 2);
            _grid1.Children.Add(_optionsElement, 1, 2);
            //_grid1.Children.Add(new Xamarin.Forms.Label { Text = "Icon", VerticalTextAlignment = TextAlignment.Center, FontSize = 9 }, 0, 3);
            //_grid1.Children.Add(_iconElement, 1, 3);

            _grid2.Children.Add(new Xamarin.Forms.Label {
                Text = "Spacing:"
            }, 0, 0);
            _grid2.Children.Add(_spacingSlider, 0, 1);
            _grid2.Children.Add(new Xamarin.Forms.Label {
                Text = "Imposed Ht:"
            }, 1, 0);
            _grid2.Children.Add(_imposedHeightSwitch, 1, 1);


            _iconTextAndTextButton.Tapped       += (sender, e) => System.Diagnostics.Debug.WriteLine("Tapped");
            _iconTextAndTextButton.LongPressed  += (sender, e) => System.Diagnostics.Debug.WriteLine("LongPressed");
            _iconTextAndTextButton.LongPressing += (sender, e) => System.Diagnostics.Debug.WriteLine("LongPressing");

            Padding = new Thickness(40, 20, 20, 20);
            Content = new Xamarin.Forms.ScrollView
            {
                Content = new Xamarin.Forms.StackLayout
                {
                    Children =
                    {
                        _grid1,
                        _grid2,


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

                        _iconTextAndTextButton,
                    }
                }
            };

            _hzAlignmentElement.SegmentTapped += (sender, e) =>
            {
                TextAlignment alignment;
                var           buttonText = string.Concat(e.Segment.Text.ToUpper().Substring(0, 1), e.Segment.Text.ToLower().Substring(1));
                if (!Enum.TryParse <TextAlignment>(buttonText, out alignment))
                {
                    throw new Exception("doh");
                }
                _labelElement.HorizontalTextAlignment          = alignment;
                _iconTextAndTextButton.HorizontalTextAlignment = alignment;
            };

            _vtAlignmentElement.SegmentTapped += (sender, e) =>
            {
                TextAlignment alignment;
                var           buttonText = string.Concat(e.Segment.Text.ToUpper().Substring(0, 1), e.Segment.Text.ToLower().Substring(1));
                if (!Enum.TryParse <TextAlignment>(buttonText, out alignment))
                {
                    throw new Exception("doh");
                }
                _labelElement.VerticalTextAlignment          = alignment;
                _iconTextAndTextButton.VerticalTextAlignment = alignment;
            };

            _optionsElement.SegmentTapped += (sender, e) =>
            {
                _iconTextAndTextButton.HasTightSpacing = _optionsElement.IsIndexSelected(0);
                _iconTextAndTextButton.TrailingIcon    = _optionsElement.IsIndexSelected(1);
                _iconTextAndTextButton.Orientation     = _optionsElement.IsIndexSelected(2) ? StackOrientation.Vertical : StackOrientation.Horizontal;
            };

            _iconElement.SegmentTapped += (sender, e) =>
            {
                if (e.Segment.IconImage != null)
                {
                    _iconTextAndTextButton.IconImage = new Forms9Patch.Image {
                        Source = e.Segment.IconImage.Source
                    }
                }
                ;                                                                                                     // Forms9Patch.ImageSource.FromMultiResource("Forms9PatchDemo.Resources.Info");
                else
                {
                    SetIconText(e.Segment.HtmlText);
                }
            };

            _spacingSlider.ValueChanged += (sender, e) =>
            {
                _iconTextAndTextButton.Spacing = _spacingSlider.Value;
            };

            _imposedHeightSwitch.Toggled += (sender, e) =>
            {
                _iconTextAndTextButton.HeightRequest = _imposedHeightSwitch.IsToggled ? 60 : -1;

                _vtAlignmentElement.IsEnabled = _imposedHeightSwitch.IsToggled;
                if (!_vtAlignmentElement.IsEnabled)
                {
                    _vtAlignmentElement.DeselectAll();
                }
            };

            var defaultHzAlignment = _iconTextAndTextButton.HorizontalTextAlignment;

            if (defaultHzAlignment == TextAlignment.Start)
            {
                _hzAlignmentElement.SelectIndex(0);
            }
            else if (defaultHzAlignment == TextAlignment.Center)
            {
                _hzAlignmentElement.SelectIndex(1);
            }
            else
            {
                _hzAlignmentElement.SelectIndex(2);
            }


            _iconElement.SelectIndex(0);
            _vtAlignmentElement.IsEnabled = false;
        }