-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Refactor text trimming and implement prefix trimming. #7322
Refactor text trimming and implement prefix trimming. #7322
Conversation
I was worried when I saw the TextTrimming enum being dropped -- there is a lot of existing code that uses this both in XAML and C#. This is a smartly designed change though and it looks easy to integrate into existing apps. The new PrefixEllipsis is very welcome and has been missing, well, forever in XAML. It's a great idea! Using "This is the longest name" as an example it seems the following is possible: Word: "This is the longest..." What about the case where only the beginning should be trimmed with an ellipse? This is useful for file paths and other types of text where most significant info is at the end. In WPF there was no way to do this: "... the longest name". I'm assuming it can be done now with PrefixEllipsis and the length set to zero? Just want to be sure that case is fully supported. Then I wonder if actually PrefixEllipsis with length set to zero should be the default instead of an arbitrary length of 8 characters. This would make it symmetrical by default with character trimming at the end. Finally, can the PrefixEllipsis length be set in XAML? If so, what is the syntax? The docs really should be updated for that. Edit: The name "PrefixEllipsis" where did it come from? It doesn't actually match with the other terms. It might be better to call this "PrefixCharacterEllipsis" and leave the door open for a future "PrefixWordEllipsis" as well. |
Hi, Imo this is an interesting idea. I have two questions/suggestions if you don't mind:
Happy coding |
Trimming happens on TextLine level and for collapsed lines this is set https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Visuals/Media/TextFormatting/TextLine.cs#L56 |
Maybe it might make sense to introduce a position property on TextTrimming so we are able to chose on which side the text is trimmed. PrefixLength will become OmittedLength or something. |
...rkup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlLanguageParseIntrinsics.cs
Show resolved
Hide resolved
Thank you for your detailed reply So I could check if this property is true for any line, if I want to know if any trimming happened? public abstract bool HasOverflowed { get; } |
You can look for lines that have |
Thank you @Gillibald. Now I got it. 👍 |
I realize we probably need a separate spec discussion for this. Fundamentally, there are a few different generalized concepts:
This all could and probably should be calculated using a single generalized method which would support:
Usage in code would involve the following fields:
Open Questions:
|
Under CSS there is a spec for this without a prefix length: https://developer.mozilla.org/en-US/docs/Web/CSS/text-overflow It is possible to trim text at both sides and also define a custom symbol individually. So we could adapt this syntax but need to add the Prefix/SuffixLength |
CSS has some good ideas like making the overflow indicator a configurable string. That could also be implemented relatively easily in the underlying functionality here. I will also amend the table above. PrefixLength/SuffixLength can really be the same property. It can also apply to word break mode. |
Closing due to inactivity and merge conflicts. @MarchingCube reopen this if it's gonna be worked on again :) |
Will resolve conflicts in a few hours |
I don't think this is quite general-purpose enough. Merging as-is may very well be a restriction in the future. This is brand-new functionality. API and features should be well discussed IMO. |
Had a quick look at this and it seems master did diverge too much recently. We might need to recreate everything on top of master. |
@robloo We can add more advanced trimming modes after this PR got merged. This is mainly aiming on being able to customize the text trimming by replacing the TextTrimming enum with a class that is responsible for TextLine collapsing. |
Alright, as long as the API isn't locked after this. Some of my comments about naming of the new class members should be considered at least though. |
a17f110
to
05fc177
Compare
@Gillibald I have found some time to resolve conflicts. Since text formatting changes are mostly wrapped up we can revisit this PR again. I've added a TODO to both ellipsis functions since I'm not dealing with flow direction yet. Also I've added If prefix trimming is too controversial to include now we can also look into text formatting API to let users implement it externally. Since I would be fine with moving this implementation to my project until we figure out API surface and how to configure it. In my opinion it should only work with character level trimming since prefix length is given in characters. Ellipsis symbol is already configurable in my PR (each trimming ctor takes it). Only problem would be XAML syntax although we might be missing a few features in there to make this work (constructor params primarily). Although I would expect users to either create a new static trimming property and reference it via |
My recommendation is to at least:
|
src/Avalonia.Visuals/Media/TextFormatting/TextEllipsisHelper.cs
Outdated
Show resolved
Hide resolved
c91a9ae
to
47ad3d7
Compare
src/Avalonia.Visuals/Media/TextFormatting/TextCollapsingProperties.cs
Outdated
Show resolved
Hide resolved
You can test this PR using the following package version. |
You can test this PR using the following package version. |
What does the pull request do?
Current text trimming setup was fairly limiting and didn't allow users to customize behavior (for example using custom ellipsis symbols) or parametrize trimming.
I'm also adding new kind of trimming that could be found in programs like Adobe After Effects (trimming that keeps a fixed prefix and has ellipsis in the middle). Such trimming is useful in cases where prefix and suffix is more important than content in the middle.
This trimming mode is configurable so new changed API is immediately useful here.
prefix-trimming.mp4
I've implemented XAML compiler intrinsic handling for both text trimming and decorations. Previously if one used
TextDecorations="Underline"
it would create a completely new collection of decorations.What is the current behavior?
One cannot easily configure trimming behavior and only trailing word/character trimming is available.
What is the updated/expected behavior with this PR?
Users can create custom trimming configuration and use it with
TextBlock
. One can enable newPrefixEllipsis
to see new trimming in action.How was the solution implemented (if it's not obvious)?
Using an enum is not enough to configure trimming fully so instead it is a class. I've added static properties that have matching names with old enum members, this is comparable to
TextDecorations
.Checklist
Breaking changes
TextTrimming
is no longer an enum. This breaks binary compatibility. XAML files should compile as is, most of usages in code will work too. Only cases when user expectedTextTrimming
to be an enum won't work.Obsoletions / Deprecations
Fixed issues