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

TextTrimming - Trim at start #283

Open
Symbai opened this issue Dec 13, 2023 · 9 comments
Open

TextTrimming - Trim at start #283

Symbai opened this issue Dec 13, 2023 · 9 comments

Comments

@Symbai
Copy link

Symbai commented Dec 13, 2023

Is your feature request related to a problem? Please describe.

Sometimes its more useful to trim a text at the beginning instead of end.

Describe the solution you'd like

Be able to trim at the beginning. Either by extending the existing TextTrimming enum or by adding a new property

enum TextTrimLocation
{
    End = 0,
    Start = 1,
    Middle = 2 //not requested but in this case to complete the list
}

Describe alternatives you've considered

Using a custom converter

Additional context

@timunie
Copy link
Contributor

timunie commented Dec 13, 2023

Isn't it supported already? AvaloniaUI/Avalonia#7322

@timunie
Copy link
Contributor

timunie commented Dec 13, 2023

works already

<TextBlock Text="Hello world from long text" MaxWidth="100">
	<TextBlock.TextTrimming>
		<TextLeadingPrefixTrimming>
			<x:Arguments>
				<system:String> ▲ ▲ ▲ </system:String>
				<system:Int32>3</system:Int32>
			</x:Arguments>
		</TextLeadingPrefixTrimming>
	</TextBlock.TextTrimming>
</TextBlock>

image

@timunie timunie closed this as not planned Won't fix, can't repro, duplicate, stale Dec 13, 2023
@Symbai
Copy link
Author

Symbai commented Dec 13, 2023

Jesus, this looks so "over complicated ". Instead of a single line we have now 8 lines to write... for EVERY single textblock. Also in your example it trims at the middle of text. How to trim at the beginning? I dont even understand how this works. Is there any documentation?!

@jp2masa
Copy link

jp2masa commented Dec 13, 2023

Jesus, this looks so "over complicated ". Instead of a single line we have now 8 lines to write... for EVERY single textblock.

I think you can define a resource and then use it: <TextBlock TextTrimming="{StaticResource MyTrimming}" />

Also in your example it trims at the middle of text. How to trim at the beginning?

I think the second argument corresponds to the length of the prefix to keep, so you would set it to 0 instead of 3.

Not sure if there are docs for this yet. You can see the docs in this class:

https://github.com/AvaloniaUI/Avalonia/blob/73f7fd1d3eed0a9cb0bb7757a1ee1b728f68af6a/src/Avalonia.Base/Media/TextTrimming.cs

You're probably looking for this:

https://github.com/AvaloniaUI/Avalonia/blob/73f7fd1d3eed0a9cb0bb7757a1ee1b728f68af6a/src/Avalonia.Base/Media/TextTrimming.cs#L33-L36

So I guess you can do <TextBlock TextTrimming="{x:Static TextTrimming.LeadingCharacterEllipsis}" />

@timunie timunie reopened this Dec 13, 2023
@timunie timunie transferred this issue from AvaloniaUI/Avalonia Dec 13, 2023
@timunie
Copy link
Contributor

timunie commented Dec 14, 2023

@Symbai that was only one possible syntax if you need trimming in middle of the string and want pure XAML.

other working solutions:

  • Use static or dynamic resource
  • use pre-defined members via {x:Static TextTrimming.xxx}
  • add static properties to a custom class

... We may want to extend docs here, so I transferred this issue.

@Symbai
Copy link
Author

Symbai commented Dec 14, 2023

So I guess you can do <TextBlock TextTrimming="{x:Static TextTrimming.LeadingCharacterEllipsis}" />

That is pretty cool, thank you. I hope the docs will show this example. While its cool that you can do crazy stuff I think many people are only interesting in basic scenarios and prefer short and clean solutions.

@timunie
Copy link
Contributor

timunie commented Dec 14, 2023

<TextBlock TextTrimming="LeadingCharacterEllipsis" />
can you try if this also works?

@Gillibald
Copy link

Looks like we did not add these new trimming modes to the parse method: https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Base/Media/TextTrimming.cs#L49

@timunie
Copy link
Contributor

timunie commented Dec 15, 2023

@Gillibald should I create a tracking issue for this? Would there be an option to make parameters work like LeadingCharacterEllipsis('...',3) which already works for scale(1.5)?

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

No branches or pull requests

4 participants