Compare commits
3 Commits
e5f7e3aad4
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| ff3917cd2b | |||
| 52279d6d60 | |||
| 7b6fb71e1e |
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user