LunarPresentation/Commands/AutoLocation.cs

(开头部分) 7KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System.Windows;

namespace SHomeWorkshop.LunarPresentation.Commands
{
    public partial class Command
    {
        /// <summary>
        /// 自动卷动编辑器的ScrollViewer,来显示不在可视区的公式。
        /// 此方法应在“公式被选中”后调用。
        /// 注意:“插入并编辑文本块”不应调用此方法——因为此方法未考虑文本块编辑器的位置。
        /// </summary>
        /// <param name="ex">目标公式。</param>
        public static void AutoLocation(Expressions.Expression ex)
        {
            if (ex == null) return;
            if (ex.Editor == null) return;
            if (ex.Editor.IsOpened == false) return;
            if (ex.Editor != Globals.selectedEditor) return;
            if (ex.Parent == null) return;//可能不在可视树。
            //if (ex.IsVisibleInScrollviewer == false) return;

            Globals.isDraging = false;
            if (Globals.dragSourceExpression != null) Globals.dragSourceExpression = null;

            ex.InvalidateArrange();
            ex.UpdateLayout();//不加这两句,新插入公式时定位会出问题。

            double currentVOffcet = ex.Editor.BaseScrolledViewer.VerticalOffset;
            double currentHOffcet = ex.Editor.BaseScrolledViewer.HorizontalOffset;

            Point ptBase = new Point(0, 0);
            Point ptEx = ex.PointToScreen(ptBase);
            Point ptSV = ex.Editor.BaseScrolledViewer.PointToScreen(ptBase);

            double rightOfScrollviewer = ptSV.X + ex.Editor.BaseScrolledViewer.ActualWidth;
            double rightOfBaseText = ptEx.X + ex.Editor.SelectedExpression.ActualWidth;
            
            Rect exRect = new Rect(ptEx, new Point(ptEx.X + ex.ActualWidth, ptEx.Y + ex.ActualHeight));
            Rect svRect = new Rect(ptSV, new Point(ptSV.X + ex.Editor.BaseScrolledViewer.ActualWidth - 24,
                ptSV.Y + ex.Editor.BaseScrolledViewer.ActualHeight - 24));//24是滚动条的宽度。

            //如果公式宽、高都小于可视区。
            if (exRect.Width < svRect.Width && exRect.Height < svRect.Height)
            {
                //第一种情况。公式部分或全部在可视区左上角且不可全见或不可见。
                if (exRect.Top < svRect.Top && exRect.Left < svRect.Left)
                {
                    //定位到编辑区左上角。
                    ex.Editor.BaseScrolledViewer.
                        ScrollToHorizontalOffset(currentHOffcet - (svRect.Left - exRect.Left) - 4);
                    ex.Editor.BaseScrolledViewer.
                        ScrollToVerticalOffset(currentVOffcet - (svRect.Top - exRect.Top));
                }
                //第二种情况。公式部分或全部在可视区右上角且不可全见或不可见。
                else if (exRect.Right > svRect.Right && exRect.Top < svRect.Top)
                {
                    //定位到右上角。
                    ex.Editor.BaseScrolledViewer.
                        ScrollToHorizontalOffset(currentHOffcet + (exRect.Right - svRect.Right));
                    ex.Editor.BaseScrolledViewer.
后面还有 84 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。