Ejemplo n.º 1
0
 protected override void OnMeasure(MeasureSpecification widthMeasureSpec, MeasureSpecification heightMeasureSpec)
 {
     flagOnMeasureOverride = true;
     base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
 }
Ejemplo n.º 2
0
            protected override void OnMeasure(MeasureSpecification widthMeasureSpec, MeasureSpecification heightMeasureSpec)
            {
                Extents padding     = Padding;
                float   totalHeight = padding.Top + padding.Bottom;
                float   totalWidth  = padding.Start + padding.End;

                MeasuredSize.StateType childWidthState  = MeasuredSize.StateType.MeasuredSizeOK;
                MeasuredSize.StateType childHeightState = MeasuredSize.StateType.MeasuredSizeOK;

                Direction      scrollingDirection = Direction.Vertical;
                ScrollableBase scrollableBase     = this.Owner as ScrollableBase;

                if (scrollableBase)
                {
                    scrollingDirection = scrollableBase.ScrollingDirection;
                }

                // measure child, should be a single scrolling child
                foreach (LayoutItem childLayout in LayoutChildren)
                {
                    if (childLayout != null)
                    {
                        // Get size of child
                        // Use an Unspecified MeasureSpecification mode so scrolling child is not restricted to it's parents size in Height (for vertical scrolling)
                        // or Width for horizontal scrolling
                        MeasureSpecification unrestrictedMeasureSpec = new MeasureSpecification(heightMeasureSpec.Size, MeasureSpecification.ModeType.Unspecified);

                        if (scrollingDirection == Direction.Vertical)
                        {
                            MeasureChildWithMargins(childLayout, widthMeasureSpec, new LayoutLength(0), unrestrictedMeasureSpec, new LayoutLength(0));  // Height unrestricted by parent
                        }
                        else
                        {
                            MeasureChildWithMargins(childLayout, unrestrictedMeasureSpec, new LayoutLength(0), heightMeasureSpec, new LayoutLength(0));  // Width unrestricted by parent
                        }

                        float childWidth  = childLayout.MeasuredWidth.Size.AsDecimal();
                        float childHeight = childLayout.MeasuredHeight.Size.AsDecimal();

                        // Determine the width and height needed by the children using their given position and size.
                        // Children could overlap so find the left most and right most child.
                        Position2D childPosition = childLayout.Owner.Position2D;
                        float      childLeft     = childPosition.X;
                        float      childTop      = childPosition.Y;

                        // Store current width and height needed to contain all children.
                        Extents childMargin = childLayout.Margin;
                        totalWidth  = childWidth + childMargin.Start + childMargin.End;
                        totalHeight = childHeight + childMargin.Top + childMargin.Bottom;

                        if (childLayout.MeasuredWidth.State == MeasuredSize.StateType.MeasuredSizeTooSmall)
                        {
                            childWidthState = MeasuredSize.StateType.MeasuredSizeTooSmall;
                        }
                        if (childLayout.MeasuredHeight.State == MeasuredSize.StateType.MeasuredSizeTooSmall)
                        {
                            childHeightState = MeasuredSize.StateType.MeasuredSizeTooSmall;
                        }
                    }
                }


                MeasuredSize widthSizeAndState  = ResolveSizeAndState(new LayoutLength(totalWidth + Padding.Start + Padding.End), widthMeasureSpec, MeasuredSize.StateType.MeasuredSizeOK);
                MeasuredSize heightSizeAndState = ResolveSizeAndState(new LayoutLength(totalHeight + Padding.Top + Padding.Bottom), heightMeasureSpec, MeasuredSize.StateType.MeasuredSizeOK);

                totalWidth  = widthSizeAndState.Size.AsDecimal();
                totalHeight = heightSizeAndState.Size.AsDecimal();

                // Ensure layout respects it's given minimum size
                totalWidth  = Math.Max(totalWidth, SuggestedMinimumWidth.AsDecimal());
                totalHeight = Math.Max(totalHeight, SuggestedMinimumHeight.AsDecimal());

                widthSizeAndState.State  = childWidthState;
                heightSizeAndState.State = childHeightState;

                SetMeasuredDimensions(ResolveSizeAndState(new LayoutLength(totalWidth + Padding.Start + Padding.End), widthMeasureSpec, childWidthState),
                                      ResolveSizeAndState(new LayoutLength(totalHeight + Padding.Top + Padding.Bottom), heightMeasureSpec, childHeightState));

                // Size of ScrollableBase is changed. Change Page width too.
                scrollableBase.mPageWidth = (int)MeasuredWidth.Size.AsRoundedValue();
            }
Ejemplo n.º 3
0
 public void OnMeasureTest(MeasureSpecification widthMeasureSpec, MeasureSpecification heightMeasureSpec)
 {
     OnMeasure(widthMeasureSpec, heightMeasureSpec);
 }
Ejemplo n.º 4
0
 public void MeasureChildrenTest(MeasureSpecification widthMeasureSpec, MeasureSpecification heightMeasureSpec)
 {
     MeasureChildren(widthMeasureSpec, heightMeasureSpec);
 }
Ejemplo n.º 5
0
        public void LinearLayoutOnMeasure()
        {
            tlog.Debug(tag, $"LinearLayoutOnMeasure START");

            flagOnMeasureOverride = false;
            Assert.False(flagOnMeasureOverride, "flagOnMeasureOverride should be false initial");

            LayoutItem layoutItem = new LinearLayout();

            View view = new View()
            {
                ExcludeLayouting    = false,
                Weight              = 10,
                WidthSpecification  = 0,
                HeightSpecification = 0,
                Layout              = new LinearLayout()
            };

            layoutItem.AttachToOwner(view);

            var testingTarget = new MyLinearLayout();

            Assert.IsNotNull(testingTarget, "null handle returned");
            Assert.IsInstanceOf <LinearLayout>(testingTarget, "Should be an instance of LinearLayout type.");

            testingTarget.AttachToOwner(view);
            testingTarget.Add(layoutItem);

            MeasureSpecification measureWidth  = new MeasureSpecification(new LayoutLength(50.0f), MeasureSpecification.ModeType.Exactly);
            MeasureSpecification measureHeight = new MeasureSpecification(new LayoutLength(50.0f), MeasureSpecification.ModeType.Exactly);

            /**
             * isExactly is true
             * useExcessSpace is true :(childLayout.Owner.WidthSpecification == 0) && (childWeight > 0)
             */
            testingTarget.OnMeasureTest(measureWidth, measureHeight);
            Assert.True(flagOnMeasureOverride, "LinearLayout overridden method not invoked.");

            /**
             * isExactly is false
             * useExcessSpace is true :(childLayout.Owner.WidthSpecification == 0) && (childWeight > 0)
             */
            flagOnMeasureOverride = false;
            Assert.False(flagOnMeasureOverride, "flagOnMeasureOverride should be false initial");

            MeasureSpecification measureWidth2  = new MeasureSpecification(new LayoutLength(50.0f), MeasureSpecification.ModeType.AtMost);
            MeasureSpecification measureHeight2 = new MeasureSpecification(new LayoutLength(50.0f), MeasureSpecification.ModeType.Unspecified);

            testingTarget.OnMeasureTest(measureWidth2, measureHeight2);
            Assert.True(flagOnMeasureOverride, "LinearLayout overridden method not invoked.");

            /**
             *  matchHeight
             *  heightMode != MeasureSpecification.ModeType.Exactly && childDesiredHeight == LayoutParamPolicies.MatchParent
             */
            view.HeightSpecification = LayoutParamPolicies.MatchParent;
            testingTarget.OnMeasureTest(measureWidth2, measureHeight2);

            /**Test LinearLayout.Orientation.Vertical */
            testingTarget.LinearOrientation = LinearLayout.Orientation.Vertical;
            view.HeightSpecification        = 0;

            flagOnMeasureOverride = false;
            Assert.False(flagOnMeasureOverride, "flagOnMeasureOverride should be false initial");

            /**
             * isExactly is true
             * useExcessSpace is true :(childLayout.Owner.HeightSpecification == 0) && (childWeight > 0)
             */
            testingTarget.OnMeasureTest(measureWidth, measureHeight);
            Assert.True(flagOnMeasureOverride, "LinearLayout overridden method not invoked.");

            flagOnMeasureOverride = false;
            Assert.False(flagOnMeasureOverride, "flagOnMeasureOverride should be false initial");

            /**
             * isExactly is true
             * useExcessSpace is true :(childLayout.Owner.HeightSpecification == 0) && (childWeight > 0)
             *
             * matchWidth
             * widthMode != MeasureSpecification.ModeType.Exactly && childDesiredWidth == LayoutParamPolicies.MatchParent
             */
            view.WidthSpecification = LayoutParamPolicies.MatchParent;
            testingTarget.OnMeasureTest(measureWidth2, measureHeight2);
            Assert.True(flagOnMeasureOverride, "LinearLayout overridden method not invoked.");

            testingTarget.Dispose();
            tlog.Debug(tag, $"LinearLayoutOnMeasure END (OK)");
        }
Ejemplo n.º 6
0
 public void MeasureChildTest(LayoutItem child, MeasureSpecification parentWidth, MeasureSpecification parentHeight)
 {
     MeasureChild(child, parentWidth, parentHeight);
 }
Ejemplo n.º 7
0
 protected override void MeasureChild(LayoutItem child, MeasureSpecification parentWidth, MeasureSpecification parentHeight)
 {
     flagOnMeasureChild = true;
     base.MeasureChild(child, parentWidth, parentHeight);
 }
Ejemplo n.º 8
0
 public void MeasureChildWithoutPaddingTest(LayoutItem child, MeasureSpecification parentWidthMeasureSpec, MeasureSpecification parentHeightMeasureSpec)
 {
     MeasureChildWithoutPadding(child, parentWidthMeasureSpec, parentHeightMeasureSpec);
 }
Ejemplo n.º 9
0
 protected override void MeasureChildWithMargins(LayoutItem child, MeasureSpecification parentWidthMeasureSpec, LayoutLength widthUsed, MeasureSpecification parentHeightMeasureSpec, LayoutLength heightUsed)
 {
     flagOnMeasureChild = true;
     base.MeasureChildWithMargins(child, parentWidthMeasureSpec, widthUsed, parentHeightMeasureSpec, heightUsed);
 }
Ejemplo n.º 10
0
 public void MeasureChildWithMarginsTest(LayoutItem child, MeasureSpecification parentWidthMeasureSpec, LayoutLength widthUsed, MeasureSpecification parentHeightMeasureSpec, LayoutLength heightUsed)
 {
     MeasureChildWithMargins(child, parentWidthMeasureSpec, widthUsed, parentHeightMeasureSpec, heightUsed);
 }
Ejemplo n.º 11
0
 protected override void MeasureChildren(MeasureSpecification widthMeasureSpec, MeasureSpecification heightMeasureSpec)
 {
     flagOnMeasureChild = true;
     base.MeasureChildren(widthMeasureSpec, heightMeasureSpec);
 }
Ejemplo n.º 12
0
 public MeasuredSize ResolveSizeAndState(LayoutLength size, MeasureSpecification measureSpecification, MeasuredSize.StateType childMeasuredState)
 {
     return(base.ResolveSizeAndState(size, measureSpecification, childMeasuredState));
 }