Ejemplo n.º 1
0
 /// <summary>
 /// Moves the items so that their bounding boxes all have the Top (y) value of the
 /// top-most item</summary>
 /// <param name="items">Items to move</param>
 /// <param name="layoutContext">Layout context of items to move</param>
 public virtual void AlignTops(IEnumerable<object> items, ILayoutContext layoutContext)
 {
     Rectangle bounds;
     LayoutContexts.GetBounds(layoutContext, items, out bounds);
     foreach (object item in items)
     {
         layoutContext.SetBounds(item, bounds, BoundsSpecified.Y);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Moves the items so that their bounding boxes all have the Top (y) value of the
        /// top-most item</summary>
        /// <param name="items">Items to move</param>
        /// <param name="layoutContext">Layout context of items to move</param>
        public virtual void AlignTops(IEnumerable <object> items, ILayoutContext layoutContext)
        {
            Rectangle bounds;

            LayoutContexts.GetBounds(layoutContext, items, out bounds);
            foreach (object item in items)
            {
                layoutContext.SetBounds(item, bounds, BoundsSpecified.Y);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Moves the item, so that the center of its bounding box is at the given point</summary>
        /// <param name="layoutContext">Layout context containing item</param>
        /// <param name="item">Item to center</param>
        /// <param name="center">Centering point</param>
        public static void Center(this ILayoutContext layoutContext, object item, Point center)
        {
            Rect oldBounds;

            layoutContext.GetBounds(item, out oldBounds);
            Point topLeft = new Point(
                center.X - oldBounds.Width / 2,
                center.Y - oldBounds.Height / 2);

            layoutContext.SetBounds(item, oldBounds, new Rect(topLeft, oldBounds.Size), BoundsSpecified.Location);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Sets the height of all of the items to that of the tallest item</summary>
        /// <param name="items">Items to resize</param>
        /// <param name="layoutContext">Layout context of items to resize</param>
        public virtual void MakeHeightEqual(IEnumerable <object> items, ILayoutContext layoutContext)
        {
            Size maxSize = GetMaxSize(items, layoutContext);

            foreach (object item in items)
            {
                Rectangle bounds;
                layoutContext.GetBounds(item, out bounds);
                bounds.Height = maxSize.Height;
                layoutContext.SetBounds(item, bounds, BoundsSpecified.Height);
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Moves the items so that their bounding boxes all have the Left (x) value
 /// of the left-most item</summary>
 /// <param name="items">Items to move</param>
 /// <param name="layoutContext">Layout context of items to move</param>
 public virtual void AlignLefts(IEnumerable<object> items, ILayoutContext layoutContext)
 {
     Rectangle bounds;
     LayoutContexts.GetBounds(layoutContext, items, out bounds);
     foreach (object item in items)
     {
         Rectangle itemBounds;
         layoutContext.GetBounds(item, out itemBounds);
         itemBounds.X = bounds.X;
         layoutContext.SetBounds(item, itemBounds, BoundsSpecified.X);
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Moves the items so that their bounding boxes all have the Right (x + Width) value
        /// of the right-most item</summary>
        /// <param name="items">Items to move</param>
        /// <param name="layoutContext">Layout context of items to move</param>
        public virtual void AlignRights(IEnumerable <object> items, ILayoutContext layoutContext)
        {
            Rectangle bounds;

            LayoutContexts.GetBounds(layoutContext, items, out bounds);
            foreach (object item in items)
            {
                Rectangle itemBounds;
                layoutContext.GetBounds(item, out itemBounds);
                itemBounds.X = bounds.Right - itemBounds.Width;
                layoutContext.SetBounds(item, itemBounds, BoundsSpecified.X);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Moves the items so that their bounding boxes all have the Bottom (y + Height) value
        /// of the bottom-most item</summary>
        /// <param name="items">Items to move</param>
        /// <param name="layoutContext">Layout context of items to move</param>
        public virtual void AlignBottoms(IEnumerable <object> items, ILayoutContext layoutContext)
        {
            Rectangle bounds;

            LayoutContexts.GetBounds(layoutContext, items, out bounds);
            foreach (object item in items)
            {
                Rectangle itemBounds;
                layoutContext.GetBounds(item, out itemBounds);
                itemBounds.Y = bounds.Bottom - itemBounds.Height;
                layoutContext.SetBounds(item, itemBounds, BoundsSpecified.Y);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Moves all items so that the center of their bounding box is at the given point</summary>
        /// <param name="layoutContext">Layout context containing item</param>
        /// <param name="items">Items to center</param>
        /// <param name="center">Centering point</param>
        public static void Center(this ILayoutContext layoutContext, IEnumerable <object> items, Point center)
        {
            Rect bounds;

            GetBounds(layoutContext, items, out bounds);

            // calculate offset
            Point offset = new Point(
                center.X - (bounds.Left + bounds.Width / 2),
                center.Y - (bounds.Top + bounds.Height / 2));

            foreach (object item in items)
            {
                Rect itemBounds;
                layoutContext.GetBounds(item, out itemBounds);

                Point topLeft = new Point(
                    itemBounds.Left + offset.X,
                    itemBounds.Top + offset.Y);

                layoutContext.SetBounds(item, itemBounds, new Rect(topLeft, itemBounds.Size), BoundsSpecified.Location);
            }
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Sets the height of all of the items to that of the tallest item</summary>
 /// <param name="items">Items to resize</param>
 /// <param name="layoutContext">Layout context of items to resize</param>
 public virtual void MakeHeightEqual(IEnumerable<object> items, ILayoutContext layoutContext)
 {
     Size maxSize = GetMaxSize(items, layoutContext);
     foreach (object item in items)
     {
         Rectangle bounds;
         layoutContext.GetBounds(item, out bounds);
         bounds.Height = maxSize.Height;
         layoutContext.SetBounds(item, bounds, BoundsSpecified.Height);
     }
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Moves the items up or down so that their bounding box centers all have the same
 /// Y value, which is the Y value of the center of the bounding box around the items'
 /// original positions</summary>
 /// <param name="items">Items to move</param>
 /// <param name="layoutContext">Layout context of items to move</param>
 public virtual void AlignMiddles(IEnumerable<object> items, ILayoutContext layoutContext)
 {
     Rectangle bounds;
     LayoutContexts.GetBounds(layoutContext, items, out bounds);
     int boundsMiddle = (bounds.Top + bounds.Bottom) / 2;
     foreach (object item in items)
     {
         Rectangle itemBounds;
         layoutContext.GetBounds(item, out itemBounds);
         itemBounds.Y = boundsMiddle - itemBounds.Height / 2;
         layoutContext.SetBounds(item, itemBounds, BoundsSpecified.Y);
     }
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Moves the items left or right so that their bounding box centers all have the same
 /// X value, which is the X value of the center of the bounding box around the items'
 /// original positions</summary>
 /// <param name="items">Items to move</param>
 /// <param name="layoutContext">Layout context of items to move</param>
 public virtual void AlignCenters(IEnumerable<object> items, ILayoutContext layoutContext)
 {
     Rectangle bounds;
     LayoutContexts.GetBounds(layoutContext, items, out bounds);
     int boundsCenter = (bounds.Left + bounds.Right) / 2;
     foreach (object item in items)
     {
         Rectangle itemBounds;
         layoutContext.GetBounds(item, out itemBounds);
         itemBounds.X = boundsCenter - itemBounds.Width / 2;
         layoutContext.SetBounds(item, itemBounds, BoundsSpecified.X);
     }
 }