Skip to content

Commit 303dbbd

Browse files
committed
review comments
1 parent 010898f commit 303dbbd

1 file changed

Lines changed: 37 additions & 17 deletions

File tree

packages/devtools_app/lib/src/shared/ui/hover.dart

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ const _maxHoverCardContentHeight = 250.0;
1818
const _hoverCardTitleHeight = 24.0;
1919
const _hoverCardDividerHeight = 16.0;
2020

21-
/// The total maximum height of the [HoverCard] including content, title,
22-
/// divider, vertical padding, and borders.
23-
const _totalMaxHoverCardHeight =
24-
_maxHoverCardContentHeight +
25-
_hoverCardTitleHeight +
26-
_hoverCardDividerHeight +
27-
(denseSpacing * 2) +
28-
(hoverCardBorderSize * 2);
21+
/// Returns the total maximum height of the [HoverCard] including content,
22+
/// title (if present), divider, vertical padding, and borders.
23+
double _totalMaxHoverCardHeight({
24+
required bool hasTitle,
25+
double maxCardContentHeight = _maxHoverCardContentHeight,
26+
}) {
27+
return maxCardContentHeight +
28+
(hasTitle ? _hoverCardTitleHeight + _hoverCardDividerHeight : 0.0) +
29+
(denseSpacing * 2) +
30+
(hoverCardBorderSize * 2);
31+
}
2932

3033
TextStyle get _hoverTitleTextStyle => fixBlurryText(
3134
const TextStyle(
@@ -230,31 +233,40 @@ class HoverCard {
230233
context: context,
231234
contents: contents,
232235
width: width,
233-
position: _calculateCardPositionFromPointerEvent(context, event, width),
236+
position: _calculateCardPositionFromPointerEvent(
237+
context,
238+
event,
239+
width,
240+
title: title,
241+
),
234242
title: title,
235243
hoverCardController: hoverCardController,
236244
);
237245

238246
static Offset _calculateCardPositionFromPointerEvent(
239247
BuildContext context,
240248
PointerHoverEvent event,
241-
double width,
242-
) {
249+
double width, {
250+
String? title,
251+
}) {
243252
final overlayBox =
244253
Overlay.of(context).context.findRenderObject() as RenderBox;
245254
final overlaySize = overlayBox.size;
255+
final localPosition = overlayBox.globalToLocal(event.position);
246256

247257
final maxX = math.max(
248258
_hoverMargin,
249259
overlaySize.width - _hoverMargin - width,
250260
);
251-
final x = (event.position.dx - (width / 2.0)).clamp(_hoverMargin, maxX);
261+
final x = (localPosition.dx - (width / 2.0)).clamp(_hoverMargin, maxX);
252262

253263
final maxY = math.max(
254264
_hoverMargin,
255-
overlaySize.height - _hoverMargin - _totalMaxHoverCardHeight,
265+
overlaySize.height -
266+
_hoverMargin -
267+
_totalMaxHoverCardHeight(hasTitle: title != null),
256268
);
257-
final y = (event.position.dy + _hoverYOffset).clamp(_hoverMargin, maxY);
269+
final y = (localPosition.dy + _hoverYOffset).clamp(_hoverMargin, maxY);
258270

259271
return Offset(x, y);
260272
}
@@ -546,7 +558,10 @@ class _HoverCardTooltipState extends State<HoverCardTooltip> {
546558
title: hoverCardData.title,
547559
contents: hoverCardData.contents,
548560
width: hoverCardData.width,
549-
position: _calculateCardPosition(hoverCardData.width),
561+
position: _calculateCardPosition(
562+
hoverCardData.width,
563+
title: hoverCardData.title,
564+
),
550565
hoverCardController: _hoverCardController,
551566
),
552567
);
@@ -573,7 +588,10 @@ class _HoverCardTooltipState extends State<HoverCardTooltip> {
573588
return completer;
574589
}
575590

576-
Offset _calculateCardPosition(double width) {
591+
Offset _calculateCardPosition(
592+
double width, {
593+
String? title,
594+
}) {
577595
final overlayBox =
578596
Overlay.of(context).context.findRenderObject() as RenderBox;
579597
final box = context.findRenderObject() as RenderBox;
@@ -584,7 +602,9 @@ class _HoverCardTooltipState extends State<HoverCardTooltip> {
584602
);
585603
final maxY = math.max(
586604
_hoverMargin,
587-
overlayBox.size.height - _hoverMargin - _totalMaxHoverCardHeight,
605+
overlayBox.size.height -
606+
_hoverMargin -
607+
_totalMaxHoverCardHeight(hasTitle: title != null),
588608
);
589609

590610
final offset = box.localToGlobal(

0 commit comments

Comments
 (0)