Esempio n. 1
0
        /// <summary>
        /// When list is resized (also called on init), create the labels to show item values and init graphical stuff.
        /// </summary>
        /// <param name="recalcDestRect">If true, will also recalculate destination rectangle.</param>
        protected virtual void OnResize(bool recalcDestRect = true)
        {
            // store current size
            _prevSize = _size;

            // remove all children before re-creating them
            ClearChildren();

            // remove previous paragraphs list
            _paragraphs.Clear();

            // calculate self destination rect
            if (recalcDestRect)
            {
                _destRect = CalcDestRect();
            }

            // calculate paragraphs quantity
            int i = 0;

            while (true)
            {
                // create and add new paragraph
                Paragraph paragraph = new Paragraph(".", Anchor.Auto, new Vector2(0, 40));
                // note: we set negative padding for the selected mark size so it won't be negative size
                paragraph.WrapWords = false;
                paragraph.UpdateStyle(DefaultParagraphStyle);
                paragraph.Scale        = paragraph.Scale * ItemsScale;
                paragraph.SpaceAfter   = paragraph.SpaceAfter + new Vector2(0, ExtraSpaceBetweenLines);
                paragraph.AttachedData = new ParagraphData(this, i++);
                paragraph.UseActualSizeForCollision = false;
                AddChild(paragraph);
                _paragraphs.Add(paragraph);
                OnCreatedListParagraph(paragraph);

                // add callback to selection
                paragraph.OnClick = (Entity entity) =>
                {
                    ParagraphData data = (ParagraphData)entity.AttachedData;
                    if (!data.list.LockSelection)
                    {
                        data.list.Select(data.relativeIndex, true);
                    }
                };

                // to calculate paragraph actual bottom
                paragraph.CalcDestRect();
                paragraph.PrepareForDraw();

                // if out of list bounderies remove this paragraph and stop
                if ((paragraph.GetActualDestRect().Bottom > _destRect.Bottom - Padding.Y) || i > _list.Count)
                {
                    RemoveChild(paragraph);
                    _paragraphs.Remove(paragraph);
                    break;
                }
            }

            // add scrollbar last, but only if needed
            if (_paragraphs.Count < _list.Count)
            {
                // add scrollbar to list
                AddChild(_scrollbar, false);

                // calc max scroll value
                _scrollbar.Max = (uint)(_list.Count - _paragraphs.Count);
                if (_scrollbar.Max < 2)
                {
                    _scrollbar.Max = 2;
                }
                _scrollbar.StepsCount = _scrollbar.Max;
                _scrollbar.Visible    = true;
            }
            // if no scrollbar is needed, hide it
            else
            {
                _scrollbar.Visible = false;
                if (_scrollbar.Value > 0)
                {
                    _scrollbar.Value = 0;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// When list is resized (also called on init), create the labels to show item values and init graphical stuff.
        /// </summary>
        protected virtual void OnResize()
        {
            // if not visible, skip
            if (!IsVisible())
            {
                _hadResizeWhileNotVisible = true;
                return;
            }

            // clear the _hadResizeWhileNotVisible flag
            _hadResizeWhileNotVisible = false;

            // remove all children before re-creating them
            ClearChildren();

            // remove previous paragraphs list
            _paragraphs.Clear();

            // make sure destination rect is up-to-date
            UpdateDestinationRects();

            // calculate paragraphs quantity
            int i = 0;

            while (true)
            {
                // create and add new paragraph
                Paragraph paragraph = UserInterface.DefaultParagraph(".", Anchor.Auto);
                paragraph.PromiscuousClicksMode = true;
                paragraph.WrapWords             = false;
                paragraph.UpdateStyle(DefaultParagraphStyle);
                paragraph.Scale                     = paragraph.Scale * ItemsScale;
                paragraph.SpaceAfter                = paragraph.SpaceAfter + new Vector2(0, ExtraSpaceBetweenLines - 2);
                paragraph.ExtraMargin.Y             = ExtraSpaceBetweenLines / 2 + 3;
                paragraph.AttachedData              = new ParagraphData(this, i++);
                paragraph.UseActualSizeForCollision = false;
                paragraph.Size = new Vector2(0, paragraph.GetCharacterActualSize().Y + ExtraSpaceBetweenLines);
                paragraph.BackgroundColorPadding    = new Point((int)Padding.X, 5);
                paragraph.BackgroundColorUseBoxSize = true;
                paragraph._hiddenInternalEntity     = true;
                paragraph.PropagateEventsTo(this);
                AddChild(paragraph);

                // call the callback whenever a new paragraph is created
                OnCreatedListParagraph(paragraph);

                // add to paragraphs list
                _paragraphs.Add(paragraph);

                // add callback to selection
                paragraph.OnClick += (Entity entity) =>
                {
                    ParagraphData data = (ParagraphData)entity.AttachedData;
                    if (!data.list.LockSelection)
                    {
                        data.list.Select(data.relativeIndex, true);
                    }
                };

                // to calculate paragraph actual bottom
                paragraph.UpdateDestinationRects();

                // if out of list bounderies remove this paragraph and stop
                if ((paragraph.GetActualDestRect().Bottom > _destRect.Bottom - _scaledPadding.Y) || i > _list.Count)
                {
                    RemoveChild(paragraph);
                    _paragraphs.Remove(paragraph);
                    break;
                }
            }

            // add scrollbar last, but only if needed
            if (_paragraphs.Count > 0 && _paragraphs.Count < _list.Count)
            {
                // add scrollbar to list
                AddChild(_scrollbar, false);

                // calc max scroll value
                _scrollbar.Max = (uint)(_list.Count - _paragraphs.Count);
                if (_scrollbar.Max < 2)
                {
                    _scrollbar.Max = 2;
                }
                _scrollbar.StepsCount = _scrollbar.Max;
                _scrollbar.Visible    = true;
            }
            // if no scrollbar is needed, hide it
            else
            {
                _scrollbar.Visible = false;
                if (_scrollbar.Value > 0)
                {
                    _scrollbar.Value = 0;
                }
            }
        }