Beispiel #1
0
        public override View CreateNativeView(int index)
        {
            Console.WriteLine($"CreateNativeView... for {index}");

            var rnd  = new Random();
            var view = new View();

            view.UpdateBackgroundColor(Color.FromRgb(rnd.Next(10, 255), rnd.Next(10, 255), rnd.Next(10, 255)));

            view.Add(new TextLabel
            {
                Text = $"Text for{index}"
            });
            return(view);
        }
        public override View Run()
        {
            var view = new View
            {
                Layout = new LinearLayout
                {
                    LinearAlignment   = LinearLayout.Alignment.Center,
                    LinearOrientation = LinearLayout.Orientation.Vertical,
                }
            };
            var menu = new View
            {
                Layout = new LinearLayout
                {
                    LinearOrientation = LinearLayout.Orientation.Horizontal
                },
                SizeHeight         = 200,
                WidthSpecification = LayoutParamPolicies.MatchParent,
                BackgroundColor    = Color.Green.ToNative()
            };

            view.Add(menu);


            var scrollView = new ScrollView()
            {
                WidthSpecification  = LayoutParamPolicies.MatchParent,
                HeightSpecification = LayoutParamPolicies.MatchParent,
            };

            int itemWidth  = 300;
            int itemHeight = 300;
            int itemCols   = 10;
            int itemRows   = 10;

            var outterLayout = new View
            {
                Layout = new LinearLayout
                {
                    LinearOrientation = LinearLayout.Orientation.Vertical,
                },
                SizeWidth  = itemWidth * itemCols,
                SizeHeight = itemHeight * itemRows
            };

            scrollView.Add(outterLayout);

            for (int i = 0; i < itemRows; i++)
            {
                var innerLayout = new View
                {
                    Layout = new LinearLayout
                    {
                        LinearOrientation = LinearLayout.Orientation.Horizontal,
                    },
                    SizeHeight = itemHeight,
                    SizeWidth  = itemWidth * itemCols,
                };
                for (int j = 0; j < itemCols; j++)
                {
                    var rnd  = new Random();
                    var item = new View
                    {
                        SizeWidth       = itemWidth,
                        SizeHeight      = itemHeight,
                        BackgroundColor = Color.FromRgb(rnd.Next(10, 255), rnd.Next(10, 255), rnd.Next(10, 255)).ToNative()
                    };
                    innerLayout.Add(item);
                }
                outterLayout.Add(innerLayout);
            }
            scrollView.ScrollingEventThreshold = 1;
            scrollView.ScrollDragStarted      += (s, e) => Console.WriteLine($"DragStarted");
            scrollView.ScrollDragEnded        += (s, e) => Console.WriteLine("DragEnd");
            scrollView.ScrollAnimationStarted += (s, e) => Console.WriteLine($"ScrollAnimation started");
            scrollView.ScrollAnimationEnded   += (s, e) => Console.WriteLine("$ScrollAnimation ended");
            scrollView.Scrolling += (s, e) =>
            {
                Console.WriteLine($"OnScrolling : Bound : {scrollView.ScrollBound} - {e.Position.X}x{e.Position.Y}");
            };


            var direction = new Button()
            {
                Text       = "direction(V)",
                SizeHeight = 300,
                SizeWidth  = 300,
            };

            direction.Clicked += (s, e) =>
            {
                if (scrollView.ScrollOrientation == ScrollOrientation.Horizontal)
                {
                    scrollView.ScrollOrientation = ScrollOrientation.Vertical;
                    direction.Text = "direction(V)";
                }
                else
                {
                    scrollView.ScrollOrientation = ScrollOrientation.Horizontal;
                    direction.Text = "direction(H)";
                }
            };
            menu.Add(direction);

            var scrollBar = new Button()
            {
                Text       = "Bar(Never)",
                SizeHeight = 300,
                SizeWidth  = 300,
            };

            scrollBar.Clicked += (s, e) =>
            {
                if (scrollView.VerticalScrollBarVisibility == ScrollBarVisibility.Never)
                {
                    scrollView.VerticalScrollBarVisibility = ScrollBarVisibility.Default;
                    scrollBar.Text = "Bar(Default)";
                }
                else if (scrollView.VerticalScrollBarVisibility == ScrollBarVisibility.Default)
                {
                    scrollView.VerticalScrollBarVisibility = ScrollBarVisibility.Always;
                    scrollBar.Text = "Bar(Always)";
                }
                else if (scrollView.VerticalScrollBarVisibility == ScrollBarVisibility.Always)
                {
                    scrollView.VerticalScrollBarVisibility = ScrollBarVisibility.Never;
                    scrollBar.Text = "Bar(Never)";
                }
            };
            menu.Add(scrollBar);


            view.Add(scrollView);
            return(view);
        }
Beispiel #3
0
        public override View Run()
        {
            var view = new View
            {
                Layout = new LinearLayout
                {
                    LinearAlignment   = LinearLayout.Alignment.Center,
                    LinearOrientation = LinearLayout.Orientation.Vertical,
                }
            };
            var menu = new View
            {
                Layout = new LinearLayout
                {
                    LinearOrientation = LinearLayout.Orientation.Horizontal
                },
                SizeHeight         = 200,
                WidthSpecification = LayoutParamPolicies.MatchParent,
                BackgroundColor    = Color.Green.ToNative()
            };

            view.Add(menu);


            var scrollView = new ScrollView()
            {
                WidthSpecification  = LayoutParamPolicies.MatchParent,
                HeightSpecification = LayoutParamPolicies.MatchParent,
            };

            int itemWidth  = 300;
            int itemHeight = 300;
            int itemCols   = 10;
            int itemRows   = 10;

            var outterLayout = new View
            {
                Layout = new LinearLayout
                {
                    LinearOrientation = LinearLayout.Orientation.Vertical,
                },
                SizeWidth  = itemWidth * itemCols,
                SizeHeight = itemHeight * itemRows
            };

            scrollView.Add(outterLayout);

            for (int i = 0; i < itemRows; i++)
            {
                var innerLayout = new View
                {
                    Layout = new LinearLayout
                    {
                        LinearOrientation = LinearLayout.Orientation.Horizontal,
                    },
                    SizeHeight = itemHeight,
                    SizeWidth  = itemWidth * itemCols,
                };
                for (int j = 0; j < itemCols; j++)
                {
                    var rnd  = new Random();
                    var item = new View
                    {
                        SizeWidth       = itemWidth,
                        SizeHeight      = itemHeight,
                        BackgroundColor = Color.FromRgb(rnd.Next(10, 255), rnd.Next(10, 255), rnd.Next(10, 255)).ToNative()
                    };
                    innerLayout.Add(item);
                }
                outterLayout.Add(innerLayout);
            }

            scrollView.Scrolling += (s, e) =>
            {
                Console.WriteLine($"OnScrolling : Bound : {scrollView.ScrollBound}");
            };


            var direction = new Button()
            {
                Text       = "direction(V)",
                SizeHeight = 300,
                SizeWidth  = 300,
            };

            direction.Clicked += (s, e) =>
            {
                if (scrollView.ScrollOrientation == ScrollOrientation.Horizontal)
                {
                    scrollView.ScrollOrientation = ScrollOrientation.Vertical;
                    direction.Text = "direction(V)";
                }
                else
                {
                    scrollView.ScrollOrientation = ScrollOrientation.Horizontal;
                    direction.Text = "direction(H)";
                }
            };
            menu.Add(direction);

            var scrollBar = new Button()
            {
                Text       = "Bar(X)",
                SizeHeight = 300,
                SizeWidth  = 300,
            };

            scrollBar.Clicked += (s, e) =>
            {
                if (scrollView.HideScrollbar)
                {
                    scrollView.HideScrollbar = false;
                    scrollBar.Text           = "Bar(O)";
                }
                else
                {
                    scrollView.HideScrollbar = true;
                    scrollBar.Text           = "Bar(X)";
                }
            };
            menu.Add(scrollBar);


            view.Add(scrollView);
            return(view);
        }
Beispiel #4
0
        protected override View CreateContent()
        {
            Layout = new LinearLayout
            {
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center
            };
            BackgroundColor = new TColor(0.1f, 0.1f, 0.1f, 0.5f).ToNative();
            var margin1 = (ushort)20d.ToPixel();
            var margin2 = (ushort)10d.ToPixel();
            var radius  = 8d.ToPixel();

            var isHorizontal = Window.Instance.WindowSize.Width > Window.Instance.WindowSize.Height;
            // container
            var content = new View
            {
                CornerRadius = radius,
                BoxShadow    = new Shadow(20d.ToPixel(), TColor.Black.ToNative()),
                Layout       = new LinearLayout
                {
                    VerticalAlignment   = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    LinearOrientation   = LinearLayout.Orientation.Vertical,
                },
                SizeWidth       = Window.Instance.WindowSize.Width * (isHorizontal ? 0.5f : 0.8f),
                BackgroundColor = TColor.White.ToNative(),
            };

            // title
            content.Add(new Label
            {
                Text                    = _title,
                Margin                  = new Extents(margin1, margin1, margin1, margin2),
                WidthSpecification      = LayoutParamPolicies.MatchParent,
                HorizontalTextAlignment = TextAlignment.Start,
                VerticalTextAlignment   = TextAlignment.Center,
                FontAttributes          = FontAttributes.Bold,
                TextColor               = TColor.FromHex("#000000"),
                PixelSize               = 21d.ToPixel(),
            });

            // message
            content.Add(new Label
            {
                Text               = _message,
                Margin             = new Extents(margin1, margin1, 0, margin2),
                LineBreakMode      = LineBreakMode.CharacterWrap,
                PixelSize          = 16d.ToPixel(),
                WidthSpecification = LayoutParamPolicies.MatchParent,
            });

            var entry = new Entry
            {
                Margin                = new Extents(margin1, margin1, 0, margin2),
                Text                  = _initialValue,
                Keyboard              = _keyboard,
                Placeholder           = _placeholder ?? "",
                WidthSpecification    = LayoutParamPolicies.MatchParent,
                PlaceholderColor      = TColor.FromRgb(100, 100, 100),
                VerticalTextAlignment = TextAlignment.Center,
                SizeHeight            = 40d.ToPixel(),
                PixelSize             = 16d.ToPixel(),
                BackgroundColor       = TColor.FromRgb(220, 220, 220).ToNative(),
            };

            if (_maxLength != -1)
            {
                entry.MaxLength = _maxLength;
            }
            content.Add(entry);

            var hlayout = new View
            {
                Margin = new Extents(margin1, margin1, 0, margin1),
                Layout = new LinearLayout
                {
                    HorizontalAlignment = HorizontalAlignment.End,
                    LinearOrientation   = LinearLayout.Orientation.Horizontal,
                },
                WidthSpecification  = LayoutParamPolicies.MatchParent,
                HeightSpecification = LayoutParamPolicies.WrapContent
            };

            content.Add(hlayout);

            var cancelButton = new Button
            {
                Text      = _cancel,
                Focusable = true,

                SizeWidth           = (_cancel.Length + 1) * 15d.ToPixel(),
                HeightSpecification = LayoutParamPolicies.WrapContent,

                TextColor       = TColor.Black,
                BackgroundColor = TColor.Transparent.ToNative(),
            };

            cancelButton.TextLabel.PixelSize = 15d.ToPixel();
            cancelButton.SizeWidth           = cancelButton.TextLabel.NaturalSize.Width + 15d.ToPixel() * 2;

            cancelButton.Clicked += (s, e) => SendCancel();
            hlayout.Add(cancelButton);

            var acceptButton = new Button
            {
                Text      = _accept,
                Focusable = true,

                SizeWidth           = (_accept.Length + 1) * 15d.ToPixel(),
                HeightSpecification = LayoutParamPolicies.WrapContent,
                Margin = new Extents(40, 0, 0, 0),

                TextColor       = TColor.Black,
                BackgroundColor = TColor.Transparent.ToNative(),
            };

            acceptButton.TextLabel.PixelSize = 15d.ToPixel();
            acceptButton.SizeWidth           = acceptButton.TextLabel.NaturalSize.Width + 15d.ToPixel() * 2;

            acceptButton.Clicked += (s, e) => SendSubmit(entry.Text);
            hlayout.Add(acceptButton);

            Relayout += (s, e) =>
            {
                var isHorizontal = Window.Instance.WindowSize.Width > Window.Instance.WindowSize.Height;
                content.SizeWidth = Window.Instance.WindowSize.Width * (isHorizontal ? 0.5f : 0.8f);
            };

            return(content);
        }