mirror of
https://github.com/Stone-Red-Code/RemSox.git
synced 2026-09-04 00:56:19 +02:00
Add MaxWidth property for text rendering in UI controls and fix maxWidth parameter in canvas extension methods
This commit is contained in:
@@ -304,10 +304,11 @@ public sealed class CanvasRenderSource : IRenderSource
|
|||||||
Color color = Get(cmd.Properties, "Color", Color.White);
|
Color color = Get(cmd.Properties, "Color", Color.White);
|
||||||
string content = Get(cmd.Properties, "Content", string.Empty);
|
string content = Get(cmd.Properties, "Content", string.Empty);
|
||||||
int fontSize = Get(cmd.Properties, "FontSize", 12);
|
int fontSize = Get(cmd.Properties, "FontSize", 12);
|
||||||
|
int maxWidth = Get(cmd.Properties, "MaxWidth", int.MaxValue);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(content))
|
if (!string.IsNullOrEmpty(content))
|
||||||
{
|
{
|
||||||
canvas.DrawStringHeight(content, PCScreenFont.DefaultFont, color, cmd.Position.X, cmd.Position.Y, fontSize);
|
canvas.DrawStringHeight(content, PCScreenFont.DefaultFont, color, cmd.Position.X, cmd.Position.Y, fontSize, maxWidth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ public class RenderCommand
|
|||||||
byte[] utf8 = Encoding.UTF8.GetBytes(text);
|
byte[] utf8 = Encoding.UTF8.GetBytes(text);
|
||||||
WriteVarint(s, utf8.Length);
|
WriteVarint(s, utf8.Length);
|
||||||
s.Write(utf8, 0, utf8.Length);
|
s.Write(utf8, 0, utf8.Length);
|
||||||
|
WriteVarint(s, GetProp("MaxWidth", int.MaxValue));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RenderCommandType.DrawLine:
|
case RenderCommandType.DrawLine:
|
||||||
@@ -142,6 +143,7 @@ public class RenderCommand
|
|||||||
int textLen = ReadVarint(data, ref offset);
|
int textLen = ReadVarint(data, ref offset);
|
||||||
props["Content"] = Encoding.UTF8.GetString(data, offset, textLen);
|
props["Content"] = Encoding.UTF8.GetString(data, offset, textLen);
|
||||||
offset += textLen;
|
offset += textLen;
|
||||||
|
props["MaxWidth"] = ReadVarint(data, ref offset);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RenderCommandType.DrawLine:
|
case RenderCommandType.DrawLine:
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ public class Button() : Control("Button")
|
|||||||
["Color"] = TextColor,
|
["Color"] = TextColor,
|
||||||
["Content"] = Text,
|
["Content"] = Text,
|
||||||
["FontSize"] = Size.Height - 8,
|
["FontSize"] = Size.Height - 8,
|
||||||
|
["MaxWidth"] = Size.Width,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ public class CheckBox() : Control("CheckBox")
|
|||||||
["Color"] = TextColor,
|
["Color"] = TextColor,
|
||||||
["Content"] = Text,
|
["Content"] = Text,
|
||||||
["FontSize"] = boxSize,
|
["FontSize"] = boxSize,
|
||||||
|
["MaxWidth"] = Size.Width - boxSize - 5,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ public class RadioButton() : Control("RadioButton")
|
|||||||
["Color"] = TextColor,
|
["Color"] = TextColor,
|
||||||
["Content"] = Text,
|
["Content"] = Text,
|
||||||
["FontSize"] = Size.Height,
|
["FontSize"] = Size.Height,
|
||||||
|
["MaxWidth"] = Size.Width - Size.Height - 5,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,10 +70,11 @@ public static class CanvasExtensions
|
|||||||
byte height = font.Height;
|
byte height = font.Height;
|
||||||
|
|
||||||
int targetWidth = width * targetHeight / height;
|
int targetWidth = width * targetHeight / height;
|
||||||
|
int endX = maxWidth == int.MaxValue ? int.MaxValue : x + maxWidth;
|
||||||
|
|
||||||
for (int i = 0; i < str.Length; i++)
|
for (int i = 0; i < str.Length; i++)
|
||||||
{
|
{
|
||||||
if (x + targetWidth > maxWidth)
|
if (x + targetWidth > endX)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user