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

solution to make text receive touchs detector #28

Open
Marrawi1994 opened this issue Aug 2, 2021 · 0 comments
Open

solution to make text receive touchs detector #28

Marrawi1994 opened this issue Aug 2, 2021 · 0 comments

Comments

@Marrawi1994
Copy link

Hello ...
first thanks you for developing awesome library
I noticed that drawParagraph function didn't have any touch detector
so I created my workaround solution :
1- draw text via textPainter class, like this :

  double x = 100; // Offset -> x
  double y = 100; // Offset -> y

  final textSpan = TextSpan(
      text: 'Hello world',
      style: TextStyle(color: Colors.black, fontSize: 20),
    );

    final textPainter = TextPainter(
      text: textSpan, textDirection: TextDirection.ltr
    );

    textPainter.layout(minWidth: 0, maxWidth: double.infinity);
    textPainter.paint(canvas, Offset(x, y));
    // canvas is the original canvas ( not TouchyCanvas )

2- create new transparent rect with same size as text like this:

  TouchyCanvas myCanvas = TouchyCanvas(context, canvas);
  Paint rectPaint = Paint()..color = Colors.transparent;
  Rect rect = Offset(x, y) & Size(textPainter.width, textPainter.height);
  myCanvas.drawRect(rect, rectPaint);

now you could do anything like translating 👍
just don't forget to translate text and rect

waiting for your big update !!

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

No branches or pull requests

1 participant