Skip to content

Commit

Permalink
Add TextEditor component;
Browse files Browse the repository at this point in the history
  • Loading branch information
onepiecefreak3 committed Oct 27, 2024
1 parent a4ba1fa commit fff0eeb
Show file tree
Hide file tree
Showing 16 changed files with 2,855 additions and 4 deletions.
69 changes: 69 additions & 0 deletions ImGui.Forms/Controls/Text/Editor/Coordinate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System;

namespace ImGui.Forms.Controls.Text.Editor
{
public struct Coordinate
{
public int Line { get; set; }
public int Column { get; set; }

public Coordinate()
{
Line = -1;
Column = -1;
}

public Coordinate(int line, int column)
{
Line = Math.Max(0, line);
Column = Math.Max(0, column);
}

public static bool operator ==(Coordinate a, Coordinate o) => a.Line == o.Line && a.Column == o.Column;
public static bool operator !=(Coordinate a, Coordinate o) => a.Line != o.Line || a.Column != o.Column;

public static bool operator <(Coordinate a, Coordinate o)
{
if (a.Line != o.Line)
return a.Line < o.Line;

return a.Column < o.Column;
}
public static bool operator >(Coordinate a, Coordinate o)
{
if (a.Line != o.Line)
return a.Line > o.Line;

return a.Column > o.Column;
}

public static bool operator <=(Coordinate a, Coordinate o)
{
if (a.Line != o.Line)
return a.Line < o.Line;

return a.Column <= o.Column;
}
public static bool operator >=(Coordinate a, Coordinate o)
{
if (a.Line != o.Line)
return a.Line > o.Line;

return a.Column >= o.Column;
}

public bool Equals(Coordinate other)
{
return Line == other.Line && Column == other.Column;
}
public override bool Equals(object obj)
{
return obj is Coordinate other && Equals(other);
}

public override int GetHashCode()
{
return HashCode.Combine(Line, Column);
}
}
}
9 changes: 9 additions & 0 deletions ImGui.Forms/Controls/Text/Editor/EditorState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace ImGui.Forms.Controls.Text.Editor
{
struct EditorState
{
public Coordinate SelectionStart { get; set; }
public Coordinate SelectionEnd { get; set; }
public Coordinate CursorPosition { get; set; }
}
}
18 changes: 18 additions & 0 deletions ImGui.Forms/Controls/Text/Editor/Glyph.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace ImGui.Forms.Controls.Text.Editor
{
class Glyph
{
public char Character { get; }
public PaletteIndex ColorIndex { get; set; }

public bool IsComment { get; set; }
public bool IsMultiLineComment { get; set; }
public bool IsPreprocessor { get; set; }

public Glyph(char character, PaletteIndex colorIndex = PaletteIndex.Default)
{
Character = character;
ColorIndex = colorIndex;
}
}
}
18 changes: 18 additions & 0 deletions ImGui.Forms/Controls/Text/Editor/GlyphLine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Collections.Generic;

namespace ImGui.Forms.Controls.Text.Editor
{
class GlyphLine
{
public bool HasCarriageReturn { get; set; }
public List<Glyph> Glyphs { get; } = new();

public int Length => Glyphs.Count;

public Glyph this[int i]
{
get => Glyphs[i];
set => Glyphs[i] = value;
}
}
}
8 changes: 8 additions & 0 deletions ImGui.Forms/Controls/Text/Editor/Identifier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace ImGui.Forms.Controls.Text.Editor
{
public struct Identifier
{
public Coordinate Location { get; set; }
public string Value { get; set; }
}
}
36 changes: 36 additions & 0 deletions ImGui.Forms/Controls/Text/Editor/LanguageDefinition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Collections.Generic;

namespace ImGui.Forms.Controls.Text.Editor
{
public class LanguageDefinition
{
public string Name { get; protected set; } = string.Empty;

public IReadOnlySet<string> Keywords { get; protected set; } = new HashSet<string>();
public IReadOnlyDictionary<string, Identifier> Identifiers { get; protected set; } = new Dictionary<string, Identifier>();
public IReadOnlyDictionary<string, Identifier> Preprocessors { get; protected set; } = new Dictionary<string, Identifier>();
public IReadOnlyList<(string, PaletteIndex)> TokenRegularExpressions { get; protected set; } = new List<(string, PaletteIndex)>();

public string SingleLineCommentIdentifier { get; protected set; } = string.Empty;
public string CommentStartIdentifier { get; protected set; } = string.Empty;
public string CommentEndIdentifier { get; protected set; } = string.Empty;
public char PreprocessorCharacter { get; protected set; } = '#';

public bool IsAutoIndentation { get; protected set; }
public bool IsCaseSensitive { get; protected set; }


public virtual bool CanTokenize() => false;

public virtual bool Tokenize(string text, int inBegin, int inEnd,
out int outBegin, out int outEnd, out PaletteIndex paletteIndex)
{
outBegin = 0;
outEnd = 0;
paletteIndex = 0;

return false;
}
}

}
28 changes: 28 additions & 0 deletions ImGui.Forms/Controls/Text/Editor/PaletteIndex.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace ImGui.Forms.Controls.Text.Editor
{
public enum PaletteIndex
{
Default,
Keyword,
Number,
String,
CharLiteral,
Punctuation,
Preprocessor,
Identifier,
KnownIdentifier,
PreprocessorIdentifier,
Comment,
MultiLineComment,
Background,
Cursor,
Selection,
ErrorMarker,
Breakpoint,
LineNumber,
CurrentLineFill,
CurrentLineFillInactive,
CurrentLineEdge,
Max
}
}
9 changes: 9 additions & 0 deletions ImGui.Forms/Controls/Text/Editor/SelectionMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace ImGui.Forms.Controls.Text.Editor
{
public enum SelectionMode
{
Normal,
Word,
Line
}
}
Loading

0 comments on commit fff0eeb

Please sign in to comment.