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

Fixed bad test for TryModifyOrCreate to call InvalidateVisual in Shape #14694

Merged
merged 1 commit into from
Mar 5, 2024
Merged

Fixed bad test for TryModifyOrCreate to call InvalidateVisual in Shape #14694

merged 1 commit into from
Mar 5, 2024

Conversation

dbriard
Copy link
Contributor

@dbriard dbriard commented Feb 22, 2024

I think there is a mistake with Shape invalidate visual, as nothing happen when I change, for example, the StrokeJoin property.

What does the pull request do?

Remove the '!' in the following test:

if (!Pen.TryModifyOrCreate(ref _strokePen, Stroke, StrokeThickness, StrokeDashArray, StrokeDashOffset, StrokeLineCap, StrokeJoin))
{
    InvalidateVisual();
}

What is the current behavior?

Currently, when the Stroke properties change such as StrokeJoin, the visual is not invalidated.

What is the updated/expected behavior with this PR?

The visual of the Shape is now updated on Stroke properties change.

How was the solution implemented (if it's not obvious)?

Just negated the test on Pen.TryModifyOrCreate as visual invalidation is required when this method return True, not False:
/// <returns>If a new instance was created and visual invalidation required.</returns>

Here I create a Rectangle with StrokeJoin = Miter by default, and cycle the StrokeJoin value with a button, the rect is not updated.

<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
    <Rectangle
        x:Name="rect"
        Width="200"
        Height="200"
        Stroke="Red"
        StrokeThickness="50" />
    <TextBlock Text="{Binding StrokeJoin, ElementName=rect}" />
    <Button x:Name="strokeJoinBtn" Content="Cycle StrokeJoin" />
</StackPanel>

It should be round here:
image

It become round only if I resize the window to clip the rectangle for example.
image

@dbriard dbriard changed the title Fixed bad test for TryModifyOrCreate to call InvalidateVisual Fixed bad test for TryModifyOrCreate to call InvalidateVisual in Shape Feb 22, 2024
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.1.999-cibuild0045240-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@@ -254,7 +254,7 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
InvalidateMeasure();
}

if (!Pen.TryModifyOrCreate(ref _strokePen, Stroke, StrokeThickness, StrokeDashArray, StrokeDashOffset, StrokeLineCap, StrokeJoin))
if (Pen.TryModifyOrCreate(ref _strokePen, Stroke, StrokeThickness, StrokeDashArray, StrokeDashOffset, StrokeLineCap, StrokeJoin))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should just call InvalidateVisual all the time here because otherwise setting the Stroke to null will not update the rendering

Copy link
Member

@maxkatz6 maxkatz6 Feb 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point of TryModifyOrCreate is to modify underlying Pen instance without invalidating whole shape. I.e. pen itself will trigger next composition render pass.
Or are you referring to something else?

@maxkatz6 maxkatz6 added this pull request to the merge queue Mar 5, 2024
Merged via the queue into AvaloniaUI:master with commit 539ad33 Mar 5, 2024
6 checks passed
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

Successfully merging this pull request may close these issues.

4 participants