Browse Source

Allow CreateFormattedText to have the string it renders overridden.

pull/1544/head
Dan Walmsley 9 years ago
parent
commit
58daa9390b
  1. 11
      src/Avalonia.Controls/Presenters/TextPresenter.cs
  2. 11
      src/Avalonia.Controls/Primitives/AccessText.cs
  3. 7
      src/Avalonia.Controls/TextBlock.cs

11
src/Avalonia.Controls/Presenters/TextPresenter.cs

@ -211,14 +211,19 @@ namespace Avalonia.Controls.Presenters
} }
} }
protected override FormattedText CreateFormattedText(Size constraint) protected override FormattedText CreateFormattedText(Size constraint, string text)
{ {
FormattedText result = null;
if (PasswordChar != default(char)) if (PasswordChar != default(char))
{ {
Text = new string(PasswordChar, Text.Length); result = base.CreateFormattedText(constraint, new string(PasswordChar, Text.Length));
}
else
{
result = base.CreateFormattedText(constraint, Text);
} }
var result = base.CreateFormattedText(constraint);
var selectionStart = SelectionStart; var selectionStart = SelectionStart;
var selectionEnd = SelectionEnd; var selectionEnd = SelectionEnd;
var start = Math.Min(selectionStart, selectionEnd); var start = Math.Min(selectionStart, selectionEnd);

11
src/Avalonia.Controls/Primitives/AccessText.cs

@ -83,16 +83,9 @@ namespace Avalonia.Controls.Primitives
/// </summary> /// </summary>
/// <param name="constraint">The constraint of the text.</param> /// <param name="constraint">The constraint of the text.</param>
/// <returns>A <see cref="FormattedText"/> object.</returns> /// <returns>A <see cref="FormattedText"/> object.</returns>
protected override FormattedText CreateFormattedText(Size constraint) protected override FormattedText CreateFormattedText(Size constraint, string text)
{ {
return new FormattedText return base.CreateFormattedText(constraint, StripAccessKey(text));
{
Constraint = constraint,
Typeface = new Typeface(FontFamily, FontSize, FontStyle, FontWeight),
Text = StripAccessKey(Text),
TextAlignment = TextAlignment,
Wrapping = TextWrapping,
};
} }
/// <summary> /// <summary>

7
src/Avalonia.Controls/TextBlock.cs

@ -197,7 +197,7 @@ namespace Avalonia.Controls
{ {
if (_formattedText == null) if (_formattedText == null)
{ {
_formattedText = CreateFormattedText(_constraint); _formattedText = CreateFormattedText(_constraint, Text);
} }
return _formattedText; return _formattedText;
@ -348,14 +348,15 @@ namespace Avalonia.Controls
/// Creates the <see cref="FormattedText"/> used to render the text. /// Creates the <see cref="FormattedText"/> used to render the text.
/// </summary> /// </summary>
/// <param name="constraint">The constraint of the text.</param> /// <param name="constraint">The constraint of the text.</param>
/// <param name="text">The text to generated the <see cref="FormattedText"/> for.</param>
/// <returns>A <see cref="FormattedText"/> object.</returns> /// <returns>A <see cref="FormattedText"/> object.</returns>
protected virtual FormattedText CreateFormattedText(Size constraint) protected virtual FormattedText CreateFormattedText(Size constraint, string text)
{ {
return new FormattedText return new FormattedText
{ {
Constraint = constraint, Constraint = constraint,
Typeface = new Typeface(FontFamily, FontSize, FontStyle, FontWeight), Typeface = new Typeface(FontFamily, FontSize, FontStyle, FontWeight),
Text = Text ?? string.Empty, Text = text ?? string.Empty,
TextAlignment = TextAlignment, TextAlignment = TextAlignment,
Wrapping = TextWrapping, Wrapping = TextWrapping,
}; };

Loading…
Cancel
Save