Exemplo n.º 1
0
        protected override void OnLayout(bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom)
        {
            LayoutLength childTop  = new LayoutLength(0);
            LayoutLength childLeft = new LayoutLength(0);

            var height = bottom - top;
            var width  = right - left;
            var middle = width / 2;

            uint count          = ChildCount;
            var  childIncrement = 0;

            if (count > 0)
            {
                childIncrement = height.Value / System.Convert.ToInt32(count);
            }
            var center = childIncrement / 2;

            var view = Owner;
            ViewLayoutDirectionType layoutDirection = view.LayoutDirection;

            for (uint i = 0; i < ChildCount; ++i)
            {
                childLayouts[i] = GetChildAt(i);
            }

            for (uint i = 0; i < count; i++)
            {
                uint itemIndex;
                if (layoutDirection == ViewLayoutDirectionType.RTL)
                {
                    itemIndex = count - 1 - i;
                }
                else
                {
                    itemIndex = i;
                }

                var childLayout = childLayouts[itemIndex];
                if (childLayout)
                {
                    var childWidth  = childLayout.MeasuredWidth;
                    var childHeight = childLayout.MeasuredHeight;

                    childLeft = middle - (childWidth / 2);

                    var topPosition = childTop + center - childHeight / 2;

                    childLayout.Layout(childLeft, topPosition, childLeft + childWidth, topPosition + childHeight);
                    childTop += childIncrement;

                    Console.WriteLine($"CustomLayoutVertical child layout is not NULL! childWidth={childWidth.Value}, i={i}");
                }
            }
            Console.WriteLine($"CustomLayoutVertical OnLayout() END");
        }
        protected override void OnLayout(bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom)
        {
            LayoutLength childTop  = new LayoutLength(0);
            LayoutLength childLeft = new LayoutLength(0);

            // We want to vertically align the children to the middle
            var height = bottom - top;
            var middle = height / 2;

            // Horizontally align the children to the middle of the space they are given too
            var  width          = right - left;
            uint count          = ChildCount;
            var  childIncrement = 0;

            if (count > 0)
            {
                childIncrement = width.Value / System.Convert.ToInt32(count);
            }
            var center = childIncrement / 2;

            // Check layout direction
            var view = GetOwner();
            ViewLayoutDirectionType layoutDirection = view.LayoutDirection;

            for (uint i = 0; i < count; i++)
            {
                uint itemIndex;
                // If RTL, then layout the last item first
                if (layoutDirection == ViewLayoutDirectionType.RTL)
                {
                    itemIndex = count - 1 - i;
                }
                else
                {
                    itemIndex = i;
                }

                LayoutItem childLayout = GetChildAt(itemIndex);
                if (childLayout)
                {
                    var childWidth  = childLayout.MeasuredWidth;
                    var childHeight = childLayout.MeasuredHeight;

                    childTop = middle - (childHeight / 2);

                    var leftPosition = childLeft + center - childWidth / 2;

                    childLayout.Layout(leftPosition, childTop, leftPosition + childWidth, childTop + childHeight);
                    childLeft += childIncrement;
                }
            }
        }
Exemplo n.º 3
0
        protected override void OnLayout(bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom)
        {
            LayoutLength childLeft = new LayoutLength(0);

            // We want to vertically align the children to the middle
            LayoutLength height = bottom - top;
            float        middle = height.AsDecimal() / 2;

            // Horizontally align the children to the middle of the space they are given too
            LayoutLength width          = right - left;
            int          count          = LayoutChildren.Count;
            int          childIncrement = 0;

            if (count > 0)
            {
                childIncrement = (int)System.Math.Ceiling(width.AsDecimal() / count);
            }
            float center = childIncrement / 2;

            // Check layout direction
            var view = Owner;
            ViewLayoutDirectionType layoutDirection = view.LayoutDirection;

            for (int i = 0; i < count; i++)
            {
                int itemIndex = i;
                // If RTL, then layout the last item first
                if (layoutDirection == ViewLayoutDirectionType.RTL)
                {
                    itemIndex = count - 1 - i;
                }

                LayoutItem childLayout = LayoutChildren[itemIndex];
                if (childLayout != null)
                {
                    LayoutLength childWidth  = childLayout.MeasuredWidth.Size;
                    LayoutLength childHeight = childLayout.MeasuredHeight.Size;

                    LayoutLength childTop = new LayoutLength(middle - (childHeight.AsDecimal() / 2));

                    LayoutLength leftPosition = new LayoutLength(childLeft.AsDecimal() + center - childWidth.AsDecimal() / 2);

                    childLayout.Layout(leftPosition,
                                       childTop,
                                       leftPosition + childWidth,
                                       childTop + childHeight);
                    childLeft += new LayoutLength(childIncrement);
                }
            }
        }
Exemplo n.º 4
0
        // Callback for View layout direction change signal
        private void OnLayoutDirectionChanged(IntPtr data, ViewLayoutDirectionType type)
        {
            LayoutDirectionChangedEventArgs e = new LayoutDirectionChangedEventArgs();

            if (data != null)
            {
                e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
            }
            e.Type = type;

            if (_layoutDirectionChangedEventHandler != null)
            {
                _layoutDirectionChangedEventHandler(this, e);
            }
        }
Exemplo n.º 5
0
        protected override void OnLayout(bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom)
        {
            Console.WriteLine($"CustomLayoutHorizental OnLayout() START");

            LayoutLength childTop  = new LayoutLength(0);
            LayoutLength childLeft = new LayoutLength(0);

            // We want to vertically align the children to the middle
            var height = bottom - top;
            var middle = height / 2;

            // Horizontally align the children to the middle of the space they are given too
            var  width = right - left;
            uint count = ChildCount;

            Console.WriteLine($"child count={count}");

            var childIncrement = 0;

            if (count > 0)
            {
                childIncrement = width.Value / System.Convert.ToInt32(count);
            }
            var center = childIncrement / 2;

            // Check layout direction
            var view = Owner;
            ViewLayoutDirectionType layoutDirection = view.LayoutDirection;

            // this is needed, otherwise the child's LayoutItem is garbage collected!
            for (uint i = 0; i < ChildCount; ++i)
            {
                childLayouts[i] = GetChildAt(i);
            }

            for (uint i = 0; i < count; i++)
            {
                uint itemIndex;
                // If RTL, then layout the last item first
                if (layoutDirection == ViewLayoutDirectionType.RTL)
                {
                    itemIndex = count - 1 - i;
                }
                else
                {
                    itemIndex = i;
                }

                var childLayout = childLayouts[itemIndex];
                if (childLayout)
                {
                    var childWidth  = childLayout.MeasuredWidth;
                    var childHeight = childLayout.MeasuredHeight;

                    childTop = middle - (childHeight / 2);

                    var leftPosition = childLeft + center - childWidth / 2;

                    childLayout.Layout(leftPosition, childTop, leftPosition + childWidth, childTop + childHeight);
                    childLeft += childIncrement;

                    Console.WriteLine($"child layout is not NULL! childWidth={childWidth.Value}, i={i}");
                }
            }
            Console.WriteLine($"CustomLayoutHorizental OnLayout() END");
        }