diff --git a/CHANGELOG.md b/CHANGELOG.md
index c98eb8a..e6b3401 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -27,6 +27,9 @@ Additions
- Added TextureExtensions.PremultipliedCopy for textures
### MLEM.Ui
+Additions
+- Added Panel.IsVisible method to check if a child element is visible
+
Improvements
- Construct images in UiParser.ParseImage on the main thread to support usage with KNI
- Create a premultiplied copy of UiParser images to support usage with KNI
diff --git a/MLEM.Ui/Elements/Panel.cs b/MLEM.Ui/Elements/Panel.cs
index c7adb25..d6dd1cf 100644
--- a/MLEM.Ui/Elements/Panel.cs
+++ b/MLEM.Ui/Elements/Panel.cs
@@ -255,6 +255,16 @@ public void ScrollToBottom() {
this.ScrollBar.CurrentValue = this.ScrollBar.MaxValue;
}
+ ///
+ /// Returns whether the given is currently visible within this panel if it scrolls overflow.
+ /// This method will return on any elements whose intersects this panel's render target area, regardless of whether it is a child or grandchild of this panel.
+ ///
+ /// The element to query for visibility.
+ /// Whether the element is in this panel's visible area.
+ public bool IsVisible(Element element) {
+ return element.Area.Intersects(this.GetRenderTargetArea());
+ }
+
///
protected override void InitStyle(UiStyle style) {
base.InitStyle(style);
@@ -369,13 +379,12 @@ private void SetScrollBarStyle() {
private void ForceUpdateRelevantChildren() {
this.relevantChildrenDirty = false;
this.relevantChildren.Clear();
- var visible = this.GetRenderTargetArea();
foreach (var child in this.SortedChildren) {
- if (child.Area.Intersects(visible)) {
+ if (this.IsVisible(child)) {
this.relevantChildren.Add(child);
} else {
foreach (var c in child.GetChildren(regardGrandchildren: true)) {
- if (c.Area.Intersects(visible)) {
+ if (this.IsVisible(c)) {
this.relevantChildren.Add(child);
break;
}