예제 #1
0
        /// <summary>
        /// Create the text input.
        /// </summary>
        /// <param name="multiline">If true, text input will accept multiple lines.</param>
        /// <param name="size">Input box size.</param>
        /// <param name="anchor">Position anchor.</param>
        /// <param name="offset">Offset from anchor position.</param>
        /// <param name="skin">TextInput skin, eg which texture to use.</param>
        public TextInput(bool multiline, Vector2 size, Anchor anchor = Anchor.Auto, Vector2?offset = null, PanelSkin skin = PanelSkin.ListBackground) :
            base(size, skin, anchor, offset)
        {
            // set multiline mode
            _multiLine = multiline;

            // special case - if multiline and asked for default height, make it heigher
            if (multiline && size.Y == -1)
            {
                _size.Y *= 4;
            }

            // update default style
            UpdateStyle(DefaultStyle);

            // set limit by size - default true in single-line, default false in multi-line
            LimitBySize = !_multiLine;

            // create paragraph to show current value
            TextParagraph = UserInterface.DefaultParagraph(string.Empty, _multiLine ? Anchor.TopLeft : Anchor.CenterLeft);
            TextParagraph.UpdateStyle(DefaultParagraphStyle);
            TextParagraph._hiddenInternalEntity = true;
            AddChild(TextParagraph, true);

            // create the placeholder paragraph
            PlaceholderParagraph = UserInterface.DefaultParagraph(string.Empty, _multiLine ? Anchor.TopLeft : Anchor.CenterLeft);
            PlaceholderParagraph.UpdateStyle(DefaultPlaceholderStyle);
            PlaceholderParagraph._hiddenInternalEntity = true;
            AddChild(PlaceholderParagraph, true);

            // create the scrollbar
            if (_multiLine)
            {
                _scrollbar         = new VerticalScrollbar(0, 0, Anchor.CenterRight, offset: new Vector2(-8, 0));
                _scrollbar.Value   = 0;
                _scrollbar.Visible = false;
                _scrollbar._hiddenInternalEntity = true;
                AddChild(_scrollbar, false);
            }

            // set word-wrap mode based on whether or not this text input is multiline
            TextParagraph.WrapWords        = _multiLine;
            PlaceholderParagraph.WrapWords = _multiLine;

            // if the default paragraph type is multicolor, disable it for input
            MulticolorParagraph colorTextParagraph = TextParagraph as MulticolorParagraph;

            if (colorTextParagraph != null)
            {
                colorTextParagraph.EnableColorInstructions = false;
            }
        }
예제 #2
0
        /// <summary>
        /// Create the text input.
        /// </summary>
        /// <param name="multiline">If true, text input will accept multiple lines.</param>
        /// <param name="size">Input box size.</param>
        /// <param name="anchor">Position anchor.</param>
        /// <param name="offset">Offset from anchor position.</param>
        /// <param name="skin">TextInput skin, eg which texture to use.</param>
        public TextInput(bool multiline, Vector2 size, Anchor anchor = Anchor.Auto, Vector2?offset = null, PanelSkin skin = PanelSkin.ListBackground) :
            base(size, skin, anchor, offset)
        {
            // set multiline mode
            _multiLine = multiline;

            // special case - if multiline and asked for default height, make it heigher
            if (multiline && size.Y == -1)
            {
                _size.Y *= 4;
            }

            // update default style
            UpdateStyle(DefaultStyle);

            // set limit by size - default true in single-line, default false in multi-line
            LimitBySize = !_multiLine;

            if (!UserInterface.Active._isDeserializing)
            {
                // create paragraph to show current value
                TextParagraph = UserInterface.DefaultParagraph(string.Empty, Anchor.TopLeft);
                TextParagraph.UpdateStyle(DefaultParagraphStyle);
                TextParagraph._hiddenInternalEntity = true;
                TextParagraph.Identifier            = "_TextParagraph";
                AddChild(TextParagraph, true);

                // create the placeholder paragraph
                PlaceholderParagraph = UserInterface.DefaultParagraph(string.Empty, Anchor.TopLeft);
                PlaceholderParagraph.UpdateStyle(DefaultPlaceholderStyle);
                PlaceholderParagraph._hiddenInternalEntity = true;
                PlaceholderParagraph.Identifier            = "_PlaceholderParagraph";
                AddChild(PlaceholderParagraph, true);

                // update multiline related stuff
                UpdateMultilineState();

                // if the default paragraph type is multicolor, disable it for input
                MulticolorParagraph colorTextParagraph = TextParagraph as MulticolorParagraph;
                if (colorTextParagraph != null)
                {
                    colorTextParagraph.EnableColorInstructions = false;
                }
            }
        }
예제 #3
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
                MulticolorParagraph paragraph = new MulticolorParagraph(".", 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;
                }
            }
        }