mirror of
https://github.com/AtomUI/AtomUI.git
synced 2026-10-26 11:10:34 +08:00
完成 Popup 重构
This commit is contained in:
@@ -1,13 +1,10 @@
|
||||
using System.Reactive.Disposables;
|
||||
using AtomUI.Controls.Utils;
|
||||
using AtomUI.Media;
|
||||
using AtomUI.Media;
|
||||
using AtomUI.Styling;
|
||||
using AtomUI.Utils;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Layout;
|
||||
using Avalonia.LogicalTree;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Metadata;
|
||||
|
||||
@@ -138,8 +135,7 @@ public class ArrowDecoratedBox : TemplatedControl,
|
||||
get => GetValue(ChildProperty);
|
||||
set => SetValue(ChildProperty, value);
|
||||
}
|
||||
|
||||
private bool _initialized = false;
|
||||
|
||||
private IControlCustomStyle _customStyle;
|
||||
private Geometry? _arrowGeometry;
|
||||
private Rect _contentRect;
|
||||
@@ -233,7 +229,7 @@ public class ArrowDecoratedBox : TemplatedControl,
|
||||
_needGenerateArrowVertexPoint = true;
|
||||
}
|
||||
|
||||
if (_initialized && VisualRoot is not null) {
|
||||
if (VisualRoot is not null) {
|
||||
BuildGeometry(true);
|
||||
_arrowRect = GetArrowRect(DesiredSize);
|
||||
}
|
||||
|
||||
@@ -389,12 +389,6 @@ public class Flyout : PopupFlyoutBase
|
||||
motionActor.SceneParent = topLevel;
|
||||
motionActor.Completed += (sender, args) =>
|
||||
{
|
||||
if (flyoutPresenter.Child is not null) {
|
||||
var child = flyoutPresenter.Child;
|
||||
UIStructureUtils.ClearLogicalParentRecursive(child, null);
|
||||
UIStructureUtils.ClearVisualParentRecursive(child, null);
|
||||
}
|
||||
|
||||
base.ShowAtCore(placementTarget, showAtPointer);
|
||||
if (Popup.Host is WindowBase window) {
|
||||
window.PlatformImpl!.SetTopmost(true);
|
||||
|
||||
@@ -155,9 +155,9 @@ public class FlyoutHost : Control
|
||||
PlacementProperty.OverrideDefaultValue<FlyoutHost>(PlacementMode.Top);
|
||||
}
|
||||
|
||||
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
|
||||
public sealed override void ApplyTemplate()
|
||||
{
|
||||
base.OnAttachedToLogicalTree(e);
|
||||
base.ApplyTemplate();
|
||||
if (!_initialized) {
|
||||
if (AnchorTarget is not null) {
|
||||
((ISetLogicalParent)AnchorTarget).SetParent(this);
|
||||
|
||||
@@ -131,22 +131,17 @@ public class LoadingMaskHost : Control, IControlCustomStyle
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
|
||||
public sealed override void ApplyTemplate()
|
||||
{
|
||||
base.OnAttachedToLogicalTree(e);
|
||||
base.ApplyTemplate();
|
||||
if (!_initialized) {
|
||||
_customStyle.HandleAttachedToLogicalTree(e);
|
||||
if (MaskTarget is not null) {
|
||||
((ISetLogicalParent)MaskTarget).SetParent(this);
|
||||
VisualChildren.Add(MaskTarget);
|
||||
}
|
||||
_initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
void IControlCustomStyle.HandleAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
|
||||
{
|
||||
if (MaskTarget is not null) {
|
||||
((ISetLogicalParent)MaskTarget).SetParent(this);
|
||||
VisualChildren.Add(MaskTarget);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
|
||||
@@ -66,10 +66,10 @@ public class Popup : AbstractPopup
|
||||
{
|
||||
IsLightDismissEnabled = false;
|
||||
}
|
||||
|
||||
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
|
||||
|
||||
public sealed override void ApplyTemplate()
|
||||
{
|
||||
base.OnAttachedToLogicalTree(e);
|
||||
base.ApplyTemplate();
|
||||
if (!_initialized) {
|
||||
BindUtils.CreateGlobalTokenBinding(this, MaskShadowsProperty, GlobalResourceKey.BoxShadowsSecondary);
|
||||
_initialized = true;
|
||||
|
||||
@@ -8,7 +8,6 @@ using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Controls.Primitives.PopupPositioning;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Threading;
|
||||
|
||||
namespace AtomUI.Controls;
|
||||
|
||||
|
||||
@@ -87,15 +87,15 @@ internal class MotionGhostControl : Control, INotifyCaptureGhostBitmap
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
|
||||
public sealed override void ApplyTemplate()
|
||||
{
|
||||
base.OnAttachedToLogicalTree(e);
|
||||
base.ApplyTemplate();
|
||||
if (!_initialized) {
|
||||
IsHitTestVisible = false;
|
||||
|
||||
_layout = new Canvas();
|
||||
VisualChildren.Add(_layout);
|
||||
LogicalChildren.Add(_layout);
|
||||
((ISetLogicalParent)_layout).SetParent(this);
|
||||
|
||||
var shadowThickness = Shadows.Thickness();
|
||||
var offsetX = shadowThickness.Left;
|
||||
|
||||
@@ -53,9 +53,9 @@ internal class ShadowRenderer : Control
|
||||
MaskContentBackgroundProperty.OverrideDefaultValue<ShadowRenderer>(new SolidColorBrush(Colors.White));
|
||||
}
|
||||
|
||||
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
|
||||
public sealed override void ApplyTemplate()
|
||||
{
|
||||
base.OnAttachedToLogicalTree(e);
|
||||
base.ApplyTemplate();
|
||||
if (!_initialized) {
|
||||
HorizontalAlignment = HorizontalAlignment.Stretch;
|
||||
VerticalAlignment = VerticalAlignment.Stretch;
|
||||
|
||||
Reference in New Issue
Block a user