dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.98k stars 1.72k forks source link

MAUI's `ICanvas` should have `SetTransform` and `ResetTransform` #4866

Closed simonsarris closed 2 years ago

simonsarris commented 2 years ago

Description

The MAUI ICanvas has several transform methods but is lacking the commonly-found SetTransform or ResetTransform methods. The docs here say:

The only ICanvas method that accepts a Matrix3x2 argument is the ConcatenateTransform method, which combines multiple transforms into a single transform.

This "only" is very unusual. SkiaSharp has both set and reset methods, as does HTML CanvasRenderingContext2D.

Of course ResetTransform is not strictly necessary, you can call SetTransform with identity. But having neither makes it very annoying to get the MAUI Graphics ICanvas back to identity transform without resetting all of its state, or creating a transform to try and cancel-out the current transform. Calling ICanvas.ResetState is unacceptable, as it destroys the Font, colors, alpha, etc.

Public API Changes

ICanvas.SetTransform(Matrix3x2 matrix); // Replaces the ICanvas current matrix values with the supplied matrix
ICanvas.ResetTransform(); // Resets the ICanvas current matrix to identity

Intended Use-Case

I author JS and C# Diagramming libraries, and am in the process of updating the C# one that uses GDI+, which is terribly slow, to MAUI/Skia, which is nice and fast. My code uses a lot of transforms and something like SetTransform is very useful when drawing persistent objects that maintain their own coordinates in the visual tree.

simonsarris commented 2 years ago

Sorry, closing this in favor of an issue in Maui.Graphics: https://github.com/dotnet/Microsoft.Maui.Graphics/issues/325