Browse Source

Added PlacementConstraintAdjustment property.

To `Popup` and `ContextMenu`. Set default value to be `FlipX | FlipY` to try to match WPF's defaults.
stable/outsystems-0.9
Steven Kirk 6 years ago
parent
commit
986955b3e8
  1. 18
      src/Avalonia.Controls/ContextMenu.cs
  2. 1
      src/Avalonia.Controls/Primitives/IPopupHost.cs
  3. 3
      src/Avalonia.Controls/Primitives/OverlayPopupHost.cs
  4. 19
      src/Avalonia.Controls/Primitives/Popup.cs
  5. 5
      src/Avalonia.Controls/Primitives/PopupPositioning/IPopupPositioner.cs
  6. 3
      src/Avalonia.Controls/Primitives/PopupRoot.cs

18
src/Avalonia.Controls/ContextMenu.cs

@ -20,7 +20,6 @@ namespace Avalonia.Controls
/// </summary>
public class ContextMenu : MenuBase, ISetterValue
{
/// <summary>
/// Defines the <see cref="HorizontalOffset"/> property.
/// </summary>
@ -39,6 +38,12 @@ namespace Avalonia.Controls
public static readonly StyledProperty<PopupAnchor> PlacementAnchorProperty =
Popup.PlacementAnchorProperty.AddOwner<ContextMenu>();
/// <summary>
/// Defines the <see cref="PlacementConstraintAdjustment"/> property.
/// </summary>
public static readonly StyledProperty<PopupPositionerConstraintAdjustment> PlacementConstraintAdjustmentProperty =
Popup.PlacementConstraintAdjustmentProperty.AddOwner<ContextMenu>();
/// <summary>
/// Defines the <see cref="PlacementGravity"/> property.
/// </summary>
@ -124,6 +129,16 @@ namespace Avalonia.Controls
set { SetValue(PlacementAnchorProperty, value); }
}
/// <summary>
/// Gets or sets a value describing how the context menu position will be adjusted if the
/// unadjusted position would result in the context menu being partly constrained.
/// </summary>
public PopupPositionerConstraintAdjustment PlacementConstraintAdjustment
{
get { return GetValue(PlacementConstraintAdjustmentProperty); }
set { SetValue(PlacementConstraintAdjustmentProperty, value); }
}
/// <summary>
/// Gets or sets a value which defines in what direction the context menu should open
/// when <see cref="PlacementMode"/> is <see cref="PlacementMode.AnchorAndGravity"/>.
@ -245,6 +260,7 @@ namespace Avalonia.Controls
HorizontalOffset = HorizontalOffset,
VerticalOffset = VerticalOffset,
PlacementAnchor = PlacementAnchor,
PlacementConstraintAdjustment = PlacementConstraintAdjustment,
PlacementGravity = PlacementGravity,
PlacementMode = PlacementMode,
PlacementRect = PlacementRect,

1
src/Avalonia.Controls/Primitives/IPopupHost.cs

@ -52,6 +52,7 @@ namespace Avalonia.Controls.Primitives
void ConfigurePosition(IVisual target, PlacementMode placement, Point offset,
PopupAnchor anchor = PopupAnchor.None,
PopupGravity gravity = PopupGravity.None,
PopupPositionerConstraintAdjustment constraintAdjustment = PopupPositionerConstraintAdjustment.All,
Rect? rect = null);
/// <summary>

3
src/Avalonia.Controls/Primitives/OverlayPopupHost.cs

@ -72,10 +72,11 @@ namespace Avalonia.Controls.Primitives
public void ConfigurePosition(IVisual target, PlacementMode placement, Point offset,
PopupAnchor anchor = PopupAnchor.None, PopupGravity gravity = PopupGravity.None,
PopupPositionerConstraintAdjustment constraintAdjustment = PopupPositionerConstraintAdjustment.All,
Rect? rect = null)
{
_positionerParameters.ConfigurePosition((TopLevel)_overlayLayer.GetVisualRoot(), target, placement, offset, anchor,
gravity, rect);
gravity, constraintAdjustment, rect);
UpdatePosition();
}

19
src/Avalonia.Controls/Primitives/Popup.cs

@ -41,6 +41,14 @@ namespace Avalonia.Controls.Primitives
public static readonly StyledProperty<PopupAnchor> PlacementAnchorProperty =
AvaloniaProperty.Register<Popup, PopupAnchor>(nameof(PlacementAnchor));
/// <summary>
/// Defines the <see cref="PlacementConstraintAdjustment"/> property.
/// </summary>
public static readonly StyledProperty<PopupPositionerConstraintAdjustment> PlacementConstraintAdjustmentProperty =
AvaloniaProperty.Register<Popup, PopupPositionerConstraintAdjustment>(
nameof(PlacementConstraintAdjustment),
PopupPositionerConstraintAdjustment.FlipX | PopupPositionerConstraintAdjustment.FlipY);
/// <summary>
/// Defines the <see cref="PlacementGravity"/> property.
/// </summary>
@ -165,6 +173,16 @@ namespace Avalonia.Controls.Primitives
set { SetValue(PlacementAnchorProperty, value); }
}
/// <summary>
/// Gets or sets a value describing how the popup position will be adjusted if the
/// unadjusted position would result in the popup being partly constrained.
/// </summary>
public PopupPositionerConstraintAdjustment PlacementConstraintAdjustment
{
get { return GetValue(PlacementConstraintAdjustmentProperty); }
set { SetValue(PlacementConstraintAdjustmentProperty, value); }
}
/// <summary>
/// Gets or sets a value which defines in what direction the popup should open
/// when <see cref="PlacementMode"/> is <see cref="PlacementMode.AnchorAndGravity"/>.
@ -311,6 +329,7 @@ namespace Avalonia.Controls.Primitives
new Point(HorizontalOffset, VerticalOffset),
PlacementAnchor,
PlacementGravity,
PlacementConstraintAdjustment,
PlacementRect);
DeferCleanup(SubscribeToEventHandler<IPopupHost, EventHandler<TemplateAppliedEventArgs>>(popupHost, RootTemplateApplied,

5
src/Avalonia.Controls/Primitives/PopupPositioning/IPopupPositioner.cs

@ -428,13 +428,14 @@ namespace Avalonia.Controls.Primitives.PopupPositioning
public static void ConfigurePosition(ref this PopupPositionerParameters positionerParameters,
TopLevel topLevel,
IVisual target, PlacementMode placement, Point offset,
PopupAnchor anchor, PopupGravity gravity, Rect? rect)
PopupAnchor anchor, PopupGravity gravity,
PopupPositionerConstraintAdjustment constraintAdjustment, Rect? rect)
{
// We need a better way for tracking the last pointer position
var pointer = topLevel.PointToClient(topLevel.PlatformImpl.MouseDevice.Position);
positionerParameters.Offset = offset;
positionerParameters.ConstraintAdjustment = PopupPositionerConstraintAdjustment.All;
positionerParameters.ConstraintAdjustment = constraintAdjustment;
if (placement == PlacementMode.Pointer)
{
positionerParameters.AnchorRectangle = new Rect(pointer, new Size(1, 1));

3
src/Avalonia.Controls/Primitives/PopupRoot.cs

@ -84,10 +84,11 @@ namespace Avalonia.Controls.Primitives
public void ConfigurePosition(IVisual target, PlacementMode placement, Point offset,
PopupAnchor anchor = PopupAnchor.None,
PopupGravity gravity = PopupGravity.None,
PopupPositionerConstraintAdjustment constraintAdjustment = PopupPositionerConstraintAdjustment.All,
Rect? rect = null)
{
_positionerParameters.ConfigurePosition(_parent, target,
placement, offset, anchor, gravity, rect);
placement, offset, anchor, gravity, constraintAdjustment, rect);
if (_positionerParameters.Size != default)
UpdatePosition();

Loading…
Cancel
Save