Browse Source

Fix: Allow ColorPicker-Fylout to swap position if needed (#13567)

* Add `PlacementConstraintAdjustmentProperty` to PopupFlyoutBase

This adds much more flexibility to control flyout positioning when there is not enough space to show the Flyout.

* Make Fylout position of the ColorPicker a DynamicResource

This allows the position to be overridden easily. It should no longer be hard coded.

* Address review
release/11.0.6
Tim 2 years ago
committed by Max Katz
parent
commit
42a739c2d9
  1. 6
      src/Avalonia.Controls.ColorPicker/Themes/Fluent/ColorPicker.xaml
  2. 7
      src/Avalonia.Controls.ColorPicker/Themes/Simple/ColorPicker.xaml
  3. 17
      src/Avalonia.Controls/Flyouts/PopupFlyoutBase.cs

6
src/Avalonia.Controls.ColorPicker/Themes/Fluent/ColorPicker.xaml

@ -1,9 +1,11 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:Avalonia.Controls"
xmlns:primitives="using:Avalonia.Controls.Primitives"
x:ClassModifier="internal">
<PlacementMode x:Key="ColorPickerFlyoutPlacement">Top</PlacementMode>
<ControlTheme x:Key="{x:Type ColorPicker}"
TargetType="ColorPicker">
<Setter Property="CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
@ -46,7 +48,7 @@
</DropDownButton.Content>
<DropDownButton.Flyout>
<Flyout FlyoutPresenterClasses="nopadding"
Placement="Top">
Placement="{DynamicResource ColorPickerFlyoutPlacement}">
<!-- The following is copy-pasted from the ColorView's control template.
It MUST always be kept in sync with the ColorView (which is master).

7
src/Avalonia.Controls.ColorPicker/Themes/Simple/ColorPicker.xaml

@ -1,8 +1,10 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:Avalonia.Controls"
xmlns:primitives="using:Avalonia.Controls.Primitives"
x:ClassModifier="internal">
<PlacementMode x:Key="ColorPickerFlyoutPlacement">Top</PlacementMode>
<ControlTheme x:Key="{x:Type ColorPicker}"
TargetType="ColorPicker">
@ -45,7 +47,8 @@
</Panel>
</DropDownButton.Content>
<DropDownButton.Flyout>
<Flyout Placement="Top">
<Flyout FlyoutPresenterClasses="nopadding"
Placement="{DynamicResource ColorPickerFlyoutPlacement}">
<!-- The following is copy-pasted from the ColorView's control template.
It MUST always be kept in sync with the ColorView (which is master).

17
src/Avalonia.Controls/Flyouts/PopupFlyoutBase.cs

@ -47,6 +47,12 @@ namespace Avalonia.Controls.Primitives
public static readonly StyledProperty<IInputElement?> OverlayInputPassThroughElementProperty =
Popup.OverlayInputPassThroughElementProperty.AddOwner<PopupFlyoutBase>();
/// <summary>
/// Defines the <see cref="PlacementConstraintAdjustment"/> property
/// </summary>
public static readonly StyledProperty<PopupPositionerConstraintAdjustment> PlacementConstraintAdjustmentProperty =
Popup.PlacementConstraintAdjustmentProperty.AddOwner<PopupFlyoutBase>();
private readonly Lazy<Popup> _popupLazy;
private Rect? _enlargedPopupRect;
private PixelRect? _enlargePopupRectScreenPixelRect;
@ -119,6 +125,13 @@ namespace Avalonia.Controls.Primitives
set => SetValue(OverlayInputPassThroughElementProperty, value);
}
/// <inheritdoc cref="Popup.PlacementConstraintAdjustment"/>
public PopupPositionerConstraintAdjustment PlacementConstraintAdjustment
{
get => GetValue(PlacementConstraintAdjustmentProperty);
set => SetValue(PlacementConstraintAdjustmentProperty, value);
}
IPopupHost? IPopupHostProvider.PopupHost => Popup?.Host;
event Action<IPopupHost?>? IPopupHostProvider.PopupHostChanged
@ -427,9 +440,7 @@ namespace Avalonia.Controls.Primitives
else
{
Popup.Placement = Placement;
Popup.PlacementConstraintAdjustment =
PopupPositioning.PopupPositionerConstraintAdjustment.SlideX |
PopupPositioning.PopupPositionerConstraintAdjustment.SlideY;
Popup.PlacementConstraintAdjustment = PlacementConstraintAdjustment;
}
}

Loading…
Cancel
Save