Skip to content

Rendering Shapes without explicit bounds.#5817

Merged
Redth merged 5 commits intodotnet:mainfrom
VSadov:shape
Apr 26, 2022
Merged

Rendering Shapes without explicit bounds.#5817
Redth merged 5 commits intodotnet:mainfrom
VSadov:shape

Conversation

@VSadov
Copy link
Member

@VSadov VSadov commented Apr 5, 2022

Description of Change

Bounds of a Shape can be inferred from its shape and specifying that should not be required.
Currently not specifying Height and Width makes lines and other shapes not render.

Issues Fixed

Fixes #4044
Fixes #6204
Fixes #4051

@VSadov
Copy link
Member Author

VSadov commented Apr 5, 2022

== Before the change:
Before

@VSadov
Copy link
Member Author

VSadov commented Apr 5, 2022

=== After the change:
After

@VSadov VSadov requested a review from jsuarezruiz April 5, 2022 06:24
@VSadov VSadov added the area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing label Apr 5, 2022
@VSadov
Copy link
Member Author

VSadov commented Apr 6, 2022

The fix also fixes other demo scenarios like Polygon, Polyline and Path.


protected override Size MeasureOverride(double widthConstraint, double heightConstraint)
{
var result = base.MeasureOverride(widthConstraint, heightConstraint);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice. This is the important part that was missing.

return result;
}

var boundsByFlattening = this.GetPath().Bounds.Size;
Copy link
Contributor

Choose a reason for hiding this comment

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

In general everything looks really nice but there are a couple of wrong cases:

image
This ellipse should fill all the yellow space.

image
This should render a spiral path in the center.

Sometimes the bounds by flattening are wrong. For example, in the second case, Width and Height is zero.

Copy link
Member Author

Choose a reason for hiding this comment

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

if the spiral path scenario is similar to one in repro project for #4044, then I believe the reason for the 0x0 size is that we do not invalidate the Height/Width request for the PolyLine when after replacing its Points. I think we should.
If I do invalidation, then the spiral path renders correctly for me (at least in the repro project):

image

Copy link
Member Author

Choose a reason for hiding this comment

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

As for the ellipse scenario, I think my repro does not have an equivalent. There is a scenario with ellipses, but it is just a few simple fixed sized ellipse shapes and they show just fine.

How can I get the AutoSize Shapes Gallery ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Open the .NET MAUI Gallery and navigate to Controls -> Shapes. Then tap the "More samples" Button and select the "AutoSize Shapes Gallery".

Copy link
Member Author

Choose a reason for hiding this comment

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

There were two issues:

  • GetBoundsByFlattening with default 0.01 flatness produces clearly incorrect results for ellipse curves. Using flatness == 1 temporarily is a workaround, but there is likely a bug in GetBoundsByFlattening
  • MeasureOverride on Shape should consider Aspect. That was missing

Copy link
Member Author

Choose a reason for hiding this comment

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

After the last changes:

image

image

@Redth Redth added this to the 6.0.300-rc.3 milestone Apr 25, 2022
@VSadov
Copy link
Member Author

VSadov commented Apr 25, 2022

Is this ok to merge? I can't tell if failures on Android Device Tests Core (API 30) are infrastructure issues or related to the change.

@Redth
Copy link
Member

Redth commented Apr 25, 2022

Running the one another time, but I suspect the last failure is unrelated.

@mattleibow
Copy link
Member

What is the purpose of the pages in the sandbox app?

Should we move that to the gallery?

@Redth Redth merged commit de3acef into dotnet:main Apr 26, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Dec 23, 2023
@samhouts samhouts added the fixed-in-6.0.300-rc.3 Look for this fix in 6.0.300-rc.3! label Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing fixed-in-6.0.300-rc.3 Look for this fix in 6.0.300-rc.3!

Projects

None yet

5 participants