Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial implementation of TextBlock.Inlines #1689

Closed
wants to merge 7 commits into from
Closed

Conversation

grokys
Copy link
Member

@grokys grokys commented Jun 22, 2018

This PR adds TextBlock.Inlines and a couple of TextElements:

  • Run
  • LineBreak

This allows one to format the text within a TextBlock, e.g.:

        <TextBlock>
          A <Run Classes="code">TextBlock</Run> with <Run FontWeight="Bold">differing</Run>
          <Run FontStyle="Italic">styles</Run> <Run FontSize="24">and fonts</Run>.
        </TextBlock>

Currently only works fully on Direct2D. The Skia backend currently only supports Foreground in FormattedText - it will need to be updated with the new properties introduced in this PR. If anyone would like to implement these in Skia, please do!

There are also more TextElements to add, such as Span and InlineUIContainer. These will come in a separate PR I think.

}
else if (Count == 1)
{
return ((IHasText)this[0]).Text ?? string.Empty;
Copy link
Contributor

@Karnah Karnah Jun 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If TextBlock contains only <LineBreak /> - this code throw exception. May be use "is IHasText"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find, as always! :)

@Karnah
Copy link
Contributor

Karnah commented Jun 23, 2018

As I understand, you will not allow use TextElement into TextBlock?

@grokys
Copy link
Member Author

grokys commented Jun 25, 2018

Sorry @Karnah - I don't understand?

@Karnah
Copy link
Contributor

Karnah commented Jun 26, 2018

I didn't know that in TextBlock I can use <Run /> and always format by another TextBlocks. Now I've tried and found out that you also can use TextBoxes in TextBlock in WPF!

<TextBlock>
    I see trees of <TextBlock Foreground="ForestGreen" Text="green" />, red roses too
    <LineBreak />
    I see them <TextBox Text="{Binding Bloom}" /> for me and you
    <LineBreak />
    And I think to myself what a <Run FontWeight="Bold" Text="wonderful world" />
</TextBlock>

2018-06-26_09-44-33

It's hard for me to decide, is it necessary to support TextBlock and TextBox or not. But as I can understand, if you decide supporty this types, you should inherit them from Inline. Or am I wrong? Or this you'll implement in future? And I decided to clarify this :)

@grokys grokys added this to the 0.7.0 milestone Jul 5, 2018
@grokys
Copy link
Member Author

grokys commented Jul 7, 2018

@Karnah ok, I think I understand: yes what you're asking for is InlineUIContainer which is an Inline which wraps controls. I mentioned this in the description above, and yes - we should probably have this if possible, though I'm not sure how difficult it would be!

/// <param name="text">The text to format.</param>
/// <returns>A <see cref="FormattedText"/> object.</returns>
protected virtual FormattedText CreateFormattedText(Size constraint, string text)
[Obsolete("Remove this")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just remove this anyway, since the next version is going to be 0.7 and we already have several other
breaking changes?

@Gillibald
Copy link
Contributor

I have merged everything with the Skia text layout PR if someone wants to try this.
https://github.com/Gillibald/Avalonia/tree/feature/SkiaInlines

@grokys grokys modified the milestones: 0.7.0, 0.9 Apr 7, 2019
@grokys
Copy link
Member Author

grokys commented Apr 26, 2019

Closing as this is superseded by #2423

@grokys grokys closed this Apr 26, 2019
@grokys grokys deleted the textelements branch April 26, 2019 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants