Пример #1
0
 public static Rect FirstLine(this Rect rect,
                              float height = 18)
 {
     rect        = rect.Abs();
     rect.height = height;
     return(rect.Abs());
 }
 public static Rect MoveDownFor(this Rect rect, float newHeight, float space = SPACE)
 {
     rect        = rect.Abs();
     rect.y     += rect.height + space;
     rect.height = newHeight;
     return(rect.Abs());
 }
 public static Rect MoveLeftFor(this Rect rect, float newWidth, float space = SPACE)
 {
     rect       = rect.Abs();
     rect.x    -= newWidth + space;
     rect.width = newWidth;
     return(rect.Abs());
 }
Пример #4
0
 public static Rect MoveRight(this Rect rect,
                              float space = SPACE)
 {
     rect    = rect.Abs();
     rect.x += rect.width + space;
     return(rect);
 }
Пример #5
0
 public static Rect MoveDown(this Rect rect,
                             float space = SPACE)
 {
     rect    = rect.Abs();
     rect.y += rect.height + space;
     return(rect);
 }
Пример #6
0
        public static Rect[] Row(this Rect rect, int count, float space = SPACE)
        {
            rect = rect.Abs();
            switch (count)
            {
            case 1:
            {
                return(new Rect[] { rect });
            }

            case 2:
            {
                return(RowTwoSlices(rect, space));
            }

            case 3:
            {
                return(RowThreeSlices(rect, space));
            }

            default:
            {
                var weights = Enumerable.Repeat(1f, count).ToArray();
                var widthes = Enumerable.Repeat(0f, count).ToArray();
                return(Row(rect, weights, widthes, space));
            }
            }
        }
Пример #7
0
        public static Rect Intend(this Rect rect, float border)
        {
            rect = rect.Abs();

            var result = new Rect(
                x: rect.x + border,
                y: rect.y + border,
                width: rect.width - 2 * border,
                height: rect.height - 2 * border
                );

            if (result.width < 0)
            {
                result.x    += result.width / 2;
                result.width = 0;
            }

            if (result.height < 0)
            {
                result.y     += result.height / 2;
                result.height = 0;
            }

            return(result);
        }
Пример #8
0
        /// <summary>
        ///     Clamp the point to the rect.
        /// </summary>
        /// <param name="extends">Extends.</param>
        /// <param name="point">Point.</param>
        public static Vector2 Clamp(this Rect extends, Vector2 point)
        {
            extends = extends.Abs();

            float x = HydraMathUtils.Clamp(point.x, extends.xMin, extends.xMax);
            float y = HydraMathUtils.Clamp(point.y, extends.yMin, extends.yMax);

            return(new Vector2(x, y));
        }
Пример #9
0
 public static Rect Extend(this Rect rect, float border)
 {
     rect = rect.Abs();
     return(new Rect(
                x: rect.x - border,
                y: rect.y - border,
                width: rect.width + 2 * border,
                height: rect.height + 2 * border
                ));
 }
Пример #10
0
        public static Rect[] Row(this Rect rect, float[] weights, float[] widthes, float space = SPACE)
        {
            if (weights == null)
            {
                throw new ArgumentException("Weights is null. You must specify it");
            }

            if (widthes == null)
            {
                widthes = Enumerable.Repeat(0f, weights.Length).ToArray();
            }

            rect = rect.Abs();
            return(RowSafe(rect, weights, widthes, space));
        }
Пример #11
0
 public static Rect MoveUp(this Rect rect, float space = 2)
 {
     rect    = rect.Abs();
     rect.y -= rect.height + space;
     return(rect);
 }
Пример #12
0
 public static Rect MoveLeft(this Rect rect, float space = 2)
 {
     rect    = rect.Abs();
     rect.x -= rect.width + space;
     return(rect);
 }
Пример #13
0
        public void Abs(string name, Rect from, Rect expected)
        {
            var actual = from.Abs();

            Assert.AreEqual(expected, actual);
        }