Skip to content

Commit

Permalink
Fixes #1165 by using DPI scaling for popup placement
Browse files Browse the repository at this point in the history
  • Loading branch information
batzen committed Sep 4, 2023
1 parent 8e3ccb8 commit 3f5df94
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog for Fluent.Ribbon

## 10.0.4

- ### Bug fixes

- [#1165](../../issues/1165) - ScreenTip is not DPI aware

## 10.0.3

- ### Bug fixes
Expand Down
21 changes: 15 additions & 6 deletions Fluent.Ribbon/Controls/ScreenTip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,15 @@ private CustomPopupPlacement[] CustomPopupPlacementMethod(Size popupSize, Size t
UIElement? topLevelElement = null;
FindControls(this.PlacementTarget, ref ribbon, ref topLevelElement);

var dpiScale = VisualTreeHelper.GetDpi(this.PlacementTarget);

// Exclude QAT items
var notQuickAccessItem = !IsQuickAccessItem(this.PlacementTarget);
var notContextMenuChild = !IsContextMenuChild(this.PlacementTarget);
var rightToLeftOffset = this.FlowDirection == FlowDirection.RightToLeft
? -popupSize.Width
: 0;
var rightToLeftOffsetScaled = rightToLeftOffset * dpiScale.DpiScaleX;

var decoratorChild = GetDecoratorChild(topLevelElement);

Expand All @@ -75,9 +78,12 @@ private CustomPopupPlacement[] CustomPopupPlacementMethod(Size popupSize, Size t
&& ribbon is not null)
{
var belowY = ribbon.TranslatePoint(new Point(0, ribbon.ActualHeight), this.PlacementTarget).Y;
belowY *= dpiScale.DpiScaleY;
var aboveY = ribbon.TranslatePoint(new Point(0, 0), this.PlacementTarget).Y - popupSize.Height;
var below = new CustomPopupPlacement(new Point(rightToLeftOffset, belowY + 1), PopupPrimaryAxis.Horizontal);
var above = new CustomPopupPlacement(new Point(rightToLeftOffset, aboveY - 1), PopupPrimaryAxis.Horizontal);
aboveY *= dpiScale.DpiScaleY;

var below = new CustomPopupPlacement(new Point(rightToLeftOffsetScaled, belowY + 1), PopupPrimaryAxis.Horizontal);
var above = new CustomPopupPlacement(new Point(rightToLeftOffsetScaled, aboveY - 1), PopupPrimaryAxis.Horizontal);
return new[] { below, above };
}

Expand All @@ -89,16 +95,19 @@ private CustomPopupPlacement[] CustomPopupPlacementMethod(Size popupSize, Size t
{
// Placed on Popup?
var belowY = decoratorChild.TranslatePoint(new Point(0, ((FrameworkElement)decoratorChild).ActualHeight), this.PlacementTarget).Y;
belowY *= dpiScale.DpiScaleY;
var aboveY = decoratorChild.TranslatePoint(new Point(0, 0), this.PlacementTarget).Y - popupSize.Height;
var below = new CustomPopupPlacement(new Point(rightToLeftOffset, belowY + 1), PopupPrimaryAxis.Horizontal);
var above = new CustomPopupPlacement(new Point(rightToLeftOffset, aboveY - 1), PopupPrimaryAxis.Horizontal);
aboveY *= dpiScale.DpiScaleY;

var below = new CustomPopupPlacement(new Point(rightToLeftOffsetScaled, belowY + 1), PopupPrimaryAxis.Horizontal);
var above = new CustomPopupPlacement(new Point(rightToLeftOffsetScaled, aboveY - 1), PopupPrimaryAxis.Horizontal);
return new[] { below, above };
}

return new[]
{
new CustomPopupPlacement(new Point(rightToLeftOffset, this.PlacementTarget.RenderSize.Height + 1), PopupPrimaryAxis.Horizontal),
new CustomPopupPlacement(new Point(rightToLeftOffset, -popupSize.Height - 1), PopupPrimaryAxis.Horizontal)
new CustomPopupPlacement(new Point(rightToLeftOffsetScaled, (this.PlacementTarget.RenderSize.Height + 1) * dpiScale.DpiScaleY), PopupPrimaryAxis.Horizontal),
new CustomPopupPlacement(new Point(rightToLeftOffsetScaled, (-popupSize.Height - 1) * dpiScale.DpiScaleY), PopupPrimaryAxis.Horizontal)
};
}

Expand Down

0 comments on commit 3f5df94

Please sign in to comment.