コード例 #1
0
        public void AddItem(ILayoutable item, Alignment alignment = Alignment.Default)
        {
            foreach (var pair in _items)
            {
                if (pair.Key == item)
                {
                    return; // already part of this layout
                }
            }
            _items.Add(new KeyValuePair <ILayoutable, Alignment>(item, alignment));
            item.AttachTo(_backgroundSprite, true);
            item.RelativeZ     = 0.1f;
            item.Alpha         = _alpha;
            item.ParentLayout  = this;
            _recalculateLayout = true;

            if (item.OnAddedToLayout != null)
            {
                item.OnAddedToLayout(this);
            }

            PerformLayout();

            item.OnSizeChangeHandler = sender =>
            {
                _recalculateLayout = true;

                // If a recalculation already happened this frame, manually trigger a new one
                if (Math.Abs(_lastLayoutFrame - TimeManager.CurrentTime) > double.Epsilon)
                {
                    ForceUpdateDependencies();
                }
            };
        }
コード例 #2
0
        public void AddItem(ILayoutable item, HorizontalPosition horizontalPosition, VerticalPosition verticalPosition, LayoutOrigin layoutFrom = LayoutOrigin.Center)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            var position = new OverallPosition
            {
                HorizontalPosition = horizontalPosition,
                VerticalPosition   = verticalPosition,
                LayoutOrigin       = layoutFrom
            };

            _items.Add(item, position);
            item.Alpha = _alpha;
            item.AttachTo(_backgroundSprite, true);
            item.RelativeZ    = 0.1f;
            item.ParentLayout = this;

            if (item.OnAddedToLayout != null)
            {
                item.OnAddedToLayout(this);
            }

            PositionItem(item, horizontalPosition, verticalPosition, layoutFrom);

            // When the size changes, make sure to reposition the item so it's still in the same spot
            item.OnSizeChangeHandler = new LayoutableEvent(delegate(ILayoutable sender) { PositionItem(item, horizontalPosition, verticalPosition, layoutFrom); });
        }
コード例 #3
0
        public void AddItem(ILayoutable item, float radiusOffset = 0, float degreeOffset = 0)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            if (!_items.ContainsKey(item))
            {
                // Add the item to the list
                _items.Add(item, new CircularPosition());
                item.AttachTo(_backgroundSprite, true);
                item.RelativeZ    = 0.1f;
                item.Alpha        = _alpha;
                item.ParentLayout = this;

                if (item.OnAddedToLayout != null)
                {
                    item.OnAddedToLayout(this);
                }
            }

            // Calculate the item's position
            _items[item].RadiusOffset = radiusOffset;
            _items[item].RadianOffset = MathHelper.ToRadians(degreeOffset);

            // Trigger a recalulation of the layout
            _recalculateLayout = true;

            // Set the size to realculate when a control changes
            item.OnSizeChangeHandler = sender => _recalculateLayout = true;
        }
コード例 #4
0
ファイル: GridLayout.cs プロジェクト: KallDrexx/FrbUi
        public void AddItem(ILayoutable item, int rowIndex, int columnIndex, HorizontalAlignment horizontalAlignment = HorizontalAlignment.Left, VerticalAlignment verticalAlignment = VerticalAlignment.Top)
        {
            if (columnIndex < 0)
            {
                throw new InvalidOperationException("Item cannot be placed in a column index less than 0");
            }

            if (rowIndex < 0)
            {
                throw new InvalidOperationException("Item cannot be placed in a row index less than 0");
            }

            // Ignore null items
            if (item == null)
            {
                return;
            }

            // If this item is already tracked, remove it from the current position
            //   and place the item in the new position
            if (_items.Contains(item))
            {
                _items.Remove(item);
            }

            // Add the item to the grid collection
            if (_items[rowIndex, columnIndex] != null)
            {
                throw new InvalidOperationException(
                          string.Format("An item already exists for this grid at row {0} column {1}", rowIndex, columnIndex));
            }

            var alignment = new GridAlignment
            {
                HorizontalAlignment = horizontalAlignment,
                VerticalAlignment   = verticalAlignment
            };

            _items.Add(item, alignment, rowIndex, columnIndex);

            // Attach the item to the background sprite
            item.AttachTo(_backgroundSprite, true);
            item.RelativeZ    = 0.1f;
            item.Alpha        = _alpha;
            item.ParentLayout = this;

            if (item.OnAddedToLayout != null)
            {
                item.OnAddedToLayout(this);
            }

            _recalculateLayout = true;

            item.OnSizeChangeHandler = sender => _recalculateLayout = true;
        }
コード例 #5
0
ファイル: GridLayout.cs プロジェクト: KallDrexx/FrbUi
        public void AddItem(ILayoutable item, int rowIndex, int columnIndex, HorizontalAlignment horizontalAlignment = HorizontalAlignment.Left, VerticalAlignment verticalAlignment = VerticalAlignment.Top)
        {
            if (columnIndex < 0)
                throw new InvalidOperationException("Item cannot be placed in a column index less than 0");

            if (rowIndex < 0)
                throw new InvalidOperationException("Item cannot be placed in a row index less than 0");

            // Ignore null items
            if (item == null)
                return;

            // If this item is already tracked, remove it from the current position
            //   and place the item in the new position
            if (_items.Contains(item))
                _items.Remove(item);

            // Add the item to the grid collection
            if (_items[rowIndex, columnIndex] != null)
                throw new InvalidOperationException(
                    string.Format("An item already exists for this grid at row {0} column {1}", rowIndex, columnIndex));

            var alignment = new GridAlignment
            {
                HorizontalAlignment = horizontalAlignment,
                VerticalAlignment = verticalAlignment
            };

            _items.Add(item, alignment, rowIndex, columnIndex);

            // Attach the item to the background sprite
            item.AttachTo(_backgroundSprite, true);
            item.RelativeZ = 0.1f;
            item.Alpha = _alpha;
            item.ParentLayout = this;

            if (item.OnAddedToLayout != null)
                item.OnAddedToLayout(this);

            _recalculateLayout = true;

            item.OnSizeChangeHandler = sender => _recalculateLayout = true;
        }