-
Notifications
You must be signed in to change notification settings - Fork 26.7k
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
Able to access the history of the draw commands in Canvas #148631
Comments
Could you please be more specific by giving an example of these expectations? |
@huycozy sure. For example, a Widget's painter might do something like this: final path = Path();
path.moveTo(0, 0);
path.lineTo(5, 5);
canvas.drawPath(path, paint); In my custom Canvas implementation, I need to know what commands were called (in this case, a class MyCanvas implements Canvas {
@override
void drawPath(Path path, Paint paint) {
// `path` was called with `moveTo(0, 0)` and `lineTo(5, 5)`, but I can't extract that information
// I would like to do something like this (`getCommands` doesn't exist)
for (final command in path.getCommands()) {
// do something with command
switch (command) {
case MoveTo(:x, :y): {
// build svg
}
}
}
}
} |
Thanks for clarifying it. Marking this as a feature request. |
@huycozy that's just one example of what I feel is missing. Another would be accessing the sets of styled "runs" of text from the The basic problem statement is, the classes passed to the various |
We're not going to add the functionality to introspect over all canvas operations. I would suggest writing shim classes that intercept the path/canvas ops you care about and then implementing your own recorder in Dart. |
Use case
I would like to write a custom class which implements
Canvas
so that I can experiment with writing a Widget -> SVG converter. But the Flutter classes don't seem to give me the necessary information I would have expected to have in order to do this. For example, when implementingdrawPath
, the passedPath
does not seem to support actually accessing the history of the commands (lineTo
,moveTo
, etc) used to define the path. Similarly theParagraph
passed todrawParagraph
doesn't expose the actual text itself (that I can tell), which I would need.Proposal
I see in the source that the
Path
andParagraph
classes are wrappers around native implementations. Could these and otherdart:ui
types expose, in the wrapper and its implementations, the information necessary to actually do something meaningful in pure Dart? My use case is generating SVG I'm sure there are others.For example, something like
getSegments()
on thePath
class that outputs an array of the commands given to define the path would enable what I'm trying to do. I don't know all that would be required in which classes, so I don't know how big of an ask this is. But the main ask is, please expose what is necessary for custom implementations to do meaningful things.The text was updated successfully, but these errors were encountered: