Do not recalculate layout if text wrapping is disabled

This commit is contained in:
2026-06-02 02:10:19 +02:00
parent 52279d6d60
commit ff3917cd2b
2 changed files with 14 additions and 4 deletions

View File

@@ -108,7 +108,7 @@ public class TestGame : Game
{ {
Size = new Rect(256.0f, 128.0f), Size = new Rect(256.0f, 128.0f),
ClipContents = false, ClipContents = false,
WrapText = true WrapText = false
}; };
// _rootFill.AddChild(_label); // _rootFill.AddChild(_label);

View File

@@ -57,7 +57,17 @@ public class Label : Widget
if (renderer is not RaylibRenderSystem rayRenderer) return; // TODO: Do NOT rely on RaylibRenderSystem check here. Very bad. if (renderer is not RaylibRenderSystem rayRenderer) return; // TODO: Do NOT rely on RaylibRenderSystem check here. Very bad.
renderer.SetTransform(GlobalPosition, Vector2.Zero); renderer.SetTransform(GlobalPosition, Vector2.Zero);
rayRenderer.DrawText(_font, _layout, style.TextColor ?? Color.Black);
var color = style.TextColor ?? Color.Black;
if (WrapText)
{
rayRenderer.DrawText(_font, _layout, color);
}
else
{
rayRenderer.DrawText(_font, _text, color);
}
} }
protected override void OnUpdate(LayoutContext layoutContext) protected override void OnUpdate(LayoutContext layoutContext)
@@ -67,8 +77,8 @@ public class Label : Widget
if (!_font.HasValue) if (!_font.HasValue)
return; return;
var width = WrapText ? Size.Width : float.MaxValue; if (!WrapText) return;
_layout = _font.Value.Layout(_text, Vector2.Zero, width); _layout = _font.Value.Layout(_text, Vector2.Zero, Size.Width);
} }
private void ResolveFont() private void ResolveFont()