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

TextMask Alignment #171

Closed
gviddy opened this issue Jul 31, 2021 · 3 comments · Fixed by #172
Closed

TextMask Alignment #171

gviddy opened this issue Jul 31, 2021 · 3 comments · Fixed by #172
Assignees
Labels
🛠️ enhancement New feature or request
Milestone

Comments

@gviddy
Copy link

gviddy commented Jul 31, 2021

I am having issues getting text to align to the start of a row. Is this a limitation of the system? Or am I doing it wrong?

Text always appears to be centered.

            <Grid HeightRequest="32">
                <magic:GradientView HorizontalOptions="Start" WidthRequest="400" BackgroundColor="Red">
                    <magic:GradientView.Mask>
                        <magic:TextMask Text="{Binding WalletTypeStr}" FontSize="22"/>
                    </magic:GradientView.Mask>
                    <magic:LinearGradient Angle="-90">
                        <magic:GradientStop Color="#A9CDFF" Offset="0" />
                        <magic:GradientStop Color="#72F6D1" Offset="0.25"/>
                        <magic:GradientStop Color="#A0ED8D" Offset="0.5"/>
                        <magic:GradientStop Color="#FED365" Offset="0.75"/>
                        <magic:GradientStop Color="#FAA49E" Offset="1.0"/>
                    </magic:LinearGradient>
                </magic:GradientView>
            </Grid>
@mgierlasinski
Copy link
Owner

Hi @gviddy
Clipping always works from the center of GradientView by design, there is no layout or alignment options at the moment. For proper positioning you need to put GradientView inside one of Xamarin.Forms layout containers, something like:

         <Grid HeightRequest="32" WidthRequest="400" BackgroundColor="Red">
                <magic:GradientView HorizontalOptions="Start" WidthRequest="60">
                    <magic:GradientView.Mask>
                        <magic:TextMask Text="Hello" FontSize="22"/>
                    </magic:GradientView.Mask>
                    <magic:LinearGradient Angle="-90">
                        <magic:GradientStop Color="#A9CDFF" Offset="0" />
                        <magic:GradientStop Color="#72F6D1" Offset="0.25"/>
                        <magic:GradientStop Color="#A0ED8D" Offset="0.5"/>
                        <magic:GradientStop Color="#FED365" Offset="0.75"/>
                        <magic:GradientStop Color="#FAA49E" Offset="1.0"/>
                    </magic:LinearGradient>
                </magic:GradientView>
            </Grid>

Unfortunately because you have binding here and WalletTypeStr can be anything, you have to measure text and set correct width instead of WidthRequest="60".

You can also extend TextMask and do your custom drawing. TextMask is really a PathMask with some text related properties. There is a method LayoutBounds in GradientMask base class which does the positioning and stretching:
LayoutBounds

I will improve positioning in next update by adding TextAlignment for text mask.

@mgierlasinski mgierlasinski self-assigned this Aug 4, 2021
@mgierlasinski mgierlasinski added the 🛠️ enhancement New feature or request label Aug 4, 2021
@mgierlasinski mgierlasinski added this to the v1.3.1 milestone Aug 4, 2021
@mgierlasinski
Copy link
Owner

Hi @gviddy
New version has just been released. Two properties were added to TextMask: HorizontalTextAlignment and VerticalTextAlignment.

@gviddy
Copy link
Author

gviddy commented Sep 10, 2021

Hi @gviddy
New version has just been released. Two properties were added to TextMask: HorizontalTextAlignment and VerticalTextAlignment.

Oh that's awesome. Thank you. I will give it a go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🛠️ enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants