예제 #1
0
        private void PlaceRow(MosaicRow row, Rect targetRect)
        {
            double prevX = targetRect.X;
            foreach (var item in row.Items)
            {
                PlaceItem(item, new Rect(prevX, targetRect.Y, item.ComputedSize.Width, item.ComputedSize.Height));

                prevX += item.ComputedSize.Width;
            }

            row.Location = new Point(targetRect.X, targetRect.Y);
        }
예제 #2
0
        private void LayoutImages()
        {
            if (_items.Count == 0)
                return;

            var currentRow = new MosaicRow() {Size = new Size(ActualWidth, 0)};
            _rows.Add(currentRow);

            double prevX = 0;
            double prevY = 0;

            foreach (var item in _items)
            {
                currentRow.Items.Add(item);

                //resize item to MaxImageSize if necessary and set ComputedSize
                MeasureItem(item);

                //set row height from the first image in the row
                if (currentRow.Size.Height == 0)
                {
                    currentRow.Size = new Size(currentRow.Size.Width, item.ComputedSize.Height);
                    currentRow.DesiredSize = currentRow.Size;
                }
                else
                {
                    //resize all other items in row to the row height
                    FitToRow(item, currentRow.Size.Height);
                }

                //calculate current item location
                var itemRect = ComputeItemLocation(item, new Rect(prevX, currentRow.Location.Y, currentRow.Size.Width, currentRow.Size.Height));

                currentRow.DesiredSize = new Size(itemRect.Right, currentRow.DesiredSize.Height);

                if (itemRect.Right > currentRow.Size.Width)
                {
                    //LINE BREAK

                    prevX = 0;
                    prevY += currentRow.Size.Height;

                    currentRow = new MosaicRow() { Location = new Point(0, prevY), Size = new Size(ActualWidth, 0) };

                    _rows.Add(currentRow);
                }
                else
                {
                    prevX += itemRect.Width;
                }

                //place item at specified location and set ComputedLocation
                PlaceItem(item, itemRect);
            }

            if (currentRow.Items.Count == 0)
                _rows.Remove(currentRow);

            Height = currentRow.Location.Y + currentRow.Size.Height;
        }