Skip to content

Commit

Permalink
feat: 鉁ˋdd tooltipOffset property
Browse files Browse the repository at this point in the history
  • Loading branch information
guenth39 committed Apr 11, 2024
1 parent 3ea39ba commit 30906ec
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ class MailTile extends StatelessWidget {
targetBorderRadius: const BorderRadius.all(
Radius.circular(150),
),
tooltipOffset: const Offset(20, -5),
container: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Expand Down
8 changes: 8 additions & 0 deletions lib/src/showcase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ class Showcase extends StatefulWidget {
/// Disables barrier interaction for a particular showCase.
final bool disableBarrierInteraction;

/// Defines the tooltip offset from the target widget.
///
/// Default to Offset.zero
final Offset tooltipOffset;

const Showcase({
required this.key,
required this.description,
Expand Down Expand Up @@ -292,6 +297,7 @@ class Showcase extends StatefulWidget {
this.descriptionTextDirection,
this.onBarrierClick,
this.disableBarrierInteraction = false,
this.tooltipOffset = Offset.zero,
}) : height = null,
width = null,
container = null,
Expand Down Expand Up @@ -332,6 +338,7 @@ class Showcase extends StatefulWidget {
this.tooltipPosition,
this.onBarrierClick,
this.disableBarrierInteraction = false,
this.tooltipOffset = Offset.zero,
}) : showArrow = false,
onToolTipClick = null,
scaleAnimationDuration = const Duration(milliseconds: 300),
Expand Down Expand Up @@ -621,6 +628,7 @@ class _ShowcaseState extends State<Showcase> {
descriptionPadding: widget.descriptionPadding,
titleTextDirection: widget.titleTextDirection,
descriptionTextDirection: widget.descriptionTextDirection,
tooltipOffset: widget.tooltipOffset,
),
],
],
Expand Down
20 changes: 13 additions & 7 deletions lib/src/tooltip_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class ToolTipWidget extends StatefulWidget {
final EdgeInsets? descriptionPadding;
final TextDirection? titleTextDirection;
final TextDirection? descriptionTextDirection;
final Offset tooltipOffset;

const ToolTipWidget({
Key? key,
Expand All @@ -89,6 +90,7 @@ class ToolTipWidget extends StatefulWidget {
required this.tooltipBorderRadius,
required this.scaleAnimationDuration,
required this.scaleAnimationCurve,
required this.tooltipOffset,
this.scaleAnimationAlignment,
this.isTooltipDismissed = false,
this.tooltipPosition,
Expand Down Expand Up @@ -183,9 +185,9 @@ class _ToolTipWidgetState extends State<ToolTipWidget>
if ((leftPositionValue + width) > widget.screenSize.width) {
return null;
} else if ((leftPositionValue) < _kDefaultPaddingFromParent) {
return _kDefaultPaddingFromParent;
return _kDefaultPaddingFromParent + widget.tooltipOffset.dx;
} else {
return leftPositionValue;
return leftPositionValue + widget.tooltipOffset.dx;
}
}
return null;
Expand All @@ -201,7 +203,7 @@ class _ToolTipWidgetState extends State<ToolTipWidget>
final rightPosition = widget.position!.getCenter() + (width * 0.5);

return (rightPosition + width) > widget.screenSize.width
? _kDefaultPaddingFromParent
? _kDefaultPaddingFromParent + widget.tooltipOffset.dx
: null;
} else {
return null;
Expand All @@ -217,7 +219,7 @@ class _ToolTipWidgetState extends State<ToolTipWidget>
} else if (space < (widget.contentWidth! / 2)) {
space = 16;
}
return space;
return space + widget.tooltipOffset.dx;
}

double _getAlignmentX() {
Expand Down Expand Up @@ -341,10 +343,12 @@ class _ToolTipWidgetState extends State<ToolTipWidget>
contentOrientation == TooltipPosition.bottom ? 1.0 : -1.0;
isArrowUp = contentOffsetMultiplier == 1.0;

final contentY = isArrowUp
var contentY = isArrowUp
? widget.position!.getBottom() + (contentOffsetMultiplier * 3)
: widget.position!.getTop() + (contentOffsetMultiplier * 3);

contentY = contentY + widget.tooltipOffset.dy;

final num contentFractionalOffset =
contentOffsetMultiplier.clamp(-1.0, 0.0);

Expand Down Expand Up @@ -546,14 +550,16 @@ class _ToolTipWidgetState extends State<ToolTipWidget>
double? _getArrowLeft(double arrowWidth) {
final left = _getLeft();
if (left == null) return null;
return (widget.position!.getCenter() - (arrowWidth / 2) - left);
return (widget.position!.getCenter() - (arrowWidth / 2) - left) +
widget.tooltipOffset.dx;
}

double? _getArrowRight(double arrowWidth) {
if (_getLeft() != null) return null;
return (widget.screenSize.width - widget.position!.getCenter()) -
(_getRight() ?? 0) -
(arrowWidth / 2);
(arrowWidth / 2) +
widget.tooltipOffset.dx;
}
}

Expand Down

0 comments on commit 30906ec

Please sign in to comment.