Added TextAlignment support in Text.
This commit is contained in:
@@ -16,6 +16,7 @@ namespace Progrart.Core.Graphics
|
|||||||
bool IsStroke;
|
bool IsStroke;
|
||||||
SKShader? shader = null;
|
SKShader? shader = null;
|
||||||
string? fontFamily = null;
|
string? fontFamily = null;
|
||||||
|
string alignment = "center";
|
||||||
public override void SetupProperties(Engine engine)
|
public override void SetupProperties(Engine engine)
|
||||||
{
|
{
|
||||||
base.SetupProperties(engine);
|
base.SetupProperties(engine);
|
||||||
@@ -30,6 +31,7 @@ namespace Progrart.Core.Graphics
|
|||||||
__object.Set("StrokeWidth", 1);
|
__object.Set("StrokeWidth", 1);
|
||||||
__object.Set("Size", 1);
|
__object.Set("Size", 1);
|
||||||
__object.Set("Text", "");
|
__object.Set("Text", "");
|
||||||
|
__object.Set("Alignment", "center");
|
||||||
__object.Set("IsStroke", true);
|
__object.Set("IsStroke", true);
|
||||||
__object.Set("Color", ProgrartFunctions.color(engine, 1, 1, 1, 1));
|
__object.Set("Color", ProgrartFunctions.color(engine, 1, 1, 1, 1));
|
||||||
|
|
||||||
@@ -42,6 +44,7 @@ namespace Progrart.Core.Graphics
|
|||||||
{
|
{
|
||||||
StrokeWidth = (float)__object.Get("StrokeWidth").AsNumber();
|
StrokeWidth = (float)__object.Get("StrokeWidth").AsNumber();
|
||||||
str = __object.Get("Text").AsString();
|
str = __object.Get("Text").AsString();
|
||||||
|
alignment = __object.Get("Alignment").AsString();
|
||||||
Size = (float)__object.Get("Size").AsNumber();
|
Size = (float)__object.Get("Size").AsNumber();
|
||||||
IsStroke = (bool)__object.Get("IsStroke").AsBoolean();
|
IsStroke = (bool)__object.Get("IsStroke").AsBoolean();
|
||||||
{
|
{
|
||||||
@@ -69,6 +72,12 @@ namespace Progrart.Core.Graphics
|
|||||||
LoadProperties();
|
LoadProperties();
|
||||||
SKPoint pos = context.TranslatePoint(Position);
|
SKPoint pos = context.TranslatePoint(Position);
|
||||||
float Size = context.TranslateSize(this.Size);
|
float Size = context.TranslateSize(this.Size);
|
||||||
|
SKTextAlign align = alignment.ToLower() switch
|
||||||
|
{
|
||||||
|
"left" => SKTextAlign.Left,
|
||||||
|
"right" => SKTextAlign.Right,
|
||||||
|
_ => SKTextAlign.Center,
|
||||||
|
};
|
||||||
if (fontFamily is not null)
|
if (fontFamily is not null)
|
||||||
{
|
{
|
||||||
var face = context.GetFont(fontFamily);
|
var face = context.GetFont(fontFamily);
|
||||||
@@ -76,7 +85,7 @@ namespace Progrart.Core.Graphics
|
|||||||
{
|
{
|
||||||
|
|
||||||
context.canvas.DrawText(str,
|
context.canvas.DrawText(str,
|
||||||
pos.X, pos.Y, SKTextAlign.Center, new SKFont(face, Size) { },
|
pos.X, pos.Y, align, new SKFont(face, Size) { },
|
||||||
new SKPaint()
|
new SKPaint()
|
||||||
{
|
{
|
||||||
ColorF = Color,
|
ColorF = Color,
|
||||||
@@ -90,7 +99,7 @@ namespace Progrart.Core.Graphics
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
context.canvas.DrawText(str,
|
context.canvas.DrawText(str,
|
||||||
pos.X, pos.Y, SKTextAlign.Center, new SKFont(SKTypeface.Default, Size) { },
|
pos.X, pos.Y, align, new SKFont(SKTypeface.Default, Size) { },
|
||||||
new SKPaint()
|
new SKPaint()
|
||||||
{
|
{
|
||||||
ColorF = Color,
|
ColorF = Color,
|
||||||
|
|||||||
@@ -49,6 +49,9 @@ namespace Progrart.Core.JSExecution
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
engine.Engine.SetValue("Left", "left");
|
||||||
|
engine.Engine.SetValue("Center", "center");
|
||||||
|
engine.Engine.SetValue("Right", "right");
|
||||||
engine.Engine.SetValue("visual_root", visual_root);
|
engine.Engine.SetValue("visual_root", visual_root);
|
||||||
engine.Engine.SetValue("line", line);
|
engine.Engine.SetValue("line", line);
|
||||||
engine.Engine.SetValue("rectangle", rectangle);
|
engine.Engine.SetValue("rectangle", rectangle);
|
||||||
|
|||||||
Reference in New Issue
Block a user