Giter Site home page Giter Site logo

Comments (7)

mimbrown avatar mimbrown commented on June 29, 2024 1

@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 Paragraph class passed to drawParagraph.

The basic problem statement is, the classes passed to the various draw* commands in the Canvas class don't seem like they were designed to be useful outside of their native implementations. There's no particular reason for this that I can think of except that it just hasn't been done yet.

from flutter.

huycozy avatar huycozy commented on June 29, 2024

the passed Path does not seem to support actually accessing the history of the commands (lineTo, moveTo, etc) used to define the path.

Similarly the Paragraph passed to drawParagraph doesn't expose the actual text itself (that I can tell), which I would need.

Could you please be more specific by giving an example of these expectations?

from flutter.

mimbrown avatar mimbrown commented on June 29, 2024

@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 moveTo followed by a lineTo). So I implement drawPath:

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
        }
      }
    }
  }
}

from flutter.

huycozy avatar huycozy commented on June 29, 2024

Thanks for clarifying it. Marking this as a feature request.

from flutter.

jonahwilliams avatar jonahwilliams commented on June 29, 2024

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.

from flutter.

mimbrown avatar mimbrown commented on June 29, 2024

@jonahwilliams I'm a bit confused because your suggestion is exactly what I'm trying to do but can't because of how it works under the hood. I'm trying to write my own canvas recorder. As far as I know, I can't override how the dart Path class in dart:ui works, so I can't do anything about how it gets instantiated/written to. But it's genuinely surprising to me that, when I implement my own drawPath class on my custom canvas, I get a Path object that's practically useless. I can't "draw" it because it exposes none of the actual path information. It's all obfuscated in the native implementation.

from flutter.

github-actions avatar github-actions commented on June 29, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

from flutter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.