Add a WrapText property to Label

This commit is contained in:
2026-06-02 02:08:04 +02:00
parent 7b6fb71e1e
commit 52279d6d60
2 changed files with 7 additions and 2 deletions

View File

@@ -107,7 +107,8 @@ public class TestGame : Game
_label = new Label("What the heck??? Word wrapping!!! That's crazy... Noooo wayyy Before GTA 6 too!!!\nnewline :)", _defaultFontSet)
{
Size = new Rect(256.0f, 128.0f),
ClipContents = false
ClipContents = false,
WrapText = true
};
// _rootFill.AddChild(_label);

View File

@@ -9,6 +9,8 @@ public class Label : Widget
{
public override Rect MinimumSize => Rect.Zero;
public bool WrapText { get; set; } = false;
public string Text
{
get => _text; set
@@ -54,6 +56,7 @@ public class Label : Widget
return;
if (renderer is not RaylibRenderSystem rayRenderer) return; // TODO: Do NOT rely on RaylibRenderSystem check here. Very bad.
renderer.SetTransform(GlobalPosition, Vector2.Zero);
rayRenderer.DrawText(_font, _layout, style.TextColor ?? Color.Black);
}
@@ -64,7 +67,8 @@ public class Label : Widget
if (!_font.HasValue)
return;
_layout = _font.Value.Layout(_text, GlobalPosition, Size.Width);
var width = WrapText ? Size.Width : float.MaxValue;
_layout = _font.Value.Layout(_text, Vector2.Zero, width);
}
private void ResolveFont()