Skip to content

Commit

Permalink
feat: Adhere to HorizontalOffset and VerticalOffset
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Dec 14, 2022
1 parent 02b730f commit 3f687ab
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 22 deletions.
2 changes: 0 additions & 2 deletions src/Uno.UI/Mixins/DependencyPropertyMixins.tt
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@
.Property("Child", "UIElement", "null", frameworkPropertyOption: "ValueInheritsDataContext")
.Property("IsLightDismissEnabled", "bool", "false")
//.Property("ChildTransitions", "TransitionCollection", "null")
.Property("HorizontalOffset", "double", "0")
.Property("VerticalOffset", "double", "0")

.Namespace("Uno.UI.Controls.Legacy")
.Class("ListViewBase", condition: "XAMARIN_IOS")
Expand Down
2 changes: 2 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/Flyout/FlyoutPopupPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public FlyoutBasePopupPanel(FlyoutBase flyout) : base(flyout._popup)
protected override bool FullPlacementRequested => _flyout.EffectivePlacement == FlyoutPlacementMode.Full;

internal override FlyoutBase Flyout => _flyout;

protected override int PopupPlacementTargetMargin => 5;
}
}
#endif
4 changes: 2 additions & 2 deletions src/Uno.UI/UI/Xaml/Controls/Popup/Popup.Legacy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private void OnBasePropertyChanged(DependencyObject sender, DependencyProperty d
get => GetHorizontalOffsetValue();
set => SetHorizontalOffsetValue(value);
}
private new void OnHorizontalOffsetChanged(double oldValue, double newValue)
private void OnHorizontalOffsetChanged(double oldValue, double newValue)
=> base.HorizontalOffset = newValue;

[GeneratedDependencyProperty(DefaultValue = 0.0, LocalCache = false, ChangedCallback = true)]
Expand All @@ -104,7 +104,7 @@ private void OnBasePropertyChanged(DependencyObject sender, DependencyProperty d
set => SetVerticalOffsetValue(value);
}

private new void OnVerticalOffsetChanged(double oldValue, double newValue)
private void OnVerticalOffsetChanged(double oldValue, double newValue)
=> base.VerticalOffset = newValue;

[GeneratedDependencyProperty(DefaultValue = 0.0, LocalCache = false, ChangedCallback = true)]
Expand Down
50 changes: 41 additions & 9 deletions src/Uno.UI/UI/Xaml/Controls/Popup/Popup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,6 @@ private void OnPopupPanelChanged(PopupPanel oldHost, PopupPanel newHost)

partial void OnPopupPanelChangedPartial(PopupPanel previousPanel, PopupPanel newPanel);

partial void OnVerticalOffsetChangedPartial(double oldVerticalOffset, double newVerticalOffset)
=> PopupPanel?.InvalidateMeasure();

partial void OnHorizontalOffsetChangedPartial(double oldHorizontalOffset, double newHorizontalOffset)
=> PopupPanel?.InvalidateMeasure();

internal override void UpdateThemeBindings(Data.ResourceUpdateReason updateReason)
{
base.UpdateThemeBindings(updateReason);
Expand Down Expand Up @@ -156,7 +150,7 @@ public FrameworkElement PlacementTarget
nameof(PlacementTarget),
typeof(FrameworkElement),
typeof(Popup),
new FrameworkPropertyMetadata(default(FrameworkElement)));
new FrameworkPropertyMetadata(default(FrameworkElement), FrameworkPropertyMetadataOptions.AffectsArrange));

/// <summary>
/// Gets or sets the preferred placement to be used for the popup, in relation to its placement target.
Expand All @@ -175,7 +169,7 @@ public PopupPlacementMode DesiredPlacement
nameof(DesiredPlacement),
typeof(PopupPlacementMode),
typeof(Popup),
new FrameworkPropertyMetadata(default(PopupPlacementMode)));
new FrameworkPropertyMetadata(default(PopupPlacementMode), FrameworkPropertyMetadataOptions.AffectsArrange));

/// <summary>
/// Gets the actual placement of the popup, in relation to its placement target.
Expand All @@ -194,11 +188,49 @@ public PopupPlacementMode ActualPlacement
}
}

/// <summary>
/// Gets or sets the distance between the left side of the application window and the left side of the popup.
/// </summary>
public double HorizontalOffset
{
get => (double)GetValue(HorizontalOffsetProperty);
set => SetValue(HorizontalOffsetProperty, value);
}

/// <summary>
/// Gets the identifier for the HorizontalOffset dependency property.
/// </summary>
public static DependencyProperty HorizontalOffsetProperty { get; } =
DependencyProperty.Register(
nameof(HorizontalOffset),
typeof(double),
typeof(Popup),
new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsMeasure));

/// <summary>
/// Gets or sets the distance between the top of the application window and the top of the popup.
/// </summary>
public double VerticalOffset
{
get => (double)GetValue(VerticalOffsetProperty);
set => SetValue(VerticalOffsetProperty, value);
}

/// <summary>
/// Gets the identifier for the VerticalOffset dependency property.
/// </summary>
public static DependencyProperty VerticalOffsetProperty { get; } =
DependencyProperty.Register(
nameof(VerticalOffset),
typeof(double),
typeof(Popup),
new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsMeasure));

/// <summary>
/// Raised when the ActualPlacement property changes.
/// </summary>
public event EventHandler<object> ActualPlacementChanged;

private void ApplyLightDismissOverlayMode()
{
if (PopupPanel != null)
Expand Down
19 changes: 10 additions & 9 deletions src/Uno.UI/UI/Xaml/Controls/Popup/PopupPanel.Placement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ partial class PopupPanel
/// <summary>
/// This value is an arbitrary value for the placement of
/// a popup below its anchor.
/// TODO: To be removed in favor of HorizontalOffset and VerticalOffset.
/// </summary>
protected virtual int PopupPlacementTargetMargin => 5;
protected virtual int PopupPlacementTargetMargin => 0;

private void Window_SizeChanged(object sender, WindowSizeChangedEventArgs e)
=> InvalidateMeasure();
Expand Down Expand Up @@ -149,23 +150,23 @@ protected virtual Rect CalculatePopupPlacement(Popup popup, Size desiredSize, Si
{
case FlyoutBase.MajorPlacementMode.Top:
finalPosition = new Point(
x: anchorRect.Left + halfAnchorWidth - halfChildWidth,
y: anchorRect.Top - PopupPlacementTargetMargin - desiredSize.Height);
x: anchorRect.Left + halfAnchorWidth - halfChildWidth + popup.HorizontalOffset,
y: anchorRect.Top - PopupPlacementTargetMargin - desiredSize.Height + popup.VerticalOffset);
break;
case FlyoutBase.MajorPlacementMode.Bottom:
finalPosition = new Point(
x: anchorRect.Left + halfAnchorWidth - halfChildWidth,
y: anchorRect.Bottom + PopupPlacementTargetMargin);
x: anchorRect.Left + halfAnchorWidth - halfChildWidth + popup.HorizontalOffset,
y: anchorRect.Bottom + PopupPlacementTargetMargin + popup.VerticalOffset);
break;
case FlyoutBase.MajorPlacementMode.Left:
finalPosition = new Point(
x: anchorRect.Left - PopupPlacementTargetMargin - desiredSize.Width,
y: anchorRect.Top + halfAnchorHeight - halfChildHeight);
x: anchorRect.Left - PopupPlacementTargetMargin - desiredSize.Width + popup.HorizontalOffset,
y: anchorRect.Top + halfAnchorHeight - halfChildHeight + popup.VerticalOffset);
break;
case FlyoutBase.MajorPlacementMode.Right:
finalPosition = new Point(
x: anchorRect.Right + PopupPlacementTargetMargin,
y: anchorRect.Top + halfAnchorHeight - halfChildHeight);
x: anchorRect.Right + PopupPlacementTargetMargin + popup.HorizontalOffset,
y: anchorRect.Top + halfAnchorHeight - halfChildHeight + popup.VerticalOffset);
break;
case FlyoutBase.MajorPlacementMode.Full:
#if __IOS__ || __ANDROID__
Expand Down
2 changes: 2 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/ToolTip/ToolTipPopupPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ internal ToolTipPopupPanel(ToolTip toolTip) : base(toolTip.Popup)
{
Background = null; // No light dismiss for tooltip, dismiss is managed by the cursor location
}

protected override int PopupPlacementTargetMargin => 5;
}
}

0 comments on commit 3f687ab

Please sign in to comment.