aboutsummaryrefslogtreecommitdiffstatsci
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2021-09-27 05:25:11 +0000
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>2021-09-27 05:25:11 +0000
commit0c0359bcbbe32b0222a76d3dcdf036cb48928acc (patch)
treeb3e7536d206267433adab2fd38c8b868fcd578f1
parent721fb6cc4bb10a03b11d18614020432237d07273 (diff)
wip, set v0.9.8
-rw-r--r--Crow/src/Input/MouseEventArgs.cs6
-rw-r--r--Crow/src/Interface.cs2
-rw-r--r--Crow/src/Mono.Cairo0
-rw-r--r--Crow/src/Text/CharLocation.cs8
-rw-r--r--Crow/src/Text/TextLine.cs4
-rw-r--r--Crow/src/Text/TextLineCollection.cs358
-rw-r--r--Crow/src/Text/TextSpan.cs4
-rw-r--r--Directory.Build.props2
8 files changed, 196 insertions, 188 deletions
diff --git a/Crow/src/Input/MouseEventArgs.cs b/Crow/src/Input/MouseEventArgs.cs
index f84822eb..9b242dd6 100644
--- a/Crow/src/Input/MouseEventArgs.cs
+++ b/Crow/src/Input/MouseEventArgs.cs
@@ -32,6 +32,10 @@ namespace Crow
X = x;
Y = y;
}
+ public MouseEventArgs (Point mousePosition) {
+ X = mousePosition.X;
+ Y = mousePosition.Y;
+ }
}
public class MouseMoveEventArgs : MouseEventArgs
{
@@ -57,7 +61,7 @@ namespace Crow
public class MouseWheelEventArgs : MouseEventArgs
{
public readonly int Delta;
- public MouseWheelEventArgs (int delta)
+ public MouseWheelEventArgs (int delta, Point mousePosition) : base (mousePosition)
{
Delta = delta;
}
diff --git a/Crow/src/Interface.cs b/Crow/src/Interface.cs
index c177cd1b..0901b9bc 100644
--- a/Crow/src/Interface.cs
+++ b/Crow/src/Interface.cs
@@ -1906,7 +1906,7 @@ namespace Crow
/// <param name="delta">wheel delta</param>
public virtual bool OnMouseWheelChanged (float delta)
{
- MouseWheelEventArgs e = new MouseWheelEventArgs ((int)delta);
+ MouseWheelEventArgs e = new MouseWheelEventArgs ((int)delta, MousePosition);
if (_hoverWidget == null)
return false;
diff --git a/Crow/src/Mono.Cairo b/Crow/src/Mono.Cairo
deleted file mode 100644
index e69de29b..00000000
--- a/Crow/src/Mono.Cairo
+++ /dev/null
diff --git a/Crow/src/Text/CharLocation.cs b/Crow/src/Text/CharLocation.cs
index cfc537c6..0d07b302 100644
--- a/Crow/src/Text/CharLocation.cs
+++ b/Crow/src/Text/CharLocation.cs
@@ -6,13 +6,13 @@ using System.Diagnostics;
namespace Crow.Text
{
- [DebuggerDisplay ("{Line}, {Column}, {VisualCharXPosition}")]
+ [DebuggerDisplay ("{Line}, {Column}, {VisualCharXPosition}")]
public struct CharLocation : IEquatable<CharLocation>
{
public readonly int Line;
/// <summary>
/// Character position in current line. If equals '-1', the visualX must contains the on screen position.
- ///
+ ///
/// </summary>
public int Column;
public double VisualCharXPosition;
@@ -21,7 +21,7 @@ namespace Crow.Text
Column = column;
VisualCharXPosition = visualX;
}
- public bool HasVisualX => Column >= 0 && VisualCharXPosition >= 0;
+ public bool HasVisualX => Column >= 0 && VisualCharXPosition >= 0;
public void ResetVisualX () => VisualCharXPosition = -1;
public static bool operator == (CharLocation a, CharLocation b)
=> a.Equals (b);
@@ -40,5 +40,5 @@ namespace Crow.Text
}
public override string ToString () => $"{Line}, {Column}";
- }
+ }
}
diff --git a/Crow/src/Text/TextLine.cs b/Crow/src/Text/TextLine.cs
index e3565083..d757ed77 100644
--- a/Crow/src/Text/TextLine.cs
+++ b/Crow/src/Text/TextLine.cs
@@ -41,6 +41,8 @@ namespace Crow.Text
/// Absolute end character position just before linebreak if any.
/// </summary>
public int End => Start + Length;
+ public TextSpan Span => new TextSpan (Start, End);
+ public TextSpan SpanIncludingLineBreak => new TextSpan (Start, EndIncludingLineBreak);
/// <summary>
/// Absolute line's end position after linebreak if any.
/// </summary>
@@ -85,7 +87,7 @@ namespace Crow.Text
/// </summary>
/// <param name="start"></param>
/// <returns></returns>
- public TextLine WithStartOffset (int start) => new TextLine (Start + start, End, EndIncludingLineBreak);
+ public TextLine WithStartOffset (int start) => new TextLine (Start + start, End, EndIncludingLineBreak);
public int CompareTo (TextLine other) => Start - other.Start;
}
}
diff --git a/Crow/src/Text/TextLineCollection.cs b/Crow/src/Text/TextLineCollection.cs
index 19696867..19be9c9e 100644
--- a/Crow/src/Text/TextLineCollection.cs
+++ b/Crow/src/Text/TextLineCollection.cs
@@ -8,203 +8,203 @@ using System.Text;
namespace Crow.Text
{
- public class LineCollection : IList<TextLine>
- {
- TextLine[] lines;
- int length;
+ public class LineCollection : IList<TextLine>
+ {
+ TextLine[] lines;
+ int length;
- #region CTOR
- public LineCollection (int capacity) {
- lines = new TextLine[capacity];
- length = 0;
- }
- public LineCollection (TextLine[] _lines, int capacity = -1) {
- if (capacity >= _lines.Length) {
- lines = new TextLine[capacity];
- _lines.AsSpan ().CopyTo (lines);
- } else
- lines =_lines;
-
- length = _lines.Length;
- }
-
- public LineCollection (string _text, int capacity = 4) : this (capacity) {
- Update (_text.AsSpan ());
- }
- #endregion
+ #region CTOR
+ public LineCollection (int capacity) {
+ lines = new TextLine[capacity];
+ length = 0;
+ }
+ public LineCollection (TextLine[] _lines, int capacity = -1) {
+ if (capacity >= _lines.Length) {
+ lines = new TextLine[capacity];
+ _lines.AsSpan ().CopyTo (lines);
+ } else
+ lines =_lines;
- public void Update (ReadOnlySpan<char> _text) {
- length = 0;
- int start = 0, i = 0;
- while (i < _text.Length) {
- char c = _text[i];
- if (c == '\r') {
- if (++i < _text.Length) {
- if (_text[i] == '\n')
- Add (new TextLine (start, i - 1, ++i));
- else
- Add (new TextLine (start, i - 1, i));
- } else
- Add (new TextLine (start, i - 1, i));
- start = i;
- } else if (c == '\n') {
- if (++i < _text.Length) {
- if (_text[i] == '\r')
- Add (new TextLine (start, i - 1, ++i));
- else
- Add (new TextLine (start, i - 1, i));
- } else
- Add (new TextLine (start, i - 1, i));
- start = i;
+ length = _lines.Length;
+ }
- } else if (c == '\u0085' || c == '\u2028' || c == '\u2029')
- Add (new TextLine (start, i - 1, i));
- else
- i++;
- }
+ public LineCollection (string _text, int capacity = 4) : this (capacity) {
+ Update (_text.AsSpan ());
+ }
+ #endregion
- if (start < i)
- Add (new TextLine (start, _text.Length, _text.Length));
- else
- Add (new TextLine (_text.Length, _text.Length, _text.Length));
- }
+ public void Update (ReadOnlySpan<char> _text) {
+ length = 0;
+ int start = 0, i = 0;
+ while (i < _text.Length) {
+ char c = _text[i];
+ if (c == '\r') {
+ if (++i < _text.Length) {
+ if (_text[i] == '\n')
+ Add (new TextLine (start, i - 1, ++i));
+ else
+ Add (new TextLine (start, i - 1, i));
+ } else
+ Add (new TextLine (start, i - 1, i));
+ start = i;
+ } else if (c == '\n') {
+ if (++i < _text.Length) {
+ if (_text[i] == '\r')
+ Add (new TextLine (start, i - 1, ++i));
+ else
+ Add (new TextLine (start, i - 1, i));
+ } else
+ Add (new TextLine (start, i - 1, i));
+ start = i;
- public void Update (TextChange change) {
- CharLocation locStart = GetLocation (change.Start);
- int charsDiff = change.ChangedText.Length - change.Length;
- int lineEnd = locStart.Line;
- while (lineEnd < length - 1 && change.End >= lines[lineEnd + 1].Start)
- lineEnd++;
- int columnEnd = change.End - lines[lineEnd].Start;
- int lineEndLineBreakLength = lines[lineEnd].LineBreakLength;
+ } else if (c == '\u0085' || c == '\u2028' || c == '\u2029')
+ Add (new TextLine (start, i - 1, i));
+ else
+ i++;
+ }
- LineCollection newLines = new LineCollection (change.ChangedText);
- int linesDiff = newLines.length - 1 - (lineEnd - locStart.Line);
- TextLine endTl = lines[lineEnd];
+ if (start < i)
+ Add (new TextLine (start, _text.Length, _text.Length));
+ else
+ Add (new TextLine (_text.Length, _text.Length, _text.Length));
+ }
- if (linesDiff < 0)
- RemoveAt (locStart.Line + 1, -linesDiff);
- else if (linesDiff > 0) {
- for (int i = 0; i < linesDiff; i++)
- Insert (locStart.Line + 1, default);
- }
+ public void Update (TextChange change) {
+ CharLocation locStart = GetLocation (change.Start);
+ int charsDiff = change.ChangedText.Length - change.Length;
+ int lineEnd = locStart.Line;
+ while (lineEnd < length - 1 && change.End >= lines[lineEnd + 1].Start)
+ lineEnd++;
+ int columnEnd = change.End - lines[lineEnd].Start;
+ int lineEndLineBreakLength = lines[lineEnd].LineBreakLength;
- int remainingColumns = endTl.Length - columnEnd;
- lineEnd += linesDiff;
- lines[lineEnd].SetLength (0);
- lines[locStart.Line].SetLength (locStart.Column + newLines[0].Length);
- lines[lineEnd].Length += remainingColumns;
- if (newLines.Count > 1) {
- lines[lineEnd].Length += newLines[newLines.Count - 1].Length;
- lines[locStart.Line].LengthIncludingLineBreak = lines[locStart.Line].Length + newLines[0].LineBreakLength;
- }
- lines[lineEnd].LengthIncludingLineBreak = lines[lineEnd].Length + endTl.LineBreakLength;
+ LineCollection newLines = new LineCollection (change.ChangedText);
+ int linesDiff = newLines.length - 1 - (lineEnd - locStart.Line);
+ TextLine endTl = lines[lineEnd];
- for (int i = 1; i < newLines.Count - 1; i++) {
- int l = locStart.Line + i;
- lines[l] = newLines[i];
- lines[l].Start = lines[l - 1].EndIncludingLineBreak;
- }
- if (lineEnd > 0)
- lines[lineEnd].Start = lines[lineEnd - 1].EndIncludingLineBreak;
+ if (linesDiff < 0)
+ RemoveAt (locStart.Line + 1, -linesDiff);
+ else if (linesDiff > 0) {
+ for (int i = 0; i < linesDiff; i++)
+ Insert (locStart.Line + 1, default);
+ }
- //shift start for remaining lines
- for (int i = lineEnd + 1; i < length; i++)
- lines[i].Start += charsDiff;
- }
- public int GetAbsolutePosition (CharLocation loc) => lines[loc.Line].Start + loc.Column;
- public CharLocation GetLocation (int absolutePosition) {
- TextLine tl = new TextLine (absolutePosition);
- int result = lines.AsSpan (0, length).BinarySearch (tl);
- if (result < 0) {
- result = ~result;
- return result == 0 ?
- new CharLocation (0, absolutePosition) :
- new CharLocation (result - 1, absolutePosition - lines[result - 1].Start);
- }
- return new CharLocation (result, absolutePosition - lines[result].Start);
- }
- public void UpdateLineLengthInPixel (int index, int lengthInPixel) {
- lines[index].LengthInPixel = lengthInPixel;
- }
- public int Count => length;
- public bool IsReadOnly => false;
- public bool IsEmpty => length == 0;
+ int remainingColumns = endTl.Length - columnEnd;
+ lineEnd += linesDiff;
+ lines[lineEnd].SetLength (0);
+ lines[locStart.Line].SetLength (locStart.Column + newLines[0].Length);
+ lines[lineEnd].Length += remainingColumns;
+ if (newLines.Count > 1) {
+ lines[lineEnd].Length += newLines[newLines.Count - 1].Length;
+ lines[locStart.Line].LengthIncludingLineBreak = lines[locStart.Line].Length + newLines[0].LineBreakLength;
+ }
+ lines[lineEnd].LengthIncludingLineBreak = lines[lineEnd].Length + endTl.LineBreakLength;
- public TextLine this[int index] { get => lines[index]; set => lines[index] = value; }
+ for (int i = 1; i < newLines.Count - 1; i++) {
+ int l = locStart.Line + i;
+ lines[l] = newLines[i];
+ lines[l].Start = lines[l - 1].EndIncludingLineBreak;
+ }
+ if (lineEnd > 0)
+ lines[lineEnd].Start = lines[lineEnd - 1].EndIncludingLineBreak;
- public void Add (TextLine item) {
- if (lines.Length < length + 1) {
- TextLine[] tmp = new TextLine[length * 2];
- lines.AsSpan ().CopyTo (tmp);
- lines = tmp;
- }
- lines[length] = item;
- length++;
- }
+ //shift start for remaining lines
+ for (int i = lineEnd + 1; i < length; i++)
+ lines[i].Start += charsDiff;
+ }
+ public int GetAbsolutePosition (CharLocation loc) => lines[loc.Line].Start + loc.Column;
+ public CharLocation GetLocation (int absolutePosition) {
+ TextLine tl = new TextLine (absolutePosition);
+ int result = lines.AsSpan (0, length).BinarySearch (tl);
+ if (result < 0) {
+ result = ~result;
+ return result == 0 ?
+ new CharLocation (0, absolutePosition) :
+ new CharLocation (result - 1, absolutePosition - lines[result - 1].Start);
+ }
+ return new CharLocation (result, absolutePosition - lines[result].Start);
+ }
+ public void UpdateLineLengthInPixel (int index, int lengthInPixel) {
+ lines[index].LengthInPixel = lengthInPixel;
+ }
+ public int Count => length;
+ public bool IsReadOnly => false;
+ public bool IsEmpty => length == 0;
- public void Clear () {
- length = 0;
- }
+ public TextLine this[int index] { get => lines[index]; set => lines[index] = value; }
- public bool Contains (TextLine item) => Array.IndexOf<TextLine> (lines, item) >= 0;
+ public void Add (TextLine item) {
+ if (lines.Length < length + 1) {
+ TextLine[] tmp = new TextLine[length * 2];
+ lines.AsSpan ().CopyTo (tmp);
+ lines = tmp;
+ }
+ lines[length] = item;
+ length++;
+ }
- public void CopyTo (TextLine[] array, int arrayIndex) {
- lines.AsSpan (0, length).CopyTo (array.AsSpan (arrayIndex));
- }
+ public void Clear () {
+ length = 0;
+ }
- public bool Remove (TextLine item) {
- int idx = Array.IndexOf<TextLine> (lines, item);
- if (idx < 0)
- return false;
- if (idx + 1 < length)
- lines.AsSpan (idx + 1, length - idx - 1).CopyTo (lines.AsSpan (idx));
- length--;
- return true;
- }
- public IEnumerator<TextLine> GetEnumerator () => new Enumerator (this);
- IEnumerator IEnumerable.GetEnumerator () => GetEnumerator ();
+ public bool Contains (TextLine item) => Array.IndexOf<TextLine> (lines, item) >= 0;
- public int IndexOf (TextLine item) => Array.IndexOf (lines, item);
+ public void CopyTo (TextLine[] array, int arrayIndex) {
+ lines.AsSpan (0, length).CopyTo (array.AsSpan (arrayIndex));
+ }
- public void Insert (int index, TextLine item) {
- if (lines.Length < length + 1) {
- TextLine[] tmp = new TextLine[length * 2];
- lines.AsSpan (0, index).CopyTo (tmp);
- lines.AsSpan (index).CopyTo (tmp.AsSpan (index + 1));
- lines = tmp;
- }else
- lines.AsSpan (index, length - index).CopyTo (lines.AsSpan (index + 1));
- lines[index] = item;
- length++;
- }
+ public bool Remove (TextLine item) {
+ int idx = Array.IndexOf<TextLine> (lines, item);
+ if (idx < 0)
+ return false;
+ if (idx + 1 < length)
+ lines.AsSpan (idx + 1, length - idx - 1).CopyTo (lines.AsSpan (idx));
+ length--;
+ return true;
+ }
+ public IEnumerator<TextLine> GetEnumerator () => new Enumerator (this);
+ IEnumerator IEnumerable.GetEnumerator () => GetEnumerator ();
- public void RemoveAt (int index) {
- if (index + 1 < length)
- lines.AsSpan (index + 1, length - index - 1).CopyTo (lines.AsSpan (index));
- length--;
- }
- public void RemoveAt (int index, int count) {
- if (index + count < length)
- lines.AsSpan (index + count, length - index - count).CopyTo (lines.AsSpan (index));
- length -= count;
- }
+ public int IndexOf (TextLine item) => Array.IndexOf (lines, item);
- public class Enumerator : IEnumerator<TextLine>
- {
- TextLine[] lines;
- int length, position = -1;
- public Enumerator (LineCollection coll) {
- lines = coll.lines;
- length = coll.length;
- }
- public TextLine Current => lines[position];
- object IEnumerator.Current => Current;
- public void Dispose () { }
- public bool MoveNext () => ++position < length;
- public void Reset () {
- position = -1;
- }
- }
- }
+ public void Insert (int index, TextLine item) {
+ if (lines.Length < length + 1) {
+ TextLine[] tmp = new TextLine[length * 2];
+ lines.AsSpan (0, index).CopyTo (tmp);
+ lines.AsSpan (index).CopyTo (tmp.AsSpan (index + 1));
+ lines = tmp;
+ }else
+ lines.AsSpan (index, length - index).CopyTo (lines.AsSpan (index + 1));
+ lines[index] = item;
+ length++;
+ }
+
+ public void RemoveAt (int index) {
+ if (index + 1 < length)
+ lines.AsSpan (index + 1, length - index - 1).CopyTo (lines.AsSpan (index));
+ length--;
+ }
+ public void RemoveAt (int index, int count) {
+ if (index + count < length)
+ lines.AsSpan (index + count, length - index - count).CopyTo (lines.AsSpan (index));
+ length -= count;
+ }
+
+ public class Enumerator : IEnumerator<TextLine>
+ {
+ TextLine[] lines;
+ int length, position = -1;
+ public Enumerator (LineCollection coll) {
+ lines = coll.lines;
+ length = coll.length;
+ }
+ public TextLine Current => lines[position];
+ object IEnumerator.Current => Current;
+ public void Dispose () { }
+ public bool MoveNext () => ++position < length;
+ public void Reset () {
+ position = -1;
+ }
+ }
+ }
}
diff --git a/Crow/src/Text/TextSpan.cs b/Crow/src/Text/TextSpan.cs
index ddc21c47..929d5054 100644
--- a/Crow/src/Text/TextSpan.cs
+++ b/Crow/src/Text/TextSpan.cs
@@ -27,9 +27,11 @@ namespace Crow.Text
public override int GetHashCode()
=> HashCode.Combine(Start, End);
public static bool operator ==(TextSpan left, TextSpan right)
- => left.Equals (right);
+ => left.Equals (right);
public static bool operator !=(TextSpan left, TextSpan right)
=> !left.Equals (right);
public override string ToString() => $"{Start},{End}";
+ public bool Contains (int absolutePosition)
+ => absolutePosition >= Start && absolutePosition < End;
}
}
diff --git a/Directory.Build.props b/Directory.Build.props
index a0ea5fb5..c0160dcb 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -6,7 +6,7 @@
<Authors>Jean-Philippe Bruyère</Authors>
<LangVersion>7.3</LangVersion>
- <CrowVersion>0.9.7</CrowVersion>
+ <CrowVersion>0.9.8</CrowVersion>
<CrowPackageVersion>$(CrowVersion)-beta</CrowPackageVersion>
<!-- If you dont have a native libstb on your system, enable the managed version of stb here