rasitayaz / flutter-pie-menu

A Flutter package providing a highly customizable circular/radial context menu
https://rasitayaz.github.io/flutter-pie-menu/
MIT License
33 stars 18 forks source link

Always render actions from center of the `child` #52

Closed sadespresso closed 7 months ago

sadespresso commented 9 months ago

Fixes #50

This PR adds alwaysPlaceActionFromCenter option to PieTheme, default to false. When set to true forces PieMenu to be rendered from the center of the child. Especially useful when using PieMenu with small buttons, such as FloatingActionButton.

When alwaysPlaceActionFromCenter = false: image image

When alwaysPlaceActionFromCenter = true: image

Not a breaking change, everything will continue to work as before

Tested on Android, iOS, Linux

NewbieJess13 commented 8 months ago

This is what I need for my project, For now I used @sadespresso fork and hopefully merged with the package. Thank you @rasitayaz & @sadespresso!!

sadespresso commented 7 months ago

Okay, lemme do that and send you review request again :D :D

sadespresso commented 7 months ago

So, I've updated the code per your recommendations, and they look quite great!

When alwaysPlaceActionFromCenter is true, the attachMenu sets _pointerOffset.

Upon pointer up, it dismisses the menu only if the pointer fails menu hit test.

sadespresso commented 7 months ago

Tested, and confirmed that the new implementation works the same as before.

rasitayaz commented 7 months ago

what's the purpose of hit test?

sadespresso commented 7 months ago

Because _pointerOffset is artificially moved to the center of the menu button, it makes '_isBeyondPointerBounds' behave incorrectly.

As I understand, a simple tap should leave the menu open. A drag triggers action only if the pointer is on the action, and dismissed the menu otherwise.

Putting hit test on the menu button ensures the behaviors mentioned above to work correctly.

sadespresso commented 7 months ago

If we remove the hit test, a simple tap will just dismiss the menu, and dragging to an action will not trigger the action; requiring an additional tap. which i believe, isn't the expected behavior

Instead of hit test, we can get the original pointer position and do distance check like one in the _isBeyondPointerBounds

rasitayaz commented 7 months ago

thank you, I'll take it from here. I might introduce alignment and offset variables instead of alwaysPlaceActionFromCenter to expand this feature.