Пример #1
0
        public TextField(float width, float height, string text = "", TextFormat format = null)
        {
            _text    = text != null ? text : "";
            _hitArea = Rectangle.Create(0, 0, width, height);
            _requiresRecomposition = true;
            _compositor            = DefaultCompositor;
            _options = new TextOptions();

            _format = format != null?format.Clone() : new TextFormat();

            _format.ChangeEvent += SetRequiresRecomposition;

            _meshBatch               = new MeshBatch();
            _meshBatch.Touchable     = false;
            _meshBatch.PixelSnapping = true;
            AddChild(_meshBatch);

            SparrowSharp.ContextCreated += SetRequiresRecomposition;
        }
Пример #2
0
        /// <summary>
        /// Forces the text contents to be composed right away.
        /// Normally, it will only do so lazily, i.e. before being rendered.
        /// </summary>
        private void Recompose()
        {
            if (_requiresRecomposition)
            {
                _compositor.ClearMeshBatch(_meshBatch);

                string          fontName   = _format.Font;
                ITextCompositor compositor = GetCompositor(fontName);

                if (compositor == null && fontName == BitmapFont.MINI)
                {
                    compositor = new BitmapFont();
                    RegisterCompositor(compositor, fontName);
                }

                _compositor = compositor != null ? compositor : DefaultCompositor;

                UpdateText();
                UpdateBorder();

                _requiresRecomposition = false;
            }
        }