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

Text aligned to top instead of center when changing LineHeight on TextBlock. #13873

Closed
Al12rs opened this issue Dec 7, 2023 · 6 comments · Fixed by #15481
Closed

Text aligned to top instead of center when changing LineHeight on TextBlock. #13873

Al12rs opened this issue Dec 7, 2023 · 6 comments · Fixed by #15481

Comments

@Al12rs
Copy link
Contributor

Al12rs commented Dec 7, 2023

Describe the bug

When changing the LineHeight or Height properties of a TextBlock, the text stays at a fixed distance from the top of the control, rather than being centered.

This causes both vertical text alignment problems as well as text clipping problems at lower line heights.

image

To Reproduce

Steps to reproduce the behavior:

Code sample:

<ResourceDictionary xmlns="https://github.com/avaloniaui"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Design.PreviewWith>
        <Border Padding="20">
            <StackPanel Spacing="10">
                <Border BorderThickness="1" BorderBrush="White" Padding="0" Margin="10">
                    <TextBlock Theme="{StaticResource WithLineHeightExample}"
                               Text="The quick brown fox jumps over the lazy dog (LH=50)" />
                </Border>
                <Border BorderThickness="1" BorderBrush="White" Padding="0" Margin="10">
                    <TextBlock Theme="{StaticResource WithoutLineHeightExample}"
                               Text="The quick brown fox jumps over the lazy dog (LH=NaN)" />
                </Border>
                <Border BorderThickness="1" BorderBrush="White" Padding="0" Margin="10">
                    <TextBlock Theme="{StaticResource WithNegativeLineHeightExample}"
                               Text="The quick brown fox jumps over the lazy dog (LN=18)" />
                </Border>
            </StackPanel>
        </Border>
    </Design.PreviewWith>

    <ControlTheme x:Key="WithLineHeightExample" TargetType="TextBlock" >
        <Setter Property="FontWeight" Value="SemiBold" />
        <Setter Property="FontSize" Value="18" />
        <Setter Property="LineHeight" Value="50" />
    </ControlTheme>

    <ControlTheme x:Key="WithoutLineHeightExample" TargetType="TextBlock">
        <Setter Property="FontWeight" Value="SemiBold" />
        <Setter Property="FontSize" Value="18" />
        <Setter Property="LineHeight" Value="NaN" />
    </ControlTheme>

    <ControlTheme x:Key="WithNegativeLineHeightExample" TargetType="TextBlock">
        <Setter Property="FontWeight" Value="SemiBold" />
        <Setter Property="FontSize" Value="18" />
        <Setter Property="Height" Value="18"/>
    </ControlTheme>
</ResourceDictionary>

Expected Behaviour

The text should be placed in the center of the available height, not at a fixed distance from the top.
This is to avoid alignment issues as well as potential clipping issues at lower LineHeight values (e.g. 120%)

This is how the line-height behaves for normal CSS, and how I would expect Avalonia to work as well:
image

Environment

  • OS: Windows
  • Avalonia-Version: 11.0.5
@Al12rs Al12rs added the bug label Dec 7, 2023
@Al12rs Al12rs changed the title Text remains aligned to the top instead of being centered when changing LineHeight or Height of TextBlock. Text aligned to top instead of center when changing LineHeight or Height of TextBlock. Dec 7, 2023
@Al12rs Al12rs changed the title Text aligned to top instead of center when changing LineHeight or Height of TextBlock. Text aligned to top instead of center when changing LineHeight on TextBlock. Dec 7, 2023
@Gillibald Gillibald self-assigned this Dec 7, 2023
@halgari
Copy link
Contributor

halgari commented Apr 18, 2024

What can I do to help with this ticket? It's a pretty glaring issue in our application and I'd rather not do some sort of hack (like manual offsets of the text)

@timunie
Copy link
Contributor

timunie commented Apr 18, 2024

You can reach out to the team in case you have a support agreement.

@Gillibald
Copy link
Contributor

LineHeight should be distributed evenly now. Are you sure this is still an issue?

@halgari
Copy link
Contributor

halgari commented Apr 22, 2024

@Gillibald When was this fixed? I don't see a PR attached to this ticket and I wasn't able to find anything in the changelog about it. We're using the latest version of Avalonia and haven't seen any change to the line height

@halgari
Copy link
Contributor

halgari commented Apr 23, 2024

This is still broken on 11.1.0-beta and 11.0.10

line_height

@Al12rs
Copy link
Contributor Author

Al12rs commented Apr 25, 2024

Thanks for the fix! Really appreciate it!

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