Compare commits

..

2 Commits

Author SHA1 Message Date
52279d6d60 Add a WrapText property to Label 2026-06-02 02:08:04 +02:00
7b6fb71e1e Add a ClipContents property to UIElement 2026-06-02 02:03:50 +02:00
3 changed files with 20 additions and 3 deletions

View File

@@ -107,6 +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,
WrapText = true
};
// _rootFill.AddChild(_label);

View File

@@ -65,6 +65,8 @@ public abstract class UIElement : IElement, IRenderableElement, IResizeableEleme
public abstract Rect MinimumSize { get; }
public bool Dirty => _dirty != DirtyFlags.None || _pendingDirty != DirtyFlags.None;
public bool ClipContents { get; set; } = true;
public bool TryGetStyle(StyleSheet styleSheet, [NotNullWhen(true)] out Style? style)
{
return styleSheet.TryGet(StyleName, out style);
@@ -109,9 +111,18 @@ public abstract class UIElement : IElement, IRenderableElement, IResizeableEleme
public void Render(RenderSystem renderer, Style style)
{
RenderStyleBox(renderer, style);
renderer.BeginScissored(GlobalPosition, LayoutSize);
if (ClipContents)
{
renderer.BeginScissored(GlobalPosition, LayoutSize);
}
OnRender(renderer, style);
renderer.EndScissored();
if (ClipContents)
{
renderer.EndScissored();
}
}
public void DrawSize(RenderSystem renderer)

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()