Example #1
0
        /// <summary>
        /// Updates <see cref="AbsoluteSize" /> and <see cref="AbsolutePosition" />.
        /// </summary>
        public virtual void Measure()
        {
            var parentGui      = Parent as GuiBase2D;
            var parentSize     = parentGui?.AbsoluteSize ?? (parentGui?.AbsoluteSize ?? new Vector2());
            var parentPosition = parentGui?.AbsolutePosition ?? new Vector2();

            AbsoluteSize = Size.toAbsolute(parentSize).round();

            var position = Position;

            var xScaleOffset    = 0.0f;
            var yScaleOffset    = 0.0f;
            var xAbsoluteOffset = 0;
            var yAbsoluteOffset = 0;
            var xMult           = 1;
            var yMult           = 1;

            if (_alignmentX == AlignmentX.Right)
            {
                xScaleOffset    = 1;
                xAbsoluteOffset = (int)-AbsoluteSize.X;
                xMult           = -1;
            }
            else if (_alignmentX == AlignmentX.Center)
            {
                xScaleOffset    = 0.5f;
                xAbsoluteOffset = (int)-AbsoluteSize.X / 2;
            }

            if (_alignmentY == AlignmentY.Bottom)
            {
                yScaleOffset    = 1;
                yAbsoluteOffset = (int)-AbsoluteSize.Y;
                yMult           = -1;
            }
            else if (_alignmentY == AlignmentY.Middle)
            {
                yScaleOffset    = 0.5f;
                yAbsoluteOffset = (int)-AbsoluteSize.Y / 2;
            }

            position = new UDim2(xScaleOffset + position.Scale.X * xMult, xAbsoluteOffset + position.Absolute.X * xMult,
                                 yScaleOffset + position.Scale.Y * xMult, yAbsoluteOffset + position.Absolute.Y * yMult);

            AbsolutePosition = (parentPosition + position.toAbsolute(parentSize)).round();

            Measured?.Fire();

            Arrange();

            foreach (var kv in Children)
            {
                var el = kv as GuiElement;
                el?.Measure();
            }
        }