Added ui labels for debugging and playability
This commit is contained in:
47
UI/CharData.cs
Normal file
47
UI/CharData.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
public static class CharWidth
|
||||
{
|
||||
private static readonly Dictionary<char, float> CharWidths = new Dictionary<char, float>();
|
||||
|
||||
static CharWidth()
|
||||
{
|
||||
// Default for all ASCII
|
||||
for (char c = (char)32; c <= (char)126; c++)
|
||||
CharWidths[c] = 5.0f;
|
||||
|
||||
// Override exceptions
|
||||
CharWidths[' '] = 3.0f;
|
||||
CharWidths['!'] = 1.0f;
|
||||
CharWidths['"'] = 3.0f;
|
||||
CharWidths['\''] = 1.0f;
|
||||
CharWidths['('] = 3.0f;
|
||||
CharWidths[')'] = 3.0f;
|
||||
CharWidths['*'] = 3.0f;
|
||||
CharWidths[','] = 1.0f;
|
||||
CharWidths['.'] = 1.0f;
|
||||
CharWidths[':'] = 1.0f;
|
||||
CharWidths[';'] = 1.0f;
|
||||
CharWidths['<'] = 4.0f;
|
||||
CharWidths['>'] = 4.0f;
|
||||
CharWidths['@'] = 6.0f;
|
||||
CharWidths['I'] = 3.0f;
|
||||
CharWidths['['] = 3.0f;
|
||||
CharWidths[']'] = 3.0f;
|
||||
CharWidths['`'] = 2.0f;
|
||||
CharWidths['f'] = 4.0f;
|
||||
CharWidths['i'] = 1.0f;
|
||||
CharWidths['k'] = 4.0f;
|
||||
CharWidths['l'] = 2.0f;
|
||||
CharWidths['t'] = 3.0f;
|
||||
CharWidths['{'] = 3.0f;
|
||||
CharWidths['|'] = 1.0f;
|
||||
CharWidths['}'] = 3.0f;
|
||||
CharWidths['~'] = 6.0f;
|
||||
}
|
||||
|
||||
public static float GetWidth(char c)
|
||||
{
|
||||
if (CharWidths.TryGetValue(c, out float width))
|
||||
return width;
|
||||
return 5.0f;
|
||||
}
|
||||
}
|
||||
@@ -77,7 +77,10 @@ public class GuiBatcher
|
||||
);
|
||||
|
||||
DrawQuad(currentX, y, size, size, uv, color);
|
||||
currentX += size * 0.8f; // Tighten horizontal spacing
|
||||
|
||||
float charWidthPixels = (CharWidth.GetWidth(c) + 1) / 8;
|
||||
float charWidthWorldUnits = size * charWidthPixels;
|
||||
currentX += charWidthWorldUnits;
|
||||
}
|
||||
}
|
||||
}
|
||||
21
UI/Label.cs
Normal file
21
UI/Label.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using OpenTK.Mathematics;
|
||||
|
||||
namespace Voxel.UI {
|
||||
public class Label
|
||||
{
|
||||
public string Text;
|
||||
public float X;
|
||||
public float Y;
|
||||
public float Size;
|
||||
public Vector4 Color;
|
||||
|
||||
public Label(string text, float x, float y, float size, Vector4 color)
|
||||
{
|
||||
Text = text;
|
||||
X = x;
|
||||
Y = y;
|
||||
Size = size;
|
||||
Color = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user