diff --git a/TestGame/TestGame.cs b/TestGame/TestGame.cs index 70a1f01..b55255b 100644 --- a/TestGame/TestGame.cs +++ b/TestGame/TestGame.cs @@ -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); diff --git a/Voile/Source/UI/Widgets/Label.cs b/Voile/Source/UI/Widgets/Label.cs index e8b55d2..8171dea 100644 --- a/Voile/Source/UI/Widgets/Label.cs +++ b/Voile/Source/UI/Widgets/Label.cs @@ -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()