Add a ClipContents property to UIElement

This commit is contained in:
2026-06-02 02:03:50 +02:00
parent e5f7e3aad4
commit 7b6fb71e1e
2 changed files with 14 additions and 2 deletions

View File

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

View File

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