From 84bf3fa0a3eaddd13de08413140594ed0b19ca7e Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 19 Sep 2024 20:21:06 +0200 Subject: [PATCH] Added Panel.IsVisible method to check if a child element is visible --- CHANGELOG.md | 3 +++ MLEM.Ui/Elements/Panel.cs | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) 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 @@ namespace MLEM.Ui.Elements { 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 @@ namespace MLEM.Ui.Elements { 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; }