Refactor ScrollViewer property

This commit is contained in:
chinboy
2025-12-30 22:46:17 +08:00
parent 346f9b6e65
commit be6477fb14
7 changed files with 60 additions and 26 deletions
@@ -43,12 +43,14 @@
HorizontalAlignment="Stretch"
DockPanel.Dock="Bottom"/>
<atom:IndicatorScrollViewer>
<atom:ScrollViewer IsMotionEnabled="{TemplateBinding IsMotionEnabled}"
IsLiteMode="True"
AllowAutoHide="True">
<ItemsPresenter Name="{x:Static atom:MenuFlyoutThemeConstants.ItemsPresenterPart}"
ItemsPanel="{TemplateBinding ItemsPanel}"
KeyboardNavigation.TabNavigation="Continue"
Grid.IsSharedSizeScope="True" />
</atom:IndicatorScrollViewer>
</atom:ScrollViewer>
</DockPanel>
</atom:ArrowDecoratedBox>
</ControlTemplate>
@@ -60,16 +60,17 @@
<Border
Name="PopupFrame"
MaxHeight="{TemplateBinding MaxDropDownHeight}"
HorizontalAlignment="Stretch"
MinWidth="{TemplateBinding EffectivePopupWidth}"
Padding="{TemplateBinding PopupContentPadding}">
<atom:IndicatorScrollViewer
IsMotionEnabled="{TemplateBinding IsMotionEnabled}">
<atom:ScrollViewer
IsMotionEnabled="{TemplateBinding IsMotionEnabled}"
IsLiteMode="True"
AllowAutoHide="True">
<ItemsPresenter
Name="{x:Static atom:ComboBoxThemeConstants.ItemsPresenterPart}"
ItemsPanel="{TemplateBinding ItemsPanel}"
Grid.IsSharedSizeScope="True" />
</atom:IndicatorScrollViewer>
</atom:ScrollViewer>
</Border>
</atom:Popup>
</Panel>
@@ -11,14 +11,16 @@
ArrowPosition="{TemplateBinding ArrowPosition}"
Padding="{TemplateBinding Padding}"
MaxHeight="{TemplateBinding MaxPopupHeight}">
<atom:IndicatorScrollViewer HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
IsMotionEnabled="{TemplateBinding IsMotionEnabled}">
<atom:ScrollViewer HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
IsLiteMode="True"
AllowAutoHide="True"
IsMotionEnabled="{TemplateBinding IsMotionEnabled}">
<ItemsPresenter Name="{x:Static atom:MenuFlyoutThemeConstants.ItemsPresenterPart}"
ItemsPanel="{TemplateBinding ItemsPanel}"
KeyboardNavigation.TabNavigation="Continue"
Grid.IsSharedSizeScope="True" />
</atom:IndicatorScrollViewer>
</atom:ScrollViewer>
</atom:ArrowDecoratedBox>
</ControlTemplate>
</Setter>
@@ -29,7 +31,7 @@
<Setter Property="IsMotionEnabled" Value="{DynamicResource {x:Static atom:SharedTokenKey.EnableMotion}}" />
<Setter Property="Padding" Value="{DynamicResource {x:Static atom:MenuTokenKey.MenuPopupContentPadding}}" />
<Setter Property="ItemHeight" Value="{DynamicResource {x:Static atom:MenuTokenKey.ItemHeight}}" />
<Style Selector="^ /template/ atom|ArrowDecoratedBox#PART_ArrowDecorator">
<Setter Property="Background" Value="{DynamicResource {x:Static atom:SharedTokenKey.ColorBgElevated}}" />
<Setter Property="MinWidth" Value="{DynamicResource {x:Static atom:MenuTokenKey.MenuPopupMinWidth}}" />
@@ -11,17 +11,19 @@
CornerRadius="{TemplateBinding CornerRadius}"
Padding="{TemplateBinding Padding}"
MaxHeight="{TemplateBinding MaxPopupHeight}">
<atom:IndicatorScrollViewer IsScrollChainingEnabled="False"
IsMotionEnabled="{TemplateBinding IsMotionEnabled}">
<atom:ScrollViewer IsScrollChainingEnabled="False"
IsMotionEnabled="{TemplateBinding IsMotionEnabled}"
IsLiteMode="True"
AllowAutoHide="True">
<ItemsPresenter Name="{x:Static atom:ContextMenuThemeConstants.ItemsPresenterPart}"
ItemsPanel="{TemplateBinding ItemsPanel}"
KeyboardNavigation.TabNavigation="Continue"
Grid.IsSharedSizeScope="True" />
</atom:IndicatorScrollViewer>
</atom:ScrollViewer>
</Border>
</ControlTemplate>
</Setter>
<Setter Property="CornerRadius" Value="{DynamicResource {x:Static atom:MenuTokenKey.MenuPopupBorderRadius}}" />
<Setter Property="IsMotionEnabled" Value="{DynamicResource {x:Static atom:SharedTokenKey.EnableMotion}}" />
<Setter Property="Padding" Value="{DynamicResource {x:Static atom:MenuTokenKey.MenuPopupContentPadding}}" />
@@ -4,7 +4,7 @@
xmlns:atom="https://atomui.net"
xmlns:converters="using:AtomUI.Desktop.Controls.Converters"
x:ClassModifier="internal">
<converters:NavMenuIsSubMenuOpenConverter x:Key="IsSubMenuOpenConverter"/>
<converters:NavMenuIsSubMenuOpenConverter x:Key="IsSubMenuOpenConverter" />
<ControlTheme x:Key="{x:Static atom:NavMenuThemeConstants.HorizontalNavMenuItemThemeId}"
TargetType="atom:NavMenuItem">
<Setter Property="Template">
@@ -35,19 +35,21 @@
</atom:Popup.IsMotionAwareOpen>
<Border Name="{x:Static atom:NavMenuItemThemeConstants.PopupFramePart}"
MinWidth="{TemplateBinding EffectivePopupMinWidth}">
<atom:IndicatorScrollViewer IsMotionEnabled="{TemplateBinding IsMotionEnabled}">
<atom:ScrollViewer IsMotionEnabled="{TemplateBinding IsMotionEnabled}"
IsLiteMode="True"
AllowAutoHide="True">
<ItemsPresenter
Name="{x:Static atom:NavMenuItemThemeConstants.ItemsPresenterPart}"
ItemsPanel="{TemplateBinding ItemsPanel}"
Grid.IsSharedSizeScope="True"
KeyboardNavigation.TabNavigation="Continue" />
</atom:IndicatorScrollViewer>
</atom:ScrollViewer>
</Border>
</atom:Popup>
</Panel>
</ControlTemplate>
</Setter>
<Setter Property="PopupMinWidth" Value="{DynamicResource {x:Static atom:NavMenuTokenKey.MenuPopupMinWidth}}" />
<Style Selector="^ /template/ atom|Popup#PART_Popup">
<Setter Property="Placement" Value="RightEdgeAlignedTop" />
@@ -56,7 +58,7 @@
<Setter Property="MaskShadows"
Value="{DynamicResource {x:Static atom:NavMenuTokenKey.MenuPopupBoxShadows}}" />
</Style>
<Style Selector="^ /template/ Border#PART_PopupFrame">
<Setter Property="Background"
Value="{DynamicResource {x:Static atom:SharedTokenKey.ColorBgElevated}}" />
@@ -65,7 +67,7 @@
<Setter Property="Padding"
Value="{DynamicResource {x:Static atom:NavMenuTokenKey.MenuPopupContentPadding}}" />
</Style>
<Style Selector="^[IsDarkStyle=True]">
<Style Selector="^ /template/ Border#PART_PopupFrame">
<Setter Property="Background"
@@ -1,4 +1,5 @@
using AtomUI.Controls;
using AtomUI.Desktop.Controls.Utils;
using AtomUI.Theme;
using AtomUI.Utils;
using Avalonia;
@@ -191,9 +192,14 @@ public class ScrollViewer : AvaloniaScrollViewer,
{
if (e is RawPointerEventArgs mouseEventArgs)
{
if (mouseEventArgs.GetInputRoot() != TopLevel.GetTopLevel(this))
{
return;
}
if (mouseEventArgs.Type == RawPointerEventType.Move)
{
if (IsMousePointValid(mouseEventArgs.Position))
if (IsMousePointIn(mouseEventArgs))
{
if (!_isPointerInside)
{
@@ -216,11 +222,13 @@ public class ScrollViewer : AvaloniaScrollViewer,
}
}
private bool IsMousePointValid(Point point)
private bool IsMousePointIn(RawPointerEventArgs args)
{
var localPoint = TopLevel.GetTopLevel(this)?.TranslatePoint(point, this) ?? default;
var constraintBounds = new Rect(Bounds.Size);
if (constraintBounds.Contains(localPoint))
var pointRoot = args.Root as Control;
var localPoint = pointRoot?.PointToScreen(args.Position) ?? default;
var offset = this.PointToScreen(new Point(0, 0));
var constraintBounds = new Rect(new Point(offset.X, offset.Y), Bounds.Size);
if (constraintBounds.Contains(new Point(localPoint.X, localPoint.Y)))
{
return true;
}
@@ -0,0 +1,17 @@
using Avalonia.Controls;
using Avalonia.Input.Raw;
namespace AtomUI.Desktop.Controls.Utils;
internal static class RawPointerEventArgsExtensions
{
public static Control? GetInputRoot(this RawPointerEventArgs eventArgs)
{
var inputRoot = eventArgs.Root;
if (inputRoot is PopupBuddyLayer popupBuddyLayer)
{
return popupBuddyLayer.BuddyPopup.Host as Control;
}
return inputRoot as Control;
}
}