Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PlacementMode -> Placement #10664

Merged
merged 10 commits into from
Mar 17, 2023
2 changes: 1 addition & 1 deletion samples/IntegrationTestApp/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private void ShowTransparentPopup()
var popup = new Popup
{
WindowManagerAddShadowHint = false,
PlacementMode = PlacementMode.AnchorAndGravity,
Placement = PlacementMode.AnchorAndGravity,
PlacementAnchor = PopupAnchor.Top,
PlacementGravity = PopupGravity.Bottom,
Width= 200,
Expand Down
103 changes: 45 additions & 58 deletions src/Avalonia.Controls/ContextMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,17 @@ public class ContextMenu : MenuBase, ISetterValue, IPopupHostProvider
public static readonly StyledProperty<PopupGravity> PlacementGravityProperty =
Popup.PlacementGravityProperty.AddOwner<ContextMenu>();

/// <summary>
/// Defines the <see cref="Placement"/> property.
/// </summary>
public static readonly StyledProperty<PlacementMode> PlacementProperty =
Popup.PlacementProperty.AddOwner<ContextMenu>();

/// <summary>
/// Defines the <see cref="PlacementMode"/> property.
/// </summary>
public static readonly StyledProperty<PlacementMode> PlacementModeProperty =
Popup.PlacementModeProperty.AddOwner<ContextMenu>();
[Obsolete("Use the Placement property instead.")]
public static readonly StyledProperty<PlacementMode> PlacementModeProperty = PlacementProperty;

/// <summary>
/// Defines the <see cref="PlacementRect"/> property.
Expand Down Expand Up @@ -108,99 +114,80 @@ public ContextMenu(IMenuInteractionHandler interactionHandler)
static ContextMenu()
{
ItemsPanelProperty.OverrideDefaultValue<ContextMenu>(DefaultPanel);
PlacementModeProperty.OverrideDefaultValue<ContextMenu>(PlacementMode.Pointer);
PlacementProperty.OverrideDefaultValue<ContextMenu>(PlacementMode.Pointer);
ContextMenuProperty.Changed.Subscribe(ContextMenuChanged);
AutomationProperties.AccessibilityViewProperty.OverrideDefaultValue<ContextMenu>(AccessibilityView.Control);
AutomationProperties.ControlTypeOverrideProperty.OverrideDefaultValue<ContextMenu>(AutomationControlType.Menu);
}

/// <summary>
/// Gets or sets the Horizontal offset of the context menu in relation to the <see cref="PlacementTarget"/>.
/// </summary>
/// <inheritdoc cref="Popup.HorizontalOffset"/>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm inheriting the docs from Popup now. The only downside is "context menu" wording is replaced by "popup". I don't consider this a major issue and it's better to find more general wording in the base docs than duplicate them everywhere.

public double HorizontalOffset
{
get { return GetValue(HorizontalOffsetProperty); }
set { SetValue(HorizontalOffsetProperty, value); }
get => GetValue(HorizontalOffsetProperty);
set => SetValue(HorizontalOffsetProperty, value);
}

/// <summary>
/// Gets or sets the Vertical offset of the context menu in relation to the <see cref="PlacementTarget"/>.
/// </summary>
/// <inheritdoc cref="Popup.VerticalOffset"/>
public double VerticalOffset
{
get { return GetValue(VerticalOffsetProperty); }
set { SetValue(VerticalOffsetProperty, value); }
get => GetValue(VerticalOffsetProperty);
set => SetValue(VerticalOffsetProperty, value);
}

/// <summary>
/// Gets or sets the anchor point on the <see cref="PlacementRect"/> when <see cref="PlacementMode"/>
/// is <see cref="PlacementMode.AnchorAndGravity"/>.
/// </summary>
/// <inheritdoc cref="Popup.PlacementAnchor"/>
public PopupAnchor PlacementAnchor
{
get { return GetValue(PlacementAnchorProperty); }
set { SetValue(PlacementAnchorProperty, value); }
get => GetValue(PlacementAnchorProperty);
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>
/// <inheritdoc cref="Popup.PlacementConstraintAdjustment"/>
public PopupPositionerConstraintAdjustment PlacementConstraintAdjustment
{
get { return GetValue(PlacementConstraintAdjustmentProperty); }
set { SetValue(PlacementConstraintAdjustmentProperty, value); }
get => 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"/>.
/// </summary>
/// <inheritdoc cref="Popup.PlacementGravity"/>
public PopupGravity PlacementGravity
{
get { return GetValue(PlacementGravityProperty); }
set { SetValue(PlacementGravityProperty, value); }
get => GetValue(PlacementGravityProperty);
set => SetValue(PlacementGravityProperty, value);
}

/// <summary>
/// Gets or sets the placement mode of the context menu in relation to the<see cref="PlacementTarget"/>.
/// </summary>
/// <inheritdoc cref="Placement"/>
[Obsolete("Use the Placement property instead.")]
public PlacementMode PlacementMode
{
get { return GetValue(PlacementModeProperty); }
set { SetValue(PlacementModeProperty, value); }
get => GetValue(PlacementProperty);
set => SetValue(PlacementProperty, value);
}

/// <inheritdoc cref="Popup.Placement"/>
public PlacementMode Placement
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the Popup "Placement" properties shouldn't really be duplicated here. There is an open question if ContextMenu should be deriving from PopupFlyoutBase as well (like MenuFlyout).

{
get => GetValue(PlacementProperty);
set => SetValue(PlacementProperty, value);
}

public bool WindowManagerAddShadowHint
{
get { return GetValue(WindowManagerAddShadowHintProperty); }
set { SetValue(WindowManagerAddShadowHintProperty, value); }
get => GetValue(WindowManagerAddShadowHintProperty);
set => SetValue(WindowManagerAddShadowHintProperty, value);
}

/// <summary>
/// Gets or sets the the anchor rectangle within the parent that the context menu will be placed
/// relative to when <see cref="PlacementMode"/> is <see cref="PlacementMode.AnchorAndGravity"/>.
/// </summary>
/// <remarks>
/// The placement rect defines a rectangle relative to <see cref="PlacementTarget"/> around
/// which the popup will be opened, with <see cref="PlacementAnchor"/> determining which edge
/// of the placement target is used.
///
/// If unset, the anchor rectangle will be the bounds of the <see cref="PlacementTarget"/>.
/// </remarks>
/// <inheritdoc cref="Popup.PlacementRect"/>
public Rect? PlacementRect
{
get { return GetValue(PlacementRectProperty); }
set { SetValue(PlacementRectProperty, value); }
get => GetValue(PlacementRectProperty);
set => SetValue(PlacementRectProperty, value);
}

/// <summary>
/// Gets or sets the control that is used to determine the popup's position.
/// </summary>
/// <inheritdoc cref="Popup.PlacementTarget"/>
public Control? PlacementTarget
{
get { return GetValue(PlacementTargetProperty); }
set { SetValue(PlacementTargetProperty, value); }
get => GetValue(PlacementTargetProperty);
set => SetValue(PlacementTargetProperty, value);
}

/// <summary>
Expand Down Expand Up @@ -343,9 +330,9 @@ private void Open(Control control, Control placementTarget, bool requestedByPoin
((ISetLogicalParent)_popup).SetParent(control);
}

_popup.PlacementMode = !requestedByPointer && PlacementMode == PlacementMode.Pointer
_popup.Placement = !requestedByPointer && Placement == PlacementMode.Pointer
? PlacementMode.Bottom
: PlacementMode;
: Placement;

//Position of the line below is really important.
//All styles are being applied only when control has logical parent.
Expand Down
2 changes: 1 addition & 1 deletion src/Avalonia.Controls/DateTimePickers/DatePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ private void OnFlyoutButtonClicked(object? sender, RoutedEventArgs e)

_presenter.Date = SelectedDate ?? DateTimeOffset.Now;

_popup.PlacementMode = PlacementMode.AnchorAndGravity;
_popup.Placement = PlacementMode.AnchorAndGravity;
_popup.PlacementAnchor = Primitives.PopupPositioning.PopupAnchor.Bottom;
_popup.PlacementGravity = Primitives.PopupPositioning.PopupGravity.Bottom;
_popup.PlacementConstraintAdjustment = Primitives.PopupPositioning.PopupPositionerConstraintAdjustment.SlideY;
Expand Down
2 changes: 1 addition & 1 deletion src/Avalonia.Controls/DateTimePickers/TimePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ private void OnFlyoutButtonClicked(object? sender, Interactivity.RoutedEventArgs

_presenter.Time = SelectedTime ?? DateTime.Now.TimeOfDay;

_popup.PlacementMode = PlacementMode.AnchorAndGravity;
_popup.Placement = PlacementMode.AnchorAndGravity;
_popup.PlacementAnchor = Primitives.PopupPositioning.PopupAnchor.Bottom;
_popup.PlacementGravity = Primitives.PopupPositioning.PopupGravity.Bottom;
_popup.PlacementConstraintAdjustment = Primitives.PopupPositioning.PopupPositionerConstraintAdjustment.SlideY;
Expand Down
14 changes: 6 additions & 8 deletions src/Avalonia.Controls/Flyouts/PopupFlyoutBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ namespace Avalonia.Controls.Primitives
{
public abstract class PopupFlyoutBase : FlyoutBase, IPopupHostProvider
{
/// <inheritdoc cref="Popup.PlacementModeProperty"/>
/// <inheritdoc cref="Popup.PlacementProperty"/>
public static readonly StyledProperty<PlacementMode> PlacementProperty =
Popup.PlacementModeProperty.AddOwner<PopupFlyoutBase>();
Popup.PlacementProperty.AddOwner<PopupFlyoutBase>();

/// <inheritdoc cref="Popup.HorizontalOffsetProperty"/>
public static readonly StyledProperty<double> HorizontalOffsetProperty =
Expand Down Expand Up @@ -64,15 +64,13 @@ public PopupFlyoutBase()

protected Popup Popup => _popupLazy.Value;

/// <summary>
/// Gets or sets the desired placement.
/// </summary>
/// <inheritdoc cref="Popup.Placement"/>
public PlacementMode Placement
{
get => GetValue(PlacementProperty);
set => SetValue(PlacementProperty, value);
}

/// <inheritdoc cref="Popup.PlacementGravity"/>
public PopupGravity PlacementGravity
{
Expand Down Expand Up @@ -423,11 +421,11 @@ private void PositionPopup(bool showAtPointer)
Popup.PlacementGravity = PlacementGravity;
if (showAtPointer)
{
Popup.PlacementMode = PlacementMode.Pointer;
Popup.Placement = PlacementMode.Pointer;
}
else
{
Popup.PlacementMode = Placement;
Popup.Placement = Placement;
Popup.PlacementConstraintAdjustment =
PopupPositioning.PopupPositionerConstraintAdjustment.SlideX |
PopupPositioning.PopupPositionerConstraintAdjustment.SlideY;
Expand Down
Loading