improve:UI面板弹出
This commit is contained in:
@@ -554,37 +554,22 @@ namespace Ink_Canvas
|
||||
BoardHighlightPenTabButton.Background = new SolidColorBrush(Colors.Transparent);
|
||||
BoardHighlightPenTabButtonIndicator.Visibility = Visibility.Collapsed;
|
||||
|
||||
// PenPalette.Margin = new Thickness(-160, -200, -33, 32);
|
||||
// 动态计算面板位置,使其对齐笔按钮(考虑快捷调色盘等动态宽度)
|
||||
await Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
var marginAnimation = new ThicknessAnimation
|
||||
{
|
||||
Duration = TimeSpan.FromSeconds(0.1),
|
||||
From = PenPalette.Margin,
|
||||
To = new Thickness(-160, -200, -33, 32),
|
||||
EasingFunction = new CubicEase()
|
||||
};
|
||||
PenPalette.BeginAnimation(MarginProperty, marginAnimation);
|
||||
PenPalette.BeginAnimation(MarginProperty, null);
|
||||
var currentMargin = PenPalette.Margin;
|
||||
// 先设置正确的Top/Bottom,保持当前Left/Right
|
||||
PenPalette.Margin = new Thickness(currentMargin.Left, -200, currentMargin.Right, 32);
|
||||
UpdatePenPalettePosition();
|
||||
});
|
||||
|
||||
await Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
var marginAnimation = new ThicknessAnimation
|
||||
{
|
||||
Duration = TimeSpan.FromSeconds(0.1),
|
||||
From = PenPalette.Margin,
|
||||
To = new Thickness(-160, -200, -33, 50),
|
||||
EasingFunction = new CubicEase()
|
||||
};
|
||||
BoardPenPaletteGrid.BeginAnimation(MarginProperty, marginAnimation);
|
||||
BoardPenPaletteGrid.BeginAnimation(MarginProperty, null);
|
||||
var currentMargin = BoardPenPaletteGrid.Margin;
|
||||
BoardPenPaletteGrid.Margin = new Thickness(currentMargin.Left, -200, currentMargin.Right, 50);
|
||||
});
|
||||
|
||||
|
||||
await Task.Delay(100);
|
||||
|
||||
await Dispatcher.InvokeAsync(() => { PenPalette.Margin = new Thickness(-160, -200, -33, 32); });
|
||||
|
||||
await Dispatcher.InvokeAsync(() => { BoardPenPaletteGrid.Margin = new Thickness(-160, -200, -33, 50); });
|
||||
}
|
||||
else if (penType == 1)
|
||||
{
|
||||
@@ -622,36 +607,22 @@ namespace Ink_Canvas
|
||||
BoardHighlightPenTabButton.Background = new SolidColorBrush(Color.FromArgb(72, 219, 234, 254));
|
||||
BoardHighlightPenTabButtonIndicator.Visibility = Visibility.Visible;
|
||||
|
||||
// PenPalette.Margin = new Thickness(-160, -157, -33, 32);
|
||||
// 动态计算面板位置,使其对齐笔按钮(考虑快捷调色盘等动态宽度)
|
||||
await Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
var marginAnimation = new ThicknessAnimation
|
||||
{
|
||||
Duration = TimeSpan.FromSeconds(0.1),
|
||||
From = PenPalette.Margin,
|
||||
To = new Thickness(-160, -157, -33, 32),
|
||||
EasingFunction = new CubicEase()
|
||||
};
|
||||
PenPalette.BeginAnimation(MarginProperty, marginAnimation);
|
||||
PenPalette.BeginAnimation(MarginProperty, null);
|
||||
var currentMargin = PenPalette.Margin;
|
||||
// 荧光笔模式面板稍小,使用不同的Top/Bottom
|
||||
PenPalette.Margin = new Thickness(currentMargin.Left, -157, currentMargin.Right, 32);
|
||||
UpdatePenPalettePosition();
|
||||
});
|
||||
|
||||
await Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
var marginAnimation = new ThicknessAnimation
|
||||
{
|
||||
Duration = TimeSpan.FromSeconds(0.1),
|
||||
From = PenPalette.Margin,
|
||||
To = new Thickness(-160, -154, -33, 50),
|
||||
EasingFunction = new CubicEase()
|
||||
};
|
||||
BoardPenPaletteGrid.BeginAnimation(MarginProperty, marginAnimation);
|
||||
BoardPenPaletteGrid.BeginAnimation(MarginProperty, null);
|
||||
var currentMargin = BoardPenPaletteGrid.Margin;
|
||||
BoardPenPaletteGrid.Margin = new Thickness(currentMargin.Left, -154, currentMargin.Right, 50);
|
||||
});
|
||||
|
||||
await Task.Delay(100);
|
||||
|
||||
await Dispatcher.InvokeAsync(() => { PenPalette.Margin = new Thickness(-160, -157, -33, 32); });
|
||||
|
||||
await Dispatcher.InvokeAsync(() => { BoardPenPaletteGrid.Margin = new Thickness(-160, -154, -33, 50); });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ namespace Ink_Canvas
|
||||
else
|
||||
{
|
||||
HideSubPanels();
|
||||
UpdateTwoFingerGestureBorderPosition();
|
||||
AnimationsHelper.ShowWithSlideFromBottomAndFade(TwoFingerGestureBorder);
|
||||
AnimationsHelper.ShowWithSlideFromBottomAndFade(BoardTwoFingerGestureBorder);
|
||||
}
|
||||
@@ -1742,6 +1743,7 @@ namespace Ink_Canvas
|
||||
else
|
||||
{
|
||||
HideSubPanels();
|
||||
UpdateBorderToolsPosition();
|
||||
AnimationsHelper.ShowWithSlideFromBottomAndFade(BorderTools);
|
||||
AnimationsHelper.ShowWithSlideFromBottomAndFade(BoardBorderTools);
|
||||
}
|
||||
@@ -2439,6 +2441,7 @@ namespace Ink_Canvas
|
||||
else
|
||||
{
|
||||
HideSubPanels();
|
||||
UpdatePenPalettePosition();
|
||||
AnimationsHelper.ShowWithSlideFromBottomAndFade(PenPalette);
|
||||
AnimationsHelper.ShowWithSlideFromBottomAndFade(BoardPenPalette);
|
||||
}
|
||||
@@ -2548,6 +2551,7 @@ namespace Ink_Canvas
|
||||
// 已是橡皮状态,再次点击才弹出/收起面板
|
||||
if (EraserSizePanel.Visibility == Visibility.Collapsed)
|
||||
{
|
||||
UpdateEraserSizePanelPosition();
|
||||
AnimationsHelper.ShowWithSlideFromBottomAndFade(EraserSizePanel);
|
||||
if (BoardEraserSizePanel != null)
|
||||
AnimationsHelper.ShowWithSlideFromBottomAndFade(BoardEraserSizePanel);
|
||||
@@ -2598,6 +2602,7 @@ namespace Ink_Canvas
|
||||
// 已是橡皮状态,再次点击才弹出/收起面板
|
||||
if (BoardEraserSizePanel != null && BoardEraserSizePanel.Visibility == Visibility.Collapsed)
|
||||
{
|
||||
UpdateEraserSizePanelPosition();
|
||||
AnimationsHelper.ShowWithSlideFromBottomAndFade(BoardEraserSizePanel);
|
||||
AnimationsHelper.ShowWithSlideFromBottomAndFade(EraserSizePanel);
|
||||
}
|
||||
@@ -4209,6 +4214,101 @@ namespace Ink_Canvas
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通用子面板位置更新方法:根据触发按钮的位置,动态调整子面板的水平位置,
|
||||
/// 使面板水平中心对齐按钮中心。不改变面板大小,不改变上下边距。
|
||||
/// </summary>
|
||||
/// <param name="button">触发按钮元素</param>
|
||||
/// <param name="panel">需要定位的子面板</param>
|
||||
/// <param name="defaultPanelWidth">面板默认宽度(当无法从Margin计算时使用)</param>
|
||||
private void UpdateSubPanelPosition(FrameworkElement button, FrameworkElement panel, double defaultPanelWidth)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (button == null || panel == null) return;
|
||||
if (!(panel.Parent is FrameworkElement panelContainer)) return;
|
||||
|
||||
var ancestor = StackPanelFloatingBar;
|
||||
if (ancestor == null) return;
|
||||
|
||||
// 获取按钮中心的X坐标(相对于 StackPanelFloatingBar 坐标系)
|
||||
var buttonTransform = button.TransformToAncestor(ancestor);
|
||||
var buttonOrigin = buttonTransform.Transform(new Point(0, 0));
|
||||
double buttonCenterX = buttonOrigin.X + button.ActualWidth / 2.0;
|
||||
|
||||
// 获取面板容器(零宽度Grid)的X坐标(相对于 StackPanelFloatingBar 坐标系)
|
||||
var containerTransform = panelContainer.TransformToAncestor(ancestor);
|
||||
var containerOrigin = containerTransform.Transform(new Point(0, 0));
|
||||
double containerX = containerOrigin.X;
|
||||
|
||||
// 计算当前面板宽度(保持不变):panelWidth = -Margin.Left - Margin.Right
|
||||
double currentLeft = panel.Margin.Left;
|
||||
double currentRight = panel.Margin.Right;
|
||||
double panelWidth = -currentLeft - currentRight;
|
||||
if (panelWidth <= 0) panelWidth = defaultPanelWidth;
|
||||
|
||||
// 计算新的左边距,使面板水平中心对齐按钮:
|
||||
// panel_center = containerX + newLeft + panelWidth/2 = buttonCenterX
|
||||
// => newLeft = buttonCenterX - containerX - panelWidth/2
|
||||
double newLeft = buttonCenterX - containerX - panelWidth / 2.0;
|
||||
|
||||
// 保持面板宽度不变:-newLeft - newRight = panelWidth
|
||||
// => newRight = -panelWidth - newLeft
|
||||
double newRight = -panelWidth - newLeft;
|
||||
|
||||
// 清除可能残留的 Margin 动画(HoldEnd 会阻止本地值生效)
|
||||
panel.BeginAnimation(FrameworkElement.MarginProperty, null);
|
||||
|
||||
// 更新边距,仅调整Left/Right,保持Top/Bottom不变
|
||||
var margin = panel.Margin;
|
||||
panel.Margin = new Thickness(newLeft, margin.Top, newRight, margin.Bottom);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"更新子面板位置失败: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新批注子面板(PenPalette)的弹出位置,使其水平中心对齐笔按钮。
|
||||
/// </summary>
|
||||
private void UpdatePenPalettePosition()
|
||||
{
|
||||
UpdateSubPanelPosition(Pen_Icon, PenPalette, 193);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新工具面板(BorderTools)的弹出位置,使其水平中心对齐工具按钮。
|
||||
/// </summary>
|
||||
private void UpdateBorderToolsPosition()
|
||||
{
|
||||
UpdateSubPanelPosition(ToolsFloatingBarBtn, BorderTools, 119);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新橡皮擦尺寸面板(EraserSizePanel)的弹出位置,使其水平中心对齐橡皮擦按钮。
|
||||
/// </summary>
|
||||
private void UpdateEraserSizePanelPosition()
|
||||
{
|
||||
UpdateSubPanelPosition(Eraser_Icon, EraserSizePanel, 120);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新形状绘制面板(BorderDrawShape)的弹出位置,使其水平中心对齐形状按钮。
|
||||
/// </summary>
|
||||
private void UpdateBorderDrawShapePosition()
|
||||
{
|
||||
UpdateSubPanelPosition(ShapeDrawFloatingBarBtn, BorderDrawShape, 317);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新手势面板(TwoFingerGestureBorder)的弹出位置,使其水平中心对齐手势按钮。
|
||||
/// </summary>
|
||||
private void UpdateTwoFingerGestureBorderPosition()
|
||||
{
|
||||
UpdateSubPanelPosition(EnableTwoFingerGestureBorder, TwoFingerGestureBorder, 119);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 隐藏浮动栏高光显示
|
||||
/// </summary>
|
||||
|
||||
@@ -49,6 +49,7 @@ namespace Ink_Canvas
|
||||
else
|
||||
{
|
||||
HideSubPanels();
|
||||
UpdateBorderDrawShapePosition();
|
||||
AnimationsHelper.ShowWithSlideFromBottomAndFade(BorderDrawShape);
|
||||
AnimationsHelper.ShowWithSlideFromBottomAndFade(BoardBorderDrawShape);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user