public bool Validate(T value)
        {
            var messages = new List <string>();

            foreach (var msg in Messages)
            {
                var isInvalid = msg.Validator(value);
                if (isInvalid)
                {
                    messages.Add(msg.Message);
                }
            }

            if (messages.Count > 0)
            {
                var text = ErrorPrefix + "\n";
                foreach (var msg in messages)
                {
                    text += msg + "\n";
                }

                Text = UIUtils.WordWrap(text, Width - (Padding * 2), Style, new Vector2(Style.Scale));
                return(false);
            }
            else
            {
                Text = null;
                return(true);
            }
        }
Esempio n. 2
0
        public override void Draw(UISpriteBatch SBatch)
        {
            _InDraw = true;

            if (!Visible)
            {
                _InDraw = false;
                return;
            }

            if (m_Text != null && CaptionStyle != null)
            {
                if (m_Size != Rectangle.Empty)
                {
                    if (_Wrapped)
                    {
                        if (_WrappedOutput == null)
                        {
                            var scale = new Vector2(CaptionStyle.Scale);
                            _WrappedOutput = UIUtils.WordWrap(m_Text, m_Size.Width, CaptionStyle, MaxLines);
                        }

                        if (_WrappedOutput == null || _WrappedOutput.Lines == null)
                        {
                            _InDraw = false;
                            return;
                        }

                        var y = 0;
                        if ((Alignment & TextAlignment.Middle) == TextAlignment.Middle)
                        {
                            y = (m_Size.Height - _WrappedOutput.Height) / 2;
                        }
                        else if ((Alignment & TextAlignment.Bottom) == TextAlignment.Bottom)
                        {
                            y = m_Size.Height - _WrappedOutput.Height;
                        }

                        for (int i = 0; i < _WrappedOutput.Lines.Count; i++)
                        {
                            var line = _WrappedOutput.Lines[i];
                            var rect = new Rectangle(0, 0, m_Size.Width, CaptionStyle.LineHeight);
                            DrawLocalString(SBatch, line, new Vector2(0, y), CaptionStyle, rect, Alignment);
                            y += rect.Height;
                        }
                    }
                    else
                    {
                        DrawLocalString(SBatch, m_Text, Vector2.Zero, CaptionStyle, m_Size, Alignment);
                    }
                }
                else
                {
                    DrawLocalString(SBatch, m_Text, Vector2.Zero, CaptionStyle);
                }
            }

            _InDraw = false;
        }