Handle text overflow nicely
This commit is contained in:
@@ -26,6 +26,7 @@ namespace OpenRA.Widgets
|
|||||||
class TextFieldWidget : Widget
|
class TextFieldWidget : Widget
|
||||||
{
|
{
|
||||||
string TextBuffer = "zomg text";
|
string TextBuffer = "zomg text";
|
||||||
|
public int VisualHeight = 1;
|
||||||
|
|
||||||
public TextFieldWidget()
|
public TextFieldWidget()
|
||||||
: base()
|
: base()
|
||||||
@@ -99,16 +100,34 @@ namespace OpenRA.Widgets
|
|||||||
|
|
||||||
public override void DrawInner(World world)
|
public override void DrawInner(World world)
|
||||||
{
|
{
|
||||||
|
int margin = 5;
|
||||||
|
var font = Game.chrome.renderer.BoldFont;
|
||||||
|
|
||||||
|
|
||||||
|
var text = TextBuffer + ((showCursor && Chrome.selectedWidget == this) ? "|" : "");
|
||||||
|
var textSize = font.Measure(TextBuffer);
|
||||||
var pos = DrawPosition();
|
var pos = DrawPosition();
|
||||||
int margin = 10;
|
|
||||||
WidgetUtils.DrawPanel("dialog3",
|
WidgetUtils.DrawPanel("dialog3",
|
||||||
new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height ) );
|
new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height ) );
|
||||||
|
|
||||||
var text = TextBuffer + ((showCursor && Chrome.selectedWidget == this) ? "|" : "");
|
// Inset text by the margin and center vertically
|
||||||
Game.chrome.renderer.BoldFont.DrawText(text,
|
var textPos = pos + new int2( margin, (Bounds.Height - textSize.Y)/2 - VisualHeight);
|
||||||
new int2( pos.X + margin, pos.Y + Bounds.Height / 2)
|
|
||||||
- new int2(0, Game.chrome.renderer.BoldFont.Measure(text).Y / 2),
|
// Right align and scissor when the text overflows
|
||||||
Color.White);
|
if (textSize.X > Bounds.Width - 2*margin)
|
||||||
|
{
|
||||||
|
textPos += new int2(Bounds.Width - 2*margin - textSize.X,0);
|
||||||
|
Game.chrome.renderer.Device.EnableScissor(pos.X + margin, pos.Y, Bounds.Width - 2*margin, Bounds.Bottom);
|
||||||
|
}
|
||||||
|
|
||||||
|
font.DrawText(text, textPos, Color.White);
|
||||||
|
|
||||||
|
if (textSize.X > Bounds.Width - 2*margin)
|
||||||
|
{
|
||||||
|
Game.chrome.renderer.RgbaSpriteRenderer.Flush();
|
||||||
|
Game.chrome.renderer.Device.DisableScissor();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Widget Clone()
|
public override Widget Clone()
|
||||||
|
|||||||
Reference in New Issue
Block a user