Add ContainsPoint helper method to Widget.

This commit is contained in:
2025-06-20 20:21:45 +02:00
parent 5b29ea012e
commit 84efb2a3d1

View File

@@ -61,5 +61,18 @@ public abstract class Widget : IElement, IRenderableElement, IInputElement, IRes
renderer.DrawRectangleOutline(new Vector2(Size.Width, Size.Height), Color.Red, 2.0f); renderer.DrawRectangleOutline(new Vector2(Size.Width, Size.Height), Color.Red, 2.0f);
} }
/// <summary>
/// Determines if this <see cref="Widget"/> contains a point within its confines.
/// </summary>
/// <param name="pointPosition">A global position of the point.</param>
/// <returns>True if the point is inside the widget; otherwise, false.</returns>
public bool ContainsPoint(Vector2 pointPosition)
{
return pointPosition.X >= Position.X &&
pointPosition.Y >= Position.Y &&
pointPosition.X <= Position.X + Size.Width &&
pointPosition.Y <= Position.Y + Size.Height;
}
private bool _isDirty = true; private bool _isDirty = true;
} }