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

Feat/tooltip position #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion lib/src/pie_canvas_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'package:pie_menu/src/pie_menu.dart';
import 'package:pie_menu/src/pie_provider.dart';
import 'package:pie_menu/src/pie_theme.dart';
import 'package:pie_menu/src/platform/base.dart';
import 'package:vector_math/vector_math.dart' hide Colors;
import 'package:vector_math/vector_math.dart' hide Colors, Matrix4;

/// Controls functionality and appearance of [PieCanvas].
class PieCanvasCore extends StatefulWidget {
Expand Down Expand Up @@ -391,6 +391,27 @@ class PieCanvasCoreState extends State<PieCanvasCore>
}

if (tooltipAlignment != null) {
// If the tooltip is centered, use a Flow widget to
// position it relative to the pointer.
if (tooltipAlignment == Alignment.center) {
return Flow(
delegate: PieDelegate(
bounceAnimation: _buttonBounceAnimation,
pointerOffset: _pointerOffset,
canvasOffset: _canvasOffset,
baseAngle: _baseAngle,
angleDiff: _angleDiff,
theme: _theme,
constraints: BoxConstraints(
minWidth: 0,
maxWidth: cw,
minHeight: 0,
maxHeight: ch,
),
),
children: [child],
);
}
return Align(
alignment: tooltipAlignment,
child: child,
Expand Down
21 changes: 16 additions & 5 deletions lib/src/pie_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ class PieDelegate extends FlowDelegate {
required this.baseAngle,
required this.angleDiff,
required this.theme,
}) : super(repaint: bounceAnimation);
BoxConstraints? constraints,
}) : _constraints = constraints,
super(repaint: bounceAnimation);

/// Bouncing animation for the buttons.
final Animation bounceAnimation;
Expand All @@ -36,6 +38,11 @@ class PieDelegate extends FlowDelegate {
/// Theme to use for the [PieMenu].
final PieTheme theme;

/// Constraints of the [PieCanvas].
///
/// If null, the constraints are calculated based on the theme.
final BoxConstraints? _constraints;

@override
bool shouldRepaint(PieDelegate oldDelegate) {
return bounceAnimation != oldDelegate.bounceAnimation;
Expand Down Expand Up @@ -78,9 +85,13 @@ class PieDelegate extends FlowDelegate {
}

@override
BoxConstraints getConstraintsForChild(int i, BoxConstraints constraints) {
return BoxConstraints.tight(
Size.square(i == 0 ? theme.pointerSize : theme.buttonSize),
);
BoxConstraints getConstraintsForChild(
int i,
BoxConstraints constraints,
) {
return _constraints ??
BoxConstraints.tight(
Size.square(i == 0 ? theme.pointerSize : theme.buttonSize),
);
}
}
3 changes: 3 additions & 0 deletions lib/src/pie_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ class PieTheme {
/// Alignment of the tooltip in the [PieCanvas].
///
/// Setting this property will disable dynamic tooltip positioning.
///
/// Setting this property to [Alignment.center] will center the tooltip
/// on the pressed position.
final Alignment? tooltipCanvasAlignment;

/// Whether to wrap the tooltip with [FittedBox] widget.
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: pie_menu
description: A Flutter package providing a highly customizable circular/radial context menu
version: 3.2.1
version: 3.3.0
homepage: https://github.com/rasitayaz/flutter-pie-menu
repository: https://github.com/rasitayaz/flutter-pie-menu
issue_tracker: https://github.com/rasitayaz/flutter-pie-menu/issues
Expand Down