Skip to content

Commit 478b0bb

Browse files
committed
Fixes and added Text editor
1 parent 663ffbe commit 478b0bb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+6441
-2593
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-

1+
global using static Hexa.NET.Utilities.Utils;

Hexa.NET.ImGui.Widgets.Extras/Hexa.NET.ImGui.Widgets.Extras.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
88

99
<AssemblyVersion>1.0.0</AssemblyVersion>
10-
<PackageVersion>1.0.1</PackageVersion>
10+
<PackageVersion>1.0.2</PackageVersion>
1111
<Description>
1212
Hexa.NET.ImGui.Widgets is a comprehensive library of custom widgets for the ImGui graphical user interface library. This package includes a variety of pre-built widgets that enhance the functionality and usability of ImGui in your .NET applications. Each widget is designed to be easy to integrate, with consistent styling and behavior. This library is an extension of the Hexa.NET.ImGui wrapper, providing additional UI components for a seamless user experience.
1313
</Description>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace Hexa.NET.ImGui.Widgets.Extras.TextEditor
2+
{
3+
using System.Collections.Generic;
4+
5+
public readonly struct CaseInsensitiveComparer : IEqualityComparer<char>
6+
{
7+
public static readonly CaseInsensitiveComparer Default = new();
8+
9+
public readonly bool Equals(char x, char y)
10+
{
11+
return char.ToLowerInvariant(x) == char.ToLowerInvariant(y);
12+
}
13+
14+
public readonly int GetHashCode(char obj)
15+
{
16+
return char.ToLowerInvariant(obj).GetHashCode();
17+
}
18+
}
19+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
namespace Hexa.NET.ImGui.Widgets.Extras.TextEditor
2+
{
3+
using System.Numerics;
4+
using System.Xml.Serialization;
5+
6+
[XmlRoot("Color")]
7+
public struct ColorRGBA
8+
{
9+
[XmlAttribute("r")]
10+
public float R;
11+
12+
[XmlAttribute("g")]
13+
public float G;
14+
15+
[XmlAttribute("b")]
16+
public float B;
17+
18+
[XmlAttribute("a")]
19+
public float A;
20+
21+
public ColorRGBA(float r, float g, float b, float a)
22+
{
23+
R = r;
24+
G = g;
25+
B = b;
26+
A = a;
27+
}
28+
29+
public ColorRGBA(Vector4 color)
30+
{
31+
R = color.X;
32+
G = color.Y;
33+
B = color.Z;
34+
A = color.W;
35+
}
36+
37+
public ColorRGBA(uint color)
38+
{
39+
R = (color >> 24 & 0xff) / (float)byte.MaxValue;
40+
G = (color >> 16 & 0xff) / (float)byte.MaxValue;
41+
B = (color >> 8 & 0xff) / (float)byte.MaxValue;
42+
A = (color & 0xff) / (float)byte.MaxValue;
43+
}
44+
45+
public static implicit operator Vector4(ColorRGBA c)
46+
{
47+
return new(c.R, c.G, c.B, c.A);
48+
}
49+
50+
public static implicit operator ColorRGBA(uint color)
51+
{
52+
return new(color);
53+
}
54+
}
55+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
namespace Hexa.NET.ImGui.Widgets.Extras.TextEditor
2+
{
3+
public struct CursorState
4+
{
5+
public int Index;
6+
public int Line;
7+
public int Column;
8+
9+
public CursorState(int index, int line, int column)
10+
{
11+
Index = index;
12+
Line = line;
13+
Column = column;
14+
}
15+
16+
public static readonly CursorState NewLineLF = new(1, 1, 0);
17+
public static readonly CursorState NewLineCR = new(1, 1, 0);
18+
public static readonly CursorState NewLineCRLF = new(2, 1, 0);
19+
public static readonly CursorState Invalid = new(-1, -1, -1);
20+
21+
public static CursorState FromOffset(int offset)
22+
{
23+
return new CursorState(offset, 0, offset);
24+
}
25+
26+
public static CursorState FromIndex(int index, TextSource source)
27+
{
28+
int line = 0;
29+
int column = 0;
30+
for (; line < source.LineCount; line++)
31+
{
32+
var lineSpan = source.Lines[line];
33+
if (lineSpan.Start <= index && lineSpan.End >= index)
34+
{
35+
column = index - lineSpan.Start;
36+
break;
37+
}
38+
}
39+
40+
return new(index, line, column);
41+
}
42+
43+
public static CursorState FromLineColumn(int line, int column, TextSource source)
44+
{
45+
var lineSpan = source.Lines[line];
46+
var index = lineSpan.Start + column;
47+
return new(index, line, column);
48+
}
49+
50+
public static CursorState operator ++(CursorState state)
51+
{
52+
int newIndex = state.Index + 1;
53+
int newColumn = state.Column + 1;
54+
return new(newIndex, state.Line, newColumn);
55+
}
56+
57+
public static CursorState operator --(CursorState state)
58+
{
59+
int newLine = state.Line;
60+
int newColumn = state.Column - 1;
61+
if (newColumn < 0)
62+
{
63+
newLine--;
64+
newColumn = 0;
65+
}
66+
return new(state.Index - 1, newLine, newColumn);
67+
}
68+
69+
public static CursorState operator +(CursorState a, CursorState b)
70+
{
71+
return new CursorState(a.Index + b.Index, a.Line + b.Line, a.Column + b.Column);
72+
}
73+
74+
public static CursorState operator -(CursorState a, CursorState b)
75+
{
76+
return new CursorState(a.Index - b.Index, a.Line - b.Line, a.Column - b.Column);
77+
}
78+
79+
public static implicit operator int(CursorState state) => state.Index;
80+
}
81+
}

0 commit comments

Comments
 (0)