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

TextAlignment.DetectFromContent with an RTL line and TextWrapping produces a width of 0 #16009

Closed
Bip901 opened this issue Jun 12, 2024 · 6 comments · Fixed by #17721
Closed

Comments

@Bip901
Copy link

Bip901 commented Jun 12, 2024

Describe the bug

Consider the following text box which has 3 lines, one of them in Hebrew, a right-to-left language:

<TextBox Text="Hello&#10;שלום&#10;Really really really really long line"
		 Background="Beige"
		 HorizontalAlignment="Center"
		 MinWidth="0"
		 TextAlignment="DetectFromContent"
		 Height="68"
		 TextWrapping="Wrap"/>

The TextBox incorrectly measures a width of 0:

incorrect

(It has some width in the screenshot above due to padding, disable with Padding="0")

To Reproduce

Use the XML provided above.

Expected behavior

The TextBox should have the same width as it has when TextAlignment is set to Left:

correct

<TextBox Text="Hello&#10;שלום&#10;Really really really really long line"
			Background="Beige"
			HorizontalAlignment="Center"
			MinWidth="0"
			TextAlignment="Left"
			Height="68"
			TextWrapping="Wrap"/>

Avalonia version

11.0.10

OS

No response

Additional context

No response

@dbriard
Copy link
Contributor

dbriard commented Jun 12, 2024

I have a similar with ContentPresenter and TextAlignment.
I am using TextAlignment="Center" in a TemplatedControl.
The control display well in designer, but when the control is used in the real app, in a view that is already visible on screen. The texts are empty.

Designer:
image

App:
image

If I resize the window so that Measure of the control is called, or if I change view and get back (e.g. in a tab control), the display is now correct
image

Same issue with TextAlignment="Right", but no problem with Left.

Avalonia 11.0.1 beta 2

You can repro using the Theme of the HeaderedContentControl and adding TextAlignement="Center" for the ContentPresenter.

@Gillibald Gillibald self-assigned this Jun 12, 2024
@dbriard
Copy link
Contributor

dbriard commented Jun 21, 2024

Another example of the issue with TextAlignment=Center: (no issue with HorizontalAlignment=Center)
image
I can use HorizontalAlignment instead of TextAlignement at the moment, but centering is not exactly the same. HorizontalAlignment is not perfectly centered, and don't work on multilines.

And another issue with text: not sure if it is the same bug or not but sometime the end of the text is not visible in ToolTips.
I display Bounds in a ToolTip:
image
image

I am using Segoe UI font in Windows 11 (scale 100%) with 11.1 RC1.
FontSize=12 but I got issue with all Font Sizes with TextAlignment.

@Bip901
Copy link
Author

Bip901 commented Jun 21, 2024

And another issue with text: not sure if it is the same bug or not but sometime the end of the text is not visible in ToolTips.

That seems unrelated, the text is simply too long for the remaining space.
You could use a TextWrapping value of WrapWithOverflow or increase the width of the ToolTip.

@dbriard
Copy link
Contributor

dbriard commented Jul 1, 2024

And another issue with text: not sure if it is the same bug or not but sometime the end of the text is not visible in ToolTips.

That seems unrelated, the text is simply too long for the remaining space. You could use a TextWrapping value of WrapWithOverflow or increase the width of the ToolTip.

I double checked and the tooltip is limited to 240 pixels wide with TextWrapping... so there is no reason that the text is truncated.
I also tried WrapWithOverflow instead of Wrap is the result is the same.

May some kind of rounding error, or a measure that is not called.

@dbriard
Copy link
Contributor

dbriard commented Jul 10, 2024

Until the bug is fixed, here a ugly workaround for tooltips if someone need:

public class TruncatedToolTipWorkaroundConverter : IValueConverter
{
    public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        if (value is string s)
        {
            return s + ' ';
        }
        return value;
    }

    public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

Then in ToolTip theme:
Content="{TemplateBinding Content, Converter={StaticResource TruncatedToolTipWorkaroundConverter}}"

The tooltip is no more truncated at the end, but there is an additional whitespace, so small tooltips are no more centered.

@Gillibald
Copy link
Contributor

This is unrelated to the original issue. Please create a new issue with a detailed reproducible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants