Ejemplo n.º 1
0
        /// <inheritdoc/>
        protected override void Render(TextBox control, PaintEventArgs e)
        {
            var text = control.Text.Length > 0 ? control.Text : control.Placeholder;

            // Bail early if we don't need to draw anything
            if (text.Length == 0 && !control.Selected)
            {
                return;
            }

            var block = GetTextBlock(control);

            UpdateScrollBars(control, block);

            e.Canvas.Save();
            e.Canvas.Clip(control.PaddedClientRectangle);

            if (text.Length > 0)
            {
                e.Canvas.DrawTextBlock(block, GetTextOrigin(control), GetTextSelection(control));
            }

            if (control.Selected)
            {
                var caret = TextMeasurer.GetCursorLocation(block, GetTextOrigin(control), GetCursorIndex(control), GetCurrentFontSize(control));
                e.Canvas.DrawRectangle(caret, Theme.PrimaryTextColor);
            }

            e.Canvas.Restore();
        }