Skip to content

Commit 3f5df94

Browse files
committed
Fixes #1165 by using DPI scaling for popup placement
1 parent 8e3ccb8 commit 3f5df94

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

Changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog for Fluent.Ribbon
22

3+
## 10.0.4
4+
5+
- ### Bug fixes
6+
7+
- [#1165](../../issues/1165) - ScreenTip is not DPI aware
8+
39
## 10.0.3
410

511
- ### Bug fixes

Fluent.Ribbon/Controls/ScreenTip.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,15 @@ private CustomPopupPlacement[] CustomPopupPlacementMethod(Size popupSize, Size t
6161
UIElement? topLevelElement = null;
6262
FindControls(this.PlacementTarget, ref ribbon, ref topLevelElement);
6363

64+
var dpiScale = VisualTreeHelper.GetDpi(this.PlacementTarget);
65+
6466
// Exclude QAT items
6567
var notQuickAccessItem = !IsQuickAccessItem(this.PlacementTarget);
6668
var notContextMenuChild = !IsContextMenuChild(this.PlacementTarget);
6769
var rightToLeftOffset = this.FlowDirection == FlowDirection.RightToLeft
6870
? -popupSize.Width
6971
: 0;
72+
var rightToLeftOffsetScaled = rightToLeftOffset * dpiScale.DpiScaleX;
7073

7174
var decoratorChild = GetDecoratorChild(topLevelElement);
7275

@@ -75,9 +78,12 @@ private CustomPopupPlacement[] CustomPopupPlacementMethod(Size popupSize, Size t
7578
&& ribbon is not null)
7679
{
7780
var belowY = ribbon.TranslatePoint(new Point(0, ribbon.ActualHeight), this.PlacementTarget).Y;
81+
belowY *= dpiScale.DpiScaleY;
7882
var aboveY = ribbon.TranslatePoint(new Point(0, 0), this.PlacementTarget).Y - popupSize.Height;
79-
var below = new CustomPopupPlacement(new Point(rightToLeftOffset, belowY + 1), PopupPrimaryAxis.Horizontal);
80-
var above = new CustomPopupPlacement(new Point(rightToLeftOffset, aboveY - 1), PopupPrimaryAxis.Horizontal);
83+
aboveY *= dpiScale.DpiScaleY;
84+
85+
var below = new CustomPopupPlacement(new Point(rightToLeftOffsetScaled, belowY + 1), PopupPrimaryAxis.Horizontal);
86+
var above = new CustomPopupPlacement(new Point(rightToLeftOffsetScaled, aboveY - 1), PopupPrimaryAxis.Horizontal);
8187
return new[] { below, above };
8288
}
8389

@@ -89,16 +95,19 @@ private CustomPopupPlacement[] CustomPopupPlacementMethod(Size popupSize, Size t
8995
{
9096
// Placed on Popup?
9197
var belowY = decoratorChild.TranslatePoint(new Point(0, ((FrameworkElement)decoratorChild).ActualHeight), this.PlacementTarget).Y;
98+
belowY *= dpiScale.DpiScaleY;
9299
var aboveY = decoratorChild.TranslatePoint(new Point(0, 0), this.PlacementTarget).Y - popupSize.Height;
93-
var below = new CustomPopupPlacement(new Point(rightToLeftOffset, belowY + 1), PopupPrimaryAxis.Horizontal);
94-
var above = new CustomPopupPlacement(new Point(rightToLeftOffset, aboveY - 1), PopupPrimaryAxis.Horizontal);
100+
aboveY *= dpiScale.DpiScaleY;
101+
102+
var below = new CustomPopupPlacement(new Point(rightToLeftOffsetScaled, belowY + 1), PopupPrimaryAxis.Horizontal);
103+
var above = new CustomPopupPlacement(new Point(rightToLeftOffsetScaled, aboveY - 1), PopupPrimaryAxis.Horizontal);
95104
return new[] { below, above };
96105
}
97106

98107
return new[]
99108
{
100-
new CustomPopupPlacement(new Point(rightToLeftOffset, this.PlacementTarget.RenderSize.Height + 1), PopupPrimaryAxis.Horizontal),
101-
new CustomPopupPlacement(new Point(rightToLeftOffset, -popupSize.Height - 1), PopupPrimaryAxis.Horizontal)
109+
new CustomPopupPlacement(new Point(rightToLeftOffsetScaled, (this.PlacementTarget.RenderSize.Height + 1) * dpiScale.DpiScaleY), PopupPrimaryAxis.Horizontal),
110+
new CustomPopupPlacement(new Point(rightToLeftOffsetScaled, (-popupSize.Height - 1) * dpiScale.DpiScaleY), PopupPrimaryAxis.Horizontal)
102111
};
103112
}
104113

0 commit comments

Comments
 (0)