verybadcat / CSharpMath

LaTeX. in C#. (ported from the wonderful iosMath project).
MIT License
384 stars 64 forks source link

TextAlignment doesn't work #123

Closed BenjaNapo closed 4 years ago

BenjaNapo commented 4 years ago

Bug Description

I'm using math:TextView for displaying math text and all works well, but when I try to display it with center alignment with the attribute TextAlignment="Center" it doesn't work. How can I fix it?

Happypig375 commented 4 years ago

What code are you using and what is the result?

Happypig375 commented 4 years ago

Will using HorizontalOptions="FillAndExpand" help? The MathView needs to occupy the entire space to align contents correctly.

BenjaNapo commented 4 years ago

What code are you using and what is the result?

Code: `

    </StackLayout>
</ContentPage.Content>`

Result: Screenshot_1591019608

Thanks, for the fast answer ^^

BenjaNapo commented 4 years ago

Will using HorizontalOptions="FillAndExpand" help? The MathView needs to occupy the entire space to align contents correctly.

I tried it, but doesn't even work

Happypig375 commented 4 years ago

The text is actually centered. Are you looking for justification?

BenjaNapo commented 4 years ago

The text is actually centered. Are you looking for justification?

Exactly, justification for Label it's called HorizontalTextAlignment

Happypig375 commented 4 years ago

Oh, I know what you mean:

123456789
this is what "centered" actually is

Happypig375 commented 4 years ago

Let me see if I can get this done today.

BenjaNapo commented 4 years ago

Oh, I know what you mean:

123456789 this is what "centered" actually is

Idk if it is possible to do, but I thought that TextAlignment had that use

Happypig375 commented 4 years ago

You can use

$$
\begin{gather}
\text{Centered}\\
\text{text}
\end{gather}
$$

as a workaround for now.

BenjaNapo commented 4 years ago

You can use

$$
\begin{gather}
\text{Centered}\\
\text{text}
\end{gather}
$$

as a workaround for now.

It seems working, but I need to get text from a binding...

<math:TextView LaTeX="{Binding Testo, Converter={StaticResource UrlDecoder}}" TextAlignment="Center" />

So if you say that in a week/month it will work with an update I can wait

Happypig375 commented 4 years ago

@BenjaNapo Take a look at #126 and see if that is what you need

charlesroddie commented 4 years ago

@Happypig375 can you translate this for me? What does this apply to? Is this xaml-specific, or Forms/Avalonia-specific? The comments in this issue suggests it is, but the changes in the PR involve core layers including CSharpMath.Rendering.

Happypig375 commented 4 years ago

@charlesroddie All uses of TextPainter.Draw with the TextAlignment overload.

BenjaNapo commented 4 years ago

@BenjaNapo Take a look at #126 and see if that is what you need

I'm a little noob using github, how can I merge your changes with my project?

Happypig375 commented 4 years ago

You can clone that branch locally, add the projects CSharpMath, CSharpMath.Editor, CSharpMath.Rendering, CSharpMath.SkiaSharp, CSharpMath.Xaml and CSharpMath.Forms to a test solution, and add a new project referencing CSharpMath.Forms.

Happypig375 commented 4 years ago

@BenjaNapo The fix has been merged! You can try whether the fix is successful by using the latest nightly packages.

Happypig375 commented 4 years ago

Oops wrong issue sorry

Happypig375 commented 4 years ago

Alright, the pull request has been merged for real this time. The commit is 810b47c314fc95ce7e1e3040deb6b3712147f32b

BenjaNapo commented 4 years ago

@BenjaNapo The fix has been merged! You can try whether the fix is successful by using the latest nightly packages.

Can you tell me what command should I put in the nuget console to get it works? Please

Happypig375 commented 4 years ago

@BenjaNapo Added https://github.com/verybadcat/CSharpMath#opting-in-to-the-nightly-feed

Happypig375 commented 4 years ago

Wait a moment. For some reason, the dependency version is out-of-date. image

Happypig375 commented 4 years ago

Above comment has been resolved

BenjaNapo commented 4 years ago

Above comment has been resolved

I finally implemented it and it seems works well but not at all, I did as you said in the documentation, so I:

  1. Created nuget.config and added relatives text with my credentials
  2. Replaced in .csproj
    <PackageReference Include="CSharpMath" Version="0.4.2" />
    <PackageReference Include="CSharpMath.Forms" Version="0.4.2" />

    With

    <PackageReference Include="CSharpMath" Version="0.4.2-ci-8cca3cc702ba45eb13e5bb1dff300a2ce37ded3d" />
    <PackageReference Include="CSharpMath.Forms" Version="0.4.2-ci-8cca3cc702ba45eb13e5bb1dff300a2ce37ded3d" />
  3. Went to the NuGet Manager and consolidated the version with mine
  4. Tested it with these lines of code

    <Grid Padding="20" VerticalOptions="StartAndExpand">
            <Grid.RowDefinitions>
                <RowDefinition Height="50*" />
                <RowDefinition Height="43*" />
                <RowDefinition Height="7*" />
            </Grid.RowDefinitions>
            <!--<Label
                HorizontalTextAlignment="Center"
                Text="{Binding DomandaAttuale.Testo, Converter={StaticResource UrlDecoder}}"
                VerticalOptions="Center" />-->
    
            <math:TextView
                Grid.Row="0"
                BackgroundColor="Red"
                FontSize="38"
                LaTeX="{Binding DomandaAttuale.Testo, Converter={StaticResource UrlDecoder}}"
                TextAlignment="Center" />
           ecc. ecc. ecc.

But that's the result: Screenshot_1592822716 As you can see there's some left padding that I didn't set

Happypig375 commented 4 years ago

Hmmm. Seems that text is centered but the whole block is shifted to the right. image

BenjaNapo commented 4 years ago

I found another bug, should I open a new issue? Or I wait the fix of this?

Happypig375 commented 4 years ago

You can open issues to report bugs whenever you want. They are free to create.

Happypig375 commented 4 years ago

@BenjaNapo This one should be fixed for good. Try the latest commit!

BenjaNapo commented 4 years ago

@BenjaNapo This one should be fixed for good. Try the latest commit!

Perfect! Now I'll try and let you know