diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2021-04-13 22:06:56 +0200 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2021-04-13 22:06:56 +0200 |
| commit | a08929b22ac6b6371585beec221c3efebc3b8a71 (patch) | |
| tree | cae2c2d57d713cc125a48a51b97b215e834e1d4c /Samples | |
| parent | 8d1522d4cb7ff6db0a9f0c7a61dd75faa887fdd7 (diff) | |
discard registerLayouting for group onChildLayoutChange when not needed
Diffstat (limited to 'Samples')
| -rw-r--r-- | Samples/common/Editor.cs | 338 |
1 files changed, 171 insertions, 167 deletions
diff --git a/Samples/common/Editor.cs b/Samples/common/Editor.cs index 44168b69..1b5d337b 100644 --- a/Samples/common/Editor.cs +++ b/Samples/common/Editor.cs @@ -336,205 +336,209 @@ namespace Crow int tabSize = 4; protected override void drawContent (Context gr) { - lock(TokenMutex) { - if (source == null || source.Tokens.Length == 0) { - base.drawContent (gr); - return; - } - - Rectangle cb = ClientRectangle; - fe = gr.FontExtents; - double lineHeight = fe.Ascent + fe.Descent; + try { + lock(TokenMutex) { + if (source == null || source.Tokens.Length == 0) { + base.drawContent (gr); + return; + } + + Rectangle cb = ClientRectangle; + fe = gr.FontExtents; + double lineHeight = fe.Ascent + fe.Descent; - CharLocation selStart = default, selEnd = default; - bool selectionNotEmpty = false; + CharLocation selStart = default, selEnd = default; + bool selectionNotEmpty = false; - if (HasFocus) { - if (currentLoc?.Column < 0) { - updateLocation (gr, cb.Width, ref currentLoc); - NotifyValueChanged ("CurrentColumn", CurrentColumn); - } else - updateLocation (gr, cb.Width, ref currentLoc); + if (HasFocus) { + if (currentLoc?.Column < 0) { + updateLocation (gr, cb.Width, ref currentLoc); + NotifyValueChanged ("CurrentColumn", CurrentColumn); + } else + updateLocation (gr, cb.Width, ref currentLoc); - if (overlay != null) { - Point p = new Point((int)currentLoc.Value.VisualCharXPosition, (int)(lineHeight * (currentLoc.Value.Line + 1))); - p += ScreenCoordinates (Slot).TopLeft; - overlay.Left = p.X; - overlay.Top = p.Y; - } - if (selectionStart.HasValue) { - updateLocation (gr, cb.Width, ref selectionStart); - if (CurrentLoc.Value != selectionStart.Value) - selectionNotEmpty = true; - } - if (selectionNotEmpty) { - if (CurrentLoc.Value.Line < selectionStart.Value.Line) { - selStart = CurrentLoc.Value; - selEnd = selectionStart.Value; - } else if (CurrentLoc.Value.Line > selectionStart.Value.Line) { - selStart = selectionStart.Value; - selEnd = CurrentLoc.Value; - } else if (CurrentLoc.Value.Column < selectionStart.Value.Column) { - selStart = CurrentLoc.Value; - selEnd = selectionStart.Value; - } else { - selStart = selectionStart.Value; - selEnd = CurrentLoc.Value; + if (overlay != null) { + Point p = new Point((int)currentLoc.Value.VisualCharXPosition, (int)(lineHeight * (currentLoc.Value.Line + 1))); + p += ScreenCoordinates (Slot).TopLeft; + overlay.Left = p.X; + overlay.Top = p.Y; } - } else - IFace.forceTextCursor = true; - } + if (selectionStart.HasValue) { + updateLocation (gr, cb.Width, ref selectionStart); + if (CurrentLoc.Value != selectionStart.Value) + selectionNotEmpty = true; + } + if (selectionNotEmpty) { + if (CurrentLoc.Value.Line < selectionStart.Value.Line) { + selStart = CurrentLoc.Value; + selEnd = selectionStart.Value; + } else if (CurrentLoc.Value.Line > selectionStart.Value.Line) { + selStart = selectionStart.Value; + selEnd = CurrentLoc.Value; + } else if (CurrentLoc.Value.Column < selectionStart.Value.Column) { + selStart = CurrentLoc.Value; + selEnd = selectionStart.Value; + } else { + selStart = selectionStart.Value; + selEnd = CurrentLoc.Value; + } + } else + IFace.forceTextCursor = true; + } - double spacePixelWidth = gr.TextExtents (" ").XAdvance; - int x = 0, y = 0; - double pixX = cb.Left; + double spacePixelWidth = gr.TextExtents (" ").XAdvance; + int x = 0, y = 0; + double pixX = cb.Left; - Foreground.SetAsSource (IFace, gr); - gr.Translate (-ScrollX, -ScrollY); + Foreground.SetAsSource (IFace, gr); + gr.Translate (-ScrollX, -ScrollY); - ReadOnlySpan<char> sourceBytes = source.Source.AsSpan(); - Span<byte> bytes = stackalloc byte[128]; - TextExtents extents; - int tokPtr = 0; - Token tok = source.Tokens[tokPtr]; - bool multilineToken = false; + ReadOnlySpan<char> sourceBytes = source.Source.AsSpan(); + Span<byte> bytes = stackalloc byte[128]; + TextExtents extents; + int tokPtr = 0; + Token tok = source.Tokens[tokPtr]; + bool multilineToken = false; - ReadOnlySpan<char> buff = sourceBytes; + ReadOnlySpan<char> buff = sourceBytes; - for (int i = 0; i < lines.Count; i++) { - //if (!cancelLinePrint (lineHeight, lineHeight * y, cb.Height)) { + for (int i = 0; i < lines.Count; i++) { + //if (!cancelLinePrint (lineHeight, lineHeight * y, cb.Height)) { - if (multilineToken) { - 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 - buff = sourceBytes.Slice (lines[i].Start, lines[i].Length); + if (multilineToken) { + 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 + buff = sourceBytes.Slice (lines[i].Start, lines[i].Length); + } } - } - while (tok.Start < lines[i].End) { - if (!multilineToken) { - if (tok.End > lines[i].End) {//first line of multiline - multilineToken = true; - buff = sourceBytes.Slice (tok.Start, lines[i].End - tok.Start); - } else - buff = sourceBytes.Slice (tok.Start, tok.Length); + while (tok.Start < lines[i].End) { + if (!multilineToken) { + if (tok.End > lines[i].End) {//first line of multiline + multilineToken = true; + buff = sourceBytes.Slice (tok.Start, lines[i].End - tok.Start); + } else + buff = sourceBytes.Slice (tok.Start, tok.Length); - if (tok.Type.HasFlag (TokenType.Punctuation)) - gr.SetSource(Colors.DarkGrey); - else if (tok.Type.HasFlag (TokenType.Trivia)) - gr.SetSource(Colors.DimGrey); - else if (tok.Type == TokenType.ElementName) { - gr.SetSource(Colors.Green); - }else if (tok.Type == TokenType.AttributeName) { - gr.SetSource(Colors.Blue); - }else if (tok.Type == TokenType.AttributeValue) { - gr.SetSource(Colors.OrangeRed); - }else if (tok.Type == TokenType.EqualSign) { - gr.SetSource(Colors.Black); - }else if (tok.Type == TokenType.PI_Target) { - gr.SetSource(Colors.DarkSlateBlue); - }else { - gr.SetSource(Colors.Red); - } - } + if (tok.Type.HasFlag (TokenType.Punctuation)) + gr.SetSource(Colors.DarkGrey); + else if (tok.Type.HasFlag (TokenType.Trivia)) + gr.SetSource(Colors.DimGrey); + else if (tok.Type == TokenType.ElementName) { + gr.SetSource(Colors.Green); + }else if (tok.Type == TokenType.AttributeName) { + gr.SetSource(Colors.Blue); + }else if (tok.Type == TokenType.AttributeValue) { + gr.SetSource(Colors.OrangeRed); + }else if (tok.Type == TokenType.EqualSign) { + gr.SetSource(Colors.Black); + }else if (tok.Type == TokenType.PI_Target) { + gr.SetSource(Colors.DarkSlateBlue); + }else { + gr.SetSource(Colors.Red); + } + } - int size = buff.Length * 4 + 1; - if (bytes.Length < size) - bytes = size > 512 ? new byte[size] : stackalloc byte[size]; + int size = buff.Length * 4 + 1; + if (bytes.Length < size) + bytes = size > 512 ? new byte[size] : stackalloc byte[size]; - int encodedBytes = Crow.Text.Encoding.ToUtf8 (buff, bytes); + int encodedBytes = Crow.Text.Encoding.ToUtf8 (buff, bytes); - if (encodedBytes > 0) { - bytes[encodedBytes++] = 0; - gr.TextExtents (bytes.Slice (0, encodedBytes), out extents); - gr.MoveTo (pixX, lineHeight * y + fe.Ascent); - gr.ShowText (bytes.Slice (0, encodedBytes)); - pixX += extents.XAdvance; - x += buff.Length; - } + if (encodedBytes > 0) { + bytes[encodedBytes++] = 0; + gr.TextExtents (bytes.Slice (0, encodedBytes), out extents); + gr.MoveTo (pixX, lineHeight * y + fe.Ascent); + gr.ShowText (bytes.Slice (0, encodedBytes)); + pixX += extents.XAdvance; + x += buff.Length; + } - if (multilineToken) { - if (tok.End < lines[i].End)//last incomplete line of multiline token - multilineToken = false; - else + if (multilineToken) { + if (tok.End < lines[i].End)//last incomplete line of multiline token + multilineToken = false; + else + break; + } + + if (++tokPtr >= source.Tokens.Length) break; + tok = source.Tokens[tokPtr]; } - if (++tokPtr >= source.Tokens.Length) - break; - tok = source.Tokens[tokPtr]; - } + if (HasFocus && selectionNotEmpty) { + RectangleD lineRect = new RectangleD (cb.X, lineHeight * y + cb.Top, pixX, lineHeight); + RectangleD selRect = lineRect; + + if (i >= selStart.Line && i <= selEnd.Line) { + if (selStart.Line == selEnd.Line) { + selRect.X = selStart.VisualCharXPosition + cb.X; + 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; + } else if (i == selEnd.Line) + selRect.Width = selEnd.VisualCharXPosition - selRect.X + cb.X; + else + selRect.Width += 10.0; - if (HasFocus && selectionNotEmpty) { - RectangleD lineRect = new RectangleD (cb.X, lineHeight * y + cb.Top, pixX, lineHeight); - RectangleD selRect = lineRect; - - if (i >= selStart.Line && i <= selEnd.Line) { - if (selStart.Line == selEnd.Line) { - selRect.X = selStart.VisualCharXPosition + cb.X; - 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; - } else if (i == selEnd.Line) - selRect.Width = selEnd.VisualCharXPosition - selRect.X + cb.X; - else - selRect.Width += 10.0; + buff = sourceBytes.Slice(lines[i].Start, lines[i].Length); + int size = buff.Length * 4 + 1; + if (bytes.Length < size) + bytes = size > 512 ? new byte[size] : stackalloc byte[size]; - buff = sourceBytes.Slice(lines[i].Start, lines[i].Length); - int size = buff.Length * 4 + 1; - if (bytes.Length < size) - bytes = size > 512 ? new byte[size] : stackalloc byte[size]; + int encodedBytes = Crow.Text.Encoding.ToUtf8 (buff, bytes); - int encodedBytes = Crow.Text.Encoding.ToUtf8 (buff, bytes); - - gr.SetSource (SelectionBackground); - gr.Rectangle (selRect); - if (encodedBytes < 0) - gr.Fill (); - else { - gr.FillPreserve (); - gr.Save (); - gr.Clip (); - gr.SetSource (SelectionForeground); - gr.MoveTo (lineRect.X, lineRect.Y + fe.Ascent); - gr.ShowText (bytes.Slice (0, encodedBytes)); - gr.Restore (); + gr.SetSource (SelectionBackground); + gr.Rectangle (selRect); + if (encodedBytes < 0) + gr.Fill (); + else { + gr.FillPreserve (); + gr.Save (); + gr.Clip (); + gr.SetSource (SelectionForeground); + gr.MoveTo (lineRect.X, lineRect.Y + fe.Ascent); + gr.ShowText (bytes.Slice (0, encodedBytes)); + gr.Restore (); + } + Foreground.SetAsSource (IFace, gr); } - Foreground.SetAsSource (IFace, gr); } - } - if (!multilineToken) { - if (++tokPtr >= source.Tokens.Length) - break; - tok = source.Tokens[tokPtr]; - } + if (!multilineToken) { + if (++tokPtr >= source.Tokens.Length) + break; + tok = source.Tokens[tokPtr]; + } - x = 0; - pixX = 0; - - y++; + x = 0; + pixX = 0; + + y++; - /* } else if (tok2.Type == TokenType.Tabulation) { - int spaceRounding = x % tabSize; - int spaces = spaceRounding == 0 ? - tabSize * tok2.Length : - spaceRounding + tabSize * (tok2.Length - 1); - x += spaces; - pixX += spacePixelWidth * spaces; - continue; - } else if (tok2.Type == TokenType.WhiteSpace) { - x += tok2.Length; - pixX += spacePixelWidth * tok2.Length;*/ - } - gr.Translate (ScrollX, ScrollY); + /* } else if (tok2.Type == TokenType.Tabulation) { + int spaceRounding = x % tabSize; + int spaces = spaceRounding == 0 ? + tabSize * tok2.Length : + spaceRounding + tabSize * (tok2.Length - 1); + x += spaces; + pixX += spacePixelWidth * spaces; + continue; + } else if (tok2.Type == TokenType.WhiteSpace) { + x += tok2.Length; + pixX += spacePixelWidth * tok2.Length;*/ + } + gr.Translate (ScrollX, ScrollY); + } + } catch { + } } } |