Compare commits

...

4 Commits

Author SHA1 Message Date
ff3917cd2b Do not recalculate layout if text wrapping is disabled 2026-06-02 02:10:19 +02:00
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
e5f7e3aad4 Update TODO 2026-06-02 01:57:15 +02:00
4 changed files with 32 additions and 5 deletions

View File

@@ -94,7 +94,7 @@
- Input propagation
- ~~Pass input to widgets.~~
- Add element focus logic, make them focusable with action inputs.
- Basic input elements (~~button~~, text field, toggle).
- Basic input elements (~~button~~, ~~text field~~, toggle).
- Styling
- ~~Style sheet~~
- ~~Add style settings for UI panels (for buttons, labels, etc.).~~

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 = false
};
// _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,7 +56,18 @@ public class Label : Widget
return;
if (renderer is not RaylibRenderSystem rayRenderer) return; // TODO: Do NOT rely on RaylibRenderSystem check here. Very bad.
rayRenderer.DrawText(_font, _layout, style.TextColor ?? Color.Black);
renderer.SetTransform(GlobalPosition, Vector2.Zero);
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)
@@ -64,7 +77,8 @@ public class Label : Widget
if (!_font.HasValue)
return;
_layout = _font.Value.Layout(_text, GlobalPosition, Size.Width);
if (!WrapText) return;
_layout = _font.Value.Layout(_text, Vector2.Zero, Size.Width);
}
private void ResolveFont()