-
Notifications
You must be signed in to change notification settings - Fork 401
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change the display method of Popup Overlay on Windows (#1485)
* Change the display method of Windows Popup Overlay * Invert overlay colors * Change popup overlay color * Change the transparency of Popup overlay * Update src/CommunityToolkit.Maui.Core/Views/Popup/PopupOverlay.windows.cs Co-authored-by: Vladislav Antonyuk <[email protected]> * Add Null Check, Create `AddOverlayToWindow` * Update src/CommunityToolkit.Maui.Core/Handlers/Popup/PopUpHandler.windows.cs * Update src/CommunityToolkit.Maui.Core/Views/Popup/PopupOverlay.windows.cs * Update formatting --------- Co-authored-by: Vladislav Antonyuk <[email protected]> Co-authored-by: Brandon Minnick <[email protected]>
- Loading branch information
1 parent
5a4f7ea
commit 40a3e38
Showing
2 changed files
with
77 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/CommunityToolkit.Maui.Core/Views/Popup/PopupOverlay.windows.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
namespace CommunityToolkit.Maui.Core.Views; | ||
|
||
/// <summary> | ||
/// Displays Overlay in the Popup background. | ||
/// </summary> | ||
class PopupOverlay : WindowOverlay | ||
{ | ||
readonly IWindowOverlayElement popupOverlayElement; | ||
|
||
/// <summary> | ||
/// Instantiates a new instance of <see cref="PopupOverlay"/>. | ||
/// </summary> | ||
/// <param name="window">An instance of <see cref="IWindow"/>.</param> | ||
/// <param name="overlayColor">Popup overlay color</param> | ||
public PopupOverlay(IWindow window, Color? overlayColor = null) : base(window) | ||
{ | ||
popupOverlayElement = new PopupOverlayElement(this, overlayColor); | ||
|
||
AddWindowElement(popupOverlayElement); | ||
|
||
EnableDrawableTouchHandling = true; | ||
} | ||
|
||
class PopupOverlayElement : IWindowOverlayElement | ||
{ | ||
readonly IWindowOverlay overlay; | ||
readonly Color overlayColor = Color.FromRgba(255, 255, 255, 153); // 60% Opacity | ||
|
||
RectF overlayRect = new(); | ||
|
||
public PopupOverlayElement(IWindowOverlay overlay, Color? overlayColor = null) | ||
{ | ||
this.overlay = overlay; | ||
if (overlayColor is not null) | ||
{ | ||
this.overlayColor = overlayColor; | ||
} | ||
} | ||
|
||
public bool Contains(Point point) | ||
{ | ||
return overlayRect.Contains(new Point(point.X / overlay.Density, point.Y / overlay.Density)); | ||
} | ||
|
||
public void Draw(ICanvas canvas, RectF dirtyRect) | ||
{ | ||
overlayRect = dirtyRect; | ||
canvas.FillColor = overlayColor; | ||
canvas.FillRectangle(dirtyRect.X, dirtyRect.Y, dirtyRect.Width, dirtyRect.Height); | ||
} | ||
} | ||
} |