]> O.S.I.I.S - jp/crowedit.git/commitdiff
debug editors
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 22 Sep 2021 15:56:29 +0000 (15:56 +0000)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 22 Sep 2021 15:56:29 +0000 (15:56 +0000)
CrowEditBase/src/CrowEditBase.cs
CrowEditBase/src/Editor.cs
CrowEditBase/src/SourceEditor.cs
CrowEditBase/ui/CrowEdit.style
CrowEditBase/ui/sourceEditor.itmp

index a34ec0f951146d9a6f4b7220a7568fccfc0fc4b7..f89d437105953e49f2475e886b4e8e76d742d7dc 100644 (file)
@@ -312,8 +312,7 @@ namespace CrowEditBase
                        <ListItem IsVisible='{IsSelected}' IsSelected='{²IsSelected}' Selected=""{/tb.HasFocus='true'}"">
                                <VerticalStack Spacing='0'>
                                        <HorizontalStack Spacing='0'>
-                                               <Editor Name='tb' Font='consolas, 12' Focusable='true' Height='Stretched' Width='Stretched'
-                                                               Margin='50' ClipToClientRect='true'
+                                               <Editor Name='tb' Font='consolas, 12' Margin='5'
                                                                Document='{}' TextChanged='onTextChanged'/>
                                                <ScrollBar Value='{²../tb.ScrollY}'
                                                                LargeIncrement='{../tb.PageHeight}' SmallIncrement='1'
@@ -322,9 +321,8 @@ namespace CrowEditBase
                                        <ScrollBar Style='HScrollBar' Value='{²../tb.ScrollX}'
                                                        LargeIncrement='{../tb.PageWidth}' SmallIncrement='1'
                                                        CursorRatio='{../tb.ChildWidthRatio}' Maximum='{../tb.MaxScrollX}' />
-                                       <HorizontalStack Height='Fit'>
+                                       <HorizontalStack Height='Fit' Spacing='3'>
                                                <Widget Width='Stretched'/>
-                                               <Widget Height='5' Width='10'/>
                                                <Label Text='Line:' Foreground='Grey'/>
                                                <Label Text='{../../tb.CurrentLine}' Margin='3'/>
                                                <Label Text='col:' Foreground='Grey'/>
index 1d3fdc16e0f218e59015b9d06ba85f757cd31772..2388a0c0a181adf56cfbcdda79ec969bd9f8a4bd 100644 (file)
@@ -840,8 +840,8 @@ namespace Crow
 
 
                #region textBox
-               bool autoAdjustScroll = false;//if scrollXY is changed directly, dont try adjust scroll to cursor
-               internal RectangleD? computeTextCursor (Rectangle cursor) {
+               protected bool autoAdjustScroll = false;//if scrollXY is changed directly, dont try adjust scroll to cursor
+               protected virtual RectangleD? computeTextCursor (Rectangle cursor) {
                        Rectangle cb = ClientRectangle;
                        cursor -= new Point (ScrollX, ScrollY);
 
index aaa93a45e6b8d9b840ee118aa4dc68908256db67..2193c3bb2fec6ff1d66c221d9ced7e77aea2c1c1 100644 (file)
@@ -214,6 +214,22 @@ namespace Crow
                                DbgLogger.EndEvent(DbgEvtType.GOMeasure);
                        }
                }
+               protected override void updateHoverLocation (Point mouseLocalPos) {
+                       int hoverLine = (int)Math.Min (Math.Max (0, Math.Floor ((mouseLocalPos.Y + ScrollY)/ (fe.Ascent + fe.Descent))), lines.Count - 1);
+                       int scrollLine = (int)Math.Ceiling((double)ScrollY / (fe.Ascent + fe.Descent));
+                       /*if (hoverLine > scrollLine + visibleLines)
+                               ScrollY = (int)((double)(hoverLine - visibleLines) * (fe.Ascent + fe.Descent));*/
+                       NotifyValueChanged("MouseY", mouseLocalPos.Y + ScrollY);
+                       NotifyValueChanged("ScrollY", ScrollY);
+                       NotifyValueChanged("VisibleLines", visibleLines);
+                       NotifyValueChanged("HoverLine", hoverLine);
+                       NotifyValueChanged("ScrollLine", hoverLine);
+                       hoverLoc = new CharLocation (hoverLine, -1, mouseLocalPos.X + ScrollX - leftMargin);
+                       using (Context gr = new Context (IFace.surf)) {
+                               setFontForContext (gr);
+                               updateLocation (gr, ClientRectangle.Width, ref hoverLoc);
+                       }
+               }
                protected override void updateMaxScrolls (LayoutingType layout) {
                        updateMargin();
                        Rectangle cb = ClientRectangle;
@@ -253,7 +269,7 @@ namespace Crow
                                double lineNumWidth = gr.TextExtents (lines.Count.ToString()).Width;
 
                                Rectangle cb = ClientRectangle;
-                               RectangleD marginRect = new RectangleD (cb.X, cb.Y, leftMargin - leftMarginRightGap, lineHeight);
+                               RectangleD marginRect = new RectangleD (cb.X + ScrollX, cb.Y, leftMargin - leftMarginRightGap, lineHeight);
                                /*gr.SetSource (App.MarginBackground);
                                gr.Rectangle (marginRect);
                                gr.Fill ();*/
@@ -263,7 +279,7 @@ namespace Crow
                                CharLocation selStart = default, selEnd = default;
                                bool selectionNotEmpty = false;
 
-                               if (HasFocus) {
+                               //if (HasFocus) {
                                        if (currentLoc?.Column < 0) {
                                                updateLocation (gr, cb.Width, ref currentLoc);
                                                NotifyValueChanged ("CurrentColumn", CurrentColumn);
@@ -301,7 +317,7 @@ namespace Crow
                                                }
                                        } else
                                                IFace.forceTextCursor = true;
-                               }
+                               //}
 
                                double spacePixelWidth = gr.TextExtents (" ").XAdvance;
                                int x = 0, y = 0;
@@ -310,9 +326,6 @@ namespace Crow
                                Foreground.SetAsSource (IFace, gr);
                                gr.Translate (-ScrollX, -ScrollY);
 
-
-
-
                                ReadOnlySpan<char> sourceBytes = doc.Source.AsSpan();
                                Span<byte> bytes = stackalloc byte[128];
                                TextExtents extents;
@@ -325,13 +338,13 @@ namespace Crow
 
                                for (int i = 0; i < lines.Count; i++) {
                                        //if (!cancelLinePrint (lineHeight, lineHeight * y, cb.Height)) {
+                                       double pixY = lineHeight * y + cb.Top;
 
                                        if (multilineToken) {
-                                               if (tok.End < lines[i].End) {//last incomplete line of multiline token
+                                               if (tok.End < lines[i].End)//last incomplete line of multiline token
                                                        buff = sourceBytes.Slice (lines[i].Start, tok.End - lines[i].Start);
-                                               } else {//print full line
+                                               else//print full line
                                                        buff = sourceBytes.Slice (lines[i].Start, lines[i].Length);
-                                               }
                                        }
 
                                        while (tok.Start < lines[i].End) {
@@ -354,7 +367,7 @@ namespace Crow
                                                if (encodedBytes > 0) {
                                                        bytes[encodedBytes++] = 0;
                                                        gr.TextExtents (bytes.Slice (0, encodedBytes), out extents);
-                                                       gr.MoveTo (pixX, lineHeight * y + fe.Ascent);
+                                                       gr.MoveTo (pixX, pixY + fe.Ascent);
                                                        gr.ShowText (bytes.Slice (0, encodedBytes));
                                                        pixX += extents.XAdvance;
                                                        x += buff.Length;
@@ -372,18 +385,17 @@ namespace Crow
                                                tok = doc.Tokens[tokPtr];
                                        }
 
-                                       RectangleD lineRect = new RectangleD (cb.X,     lineHeight * y + cb.Top, pixX, lineHeight);
+                                       RectangleD lineRect = new RectangleD (cb.X, pixY, pixX - cb.X, lineHeight);
                                        if (selectionNotEmpty) {
                                                RectangleD selRect = lineRect;
 
                                                if (i >= selStart.Line && i <= selEnd.Line) {
                                                        if (selStart.Line == selEnd.Line) {
-                                                               selRect.X = selStart.VisualCharXPosition + cb.X;
+                                                               selRect.X += selStart.VisualCharXPosition;
                                                                selRect.Width = selEnd.VisualCharXPosition - selStart.VisualCharXPosition;
                                                        } else if (i == selStart.Line) {
-                                                               double newX = selStart.VisualCharXPosition + cb.X;
-                                                               selRect.Width -= (newX - selRect.X) - 10.0;
-                                                               selRect.X = newX;
+                                                               selRect.X += selStart.VisualCharXPosition;
+                                                               selRect.Width -= selStart.VisualCharXPosition - 10.0;
                                                        } else if (i == selEnd.Line)
                                                                selRect.Width = selEnd.VisualCharXPosition - selRect.X + cb.X;
                                                        else
@@ -458,5 +470,35 @@ namespace Crow
                        }
 
                }
+               protected override RectangleD? computeTextCursor (Rectangle cursor) {
+                       Rectangle cb = ClientRectangle;
+                       cursor -= new Point (ScrollX, ScrollY);
+                       cursor.X += leftMargin;
+
+                       if (autoAdjustScroll) {
+                               autoAdjustScroll = false;
+                               int goodMsrs = 0;
+                               if (cursor.Left < leftMargin)
+                                       ScrollX += cursor.Left - leftMargin;
+                               else if (cursor.X > cb.Width)
+                                       ScrollX += cursor.X - cb.Width + 5;
+                               else
+                                       goodMsrs++;
+
+                               if (cursor.Y < 0)
+                                       ScrollY += cursor.Y;
+                               else if (cursor.Bottom > cb.Height)
+                                       ScrollY += cursor.Bottom - cb.Height;
+                               else
+                                       goodMsrs++;
+
+                               if (goodMsrs < 2)
+                                       return null;
+                       } else if (cursor.Right < 0 || cursor.X > cb.Width || cursor.Y < 0 || cursor.Bottom > cb.Height)
+                               return null;
+
+                       return cursor;
+               }
+
        }
 }
\ No newline at end of file
index f784b956ef165894d65ac1dd485ef617e80b8ad0..147c1ec89516b89255bb21ce697d9f19dda2fe9c 100644 (file)
@@ -21,11 +21,14 @@ TreeItemBackground                  = "Transparent";
 //TreeItemHighlight                    = "
 
 Editor {
+       Focusable="true";
+       Height="Stretched";
+       Width="Stretched";
        Background="White";
        Foreground="Black";
        MouseWheelSpeed = "20";
        BubbleEvents ="None";
-       ClipToClientRect = "false";
+       ClipToClientRect = "true";
 }
 
 icon {
index 527d5cfdddb272e77b04efa0c6c9f68af52398de..b1cc0b240ce739e1237614bd45d0a9ce2eb6abf7 100644 (file)
@@ -2,7 +2,7 @@
 <ListItem IsVisible="{IsSelected}" IsSelected="{²IsSelected}" Selected="{/tb.HasFocus='true'}">
        <VerticalStack Spacing="0">
                <HorizontalStack Spacing="0">
-                       <SourceEditor Name="tb"  Font="consolas, 12" Focusable="true" Height="Stretched" Width="Stretched"
+                       <SourceEditor Name="tb"  Font="consolas, 12" Margin='0'
                                        Document="{}" TextChanged="onTextChanged" />
                        <ScrollBar Value="{²../tb.ScrollY}"
                                        LargeIncrement="{../tb.PageHeight}" SmallIncrement="1"
                <ScrollBar Style="HScrollBar" Value="{²../tb.ScrollX}"
                                LargeIncrement="{../tb.PageWidth}" SmallIncrement="1"
                                CursorRatio="{../tb.ChildWidthRatio}" Maximum="{../tb.MaxScrollX}" />
-               <HorizontalStack Height="Fit">
+               <HorizontalStack Height="Fit" Spacing='3'>
                        <Widget Width="Stretched"/>
-                       <Widget Height="5" Width="10"/>
-                       <Label Text="MouseY:" Foreground="Grey"/>
+                       <!--<Label Text="MouseY:" Foreground="Grey"/>
                        <Label Text="{../../tb.MouseY}" Margin="3"/>
                        <Label Text="VisibleLines:" Foreground="Grey"/>
                        <Label Text="{../../tb.VisibleLines}" Margin="3"/>
+                       <Label Text="ScrollX:" Foreground="Grey"/>
+                       <Label Text="{../../tb.ScrollX}" Margin="3"/>
                        <Label Text="ScrollY:" Foreground="Grey"/>
                        <Label Text="{../../tb.ScrollY}" Margin="3"/>
                        <Label Text="ScrollLine:" Foreground="Grey"/>
                        <Label Text="{../../tb.ScrollLine}" Margin="3"/>
                        <Label Text="HoverLine:" Foreground="Grey"/>
-                       <Label Text="{../../tb.HoverLine}" Margin="3"/>
+                       <Label Text="{../../tb.HoverLine}" Margin="3"/>-->
                        <Label Text="Line:" Foreground="Grey"/>
                        <Label Text="{../../tb.CurrentLine}" Margin="3"/>
-                       <Label Text="col:" Foreground="Grey"/>
+                       <Label Text="Col:" Foreground="Grey"/>
                        <Label Text="{../../tb.CurrentColumn}" Margin="3"/>
                </HorizontalStack>
        </VerticalStack>