Esempio n. 1
0
        public void MeasuredSizeConstructor()
        {
            tlog.Debug(tag, $"MeasuredSizeConstructor START");

            var testingTarget = new MeasuredSize(new LayoutLength(10), MeasuredSize.StateType.MeasuredSizeOK);

            Assert.IsNotNull(testingTarget, "null handle returned");
            Assert.IsInstanceOf <MeasuredSize>(testingTarget, "Should return MeasuredSize instance.");

            tlog.Debug(tag, $"MeasuredSizeConstructor END (OK)");
        }
Esempio n. 2
0
        public void MeasuredSizeState()
        {
            tlog.Debug(tag, $"MeasuredSizeState START");

            var testingTarget = new MeasuredSize(new LayoutLength(10), MeasuredSize.StateType.MeasuredSizeOK);

            Assert.IsNotNull(testingTarget, "null handle returned");
            Assert.IsInstanceOf <MeasuredSize>(testingTarget, "Should return MeasuredSize instance.");

            Assert.AreEqual(testingTarget.State, MeasuredSize.StateType.MeasuredSizeOK, "Should match default state");

            testingTarget.State = MeasuredSize.StateType.MeasuredSizeTooSmall;
            Assert.AreEqual(testingTarget.State, MeasuredSize.StateType.MeasuredSizeTooSmall, "Should state set");

            tlog.Debug(tag, $"MeasuredSizeState END (OK)");
        }
Esempio n. 3
0
        public void LayoutItemResolveSizeAndState()
        {
            tlog.Debug(tag, $"LayoutItemResolveSizeAndState START");

            var testingTarget = new MyLayoutItem();

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

            MeasureSpecification measureSpec = new MeasureSpecification(new LayoutLength(10), MeasureSpecification.ModeType.Exactly);

            MeasuredSize measuredSize = testingTarget.ResolveSizeAndState(new LayoutLength(50), measureSpec, MeasuredSize.StateType.MeasuredSizeOK);

            Assert.AreEqual(measureSpec.GetSize().AsRoundedValue(), 10, "measuredSize not resolved correctly");

            testingTarget.Dispose();
            tlog.Debug(tag, $"LayoutItemResolveSizeAndState END (OK)");
        }
Esempio n. 4
0
        public void MeasuredSizeSize()
        {
            tlog.Debug(tag, $"MeasuredSizeSize START");

            var testingTarget = new MeasuredSize(new LayoutLength(10), MeasuredSize.StateType.MeasuredSizeOK);

            Assert.IsNotNull(testingTarget, "null handle returned");
            Assert.IsInstanceOf <MeasuredSize>(testingTarget, "Should return MeasuredSize instance.");

            float length = testingTarget.Size.AsRoundedValue();

            Assert.AreEqual(length, 10.0f, "Should be value set.");

            testingTarget.Size = new LayoutLength(20);

            length = testingTarget.Size.AsRoundedValue();
            Assert.AreEqual(length, 20.0f, "Should be value set.");

            tlog.Debug(tag, $"MeasuredSizeSize END (OK)");
        }
Esempio n. 5
0
        public void LayoutItemSetMeasuredDimensions()
        {
            tlog.Debug(tag, $"LayoutItemSetMeasuredDimensions START");

            var testingTarget = new MyLayoutItem();

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

            MeasuredSize measuredWidth  = new MeasuredSize(new LayoutLength(100), MeasuredSize.StateType.MeasuredSizeOK);
            MeasuredSize measuredHeight = new MeasuredSize(new LayoutLength(50), MeasuredSize.StateType.MeasuredSizeOK);

            testingTarget.SetMeasuredDimensions(measuredWidth, measuredHeight);

            Assert.AreEqual(100, testingTarget.MeasuredWidth.Size.AsRoundedValue(), "Should be value set");
            Assert.AreEqual(50, testingTarget.MeasuredHeight.Size.AsRoundedValue(), "Should be value set");

            testingTarget.Dispose();
            tlog.Debug(tag, $"LayoutItemSetMeasuredDimensions END (OK)");
        }
Esempio n. 6
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)
                        {
                            MeasureChild(childLayout, widthMeasureSpec, unrestrictedMeasureSpec);    // Height unrestricted by parent
                        }
                        else
                        {
                            MeasureChild(childLayout, unrestrictedMeasureSpec, heightMeasureSpec);    // 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.MeasuredWidth.State == MeasuredSize.StateType.MeasuredSizeTooSmall)
                        {
                            childHeightState = MeasuredSize.StateType.MeasuredSizeTooSmall;
                        }
                    }
                }


                MeasuredSize widthSizeAndState  = ResolveSizeAndState(new LayoutLength(totalWidth), widthMeasureSpec, MeasuredSize.StateType.MeasuredSizeOK);
                MeasuredSize heightSizeAndState = ResolveSizeAndState(new LayoutLength(totalHeight), 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), widthMeasureSpec, childWidthState),
                                      ResolveSizeAndState(new LayoutLength(totalHeight), heightMeasureSpec, childHeightState));
            }
Esempio n. 7
0
 public void SetMeasuredDimensions(MeasuredSize measuredWidth, MeasuredSize measuredHeight)
 {
     base.SetMeasuredDimensions(measuredWidth, measuredHeight);
 }