Browse Source
* Add CustomPopupPlacement API * Add Placement="Custom" support for Flyout, ToolTip and ContextMenu controls as well * Adjust some API changes * Add Avalonia.Controls.Primitives.IPopupHost.ConfigurePosition breaking change * Extract new types into separated files * Fix build after merge conflict * Adjust nupkg.xml * Dispose property subscriptions after popup is closed, avoiding flickering * Adjust API to be more future proof and add new parameters. * Add new ContextRequestedEventArgs overload while I am on itpull/16734/head
committed by
GitHub
20 changed files with 470 additions and 111 deletions
@ -0,0 +1,57 @@ |
|||||
|
namespace Avalonia.Controls.Primitives.PopupPositioning; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Defines custom placement parameters for a <see cref="CustomPopupPlacementCallback"/> callback.
|
||||
|
/// </summary>
|
||||
|
public record CustomPopupPlacement |
||||
|
{ |
||||
|
private PopupGravity _gravity; |
||||
|
private PopupAnchor _anchor; |
||||
|
|
||||
|
internal CustomPopupPlacement(Size popupSize, Visual target) |
||||
|
{ |
||||
|
PopupSize = popupSize; |
||||
|
Target = target; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The <see cref="Size"/> of the <see cref="Popup"/> control.
|
||||
|
/// </summary>
|
||||
|
public Size PopupSize { get; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Placement target of the popup.
|
||||
|
/// </summary>
|
||||
|
public Visual Target { get; } |
||||
|
|
||||
|
/// <see cref="PopupPositionerParameters.AnchorRectangle"/>
|
||||
|
public Rect AnchorRectangle { get; set; } |
||||
|
|
||||
|
/// <see cref="PopupPositionerParameters.Anchor"/>
|
||||
|
public PopupAnchor Anchor |
||||
|
{ |
||||
|
get => _anchor; |
||||
|
set |
||||
|
{ |
||||
|
PopupPositioningEdgeHelper.ValidateEdge(value); |
||||
|
_anchor = value; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <see cref="PopupPositionerParameters.Gravity"/>
|
||||
|
public PopupGravity Gravity |
||||
|
{ |
||||
|
get => _gravity; |
||||
|
set |
||||
|
{ |
||||
|
PopupPositioningEdgeHelper.ValidateGravity(value); |
||||
|
_gravity = value; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <see cref="PopupPositionerParameters.ConstraintAdjustment"/>
|
||||
|
public PopupPositionerConstraintAdjustment ConstraintAdjustment { get; set; } |
||||
|
|
||||
|
/// <see cref="PopupPositionerParameters.Offset"/>
|
||||
|
public Point Offset { get; set; } |
||||
|
} |
||||
@ -0,0 +1,6 @@ |
|||||
|
namespace Avalonia.Controls.Primitives.PopupPositioning; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Represents a method that provides custom positioning for a <see cref="Popup"/> control.
|
||||
|
/// </summary>
|
||||
|
public delegate void CustomPopupPlacementCallback(CustomPopupPlacement parameters); |
||||
@ -0,0 +1,35 @@ |
|||||
|
using Avalonia.Diagnostics; |
||||
|
using Avalonia.Metadata; |
||||
|
|
||||
|
namespace Avalonia.Controls.Primitives.PopupPositioning; |
||||
|
|
||||
|
[PrivateApi] |
||||
|
[Unstable(ObsoletionMessages.MayBeRemovedInAvalonia12)] |
||||
|
public class PopupPositionRequest |
||||
|
{ |
||||
|
internal PopupPositionRequest(Visual target, PlacementMode placement) |
||||
|
{ |
||||
|
Target = target; |
||||
|
Placement = placement; |
||||
|
} |
||||
|
|
||||
|
internal PopupPositionRequest(Visual target, PlacementMode placement, Point offset, PopupAnchor anchor, PopupGravity gravity, PopupPositionerConstraintAdjustment constraintAdjustment, Rect? anchorRect, CustomPopupPlacementCallback? placementCallback) |
||||
|
: this(target, placement) |
||||
|
{ |
||||
|
Offset = offset; |
||||
|
Anchor = anchor; |
||||
|
Gravity = gravity; |
||||
|
ConstraintAdjustment = constraintAdjustment; |
||||
|
AnchorRect = anchorRect; |
||||
|
PlacementCallback = placementCallback; |
||||
|
} |
||||
|
|
||||
|
public Visual Target { get; } |
||||
|
public PlacementMode Placement {get;} |
||||
|
public Point Offset {get;} |
||||
|
public PopupAnchor Anchor {get;} |
||||
|
public PopupGravity Gravity {get;} |
||||
|
public PopupPositionerConstraintAdjustment ConstraintAdjustment {get;} |
||||
|
public Rect? AnchorRect {get;} |
||||
|
public CustomPopupPlacementCallback? PlacementCallback {get;} |
||||
|
} |
||||
Loading…
Reference in new issue