Skip to content

Commit

Permalink
Added Panel.IsVisible method to check if a child element is visible
Browse files Browse the repository at this point in the history
  • Loading branch information
Ellpeck committed Sep 19, 2024
1 parent 3340a50 commit 84bf3fa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions MLEM.Ui/Elements/Panel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,16 @@ public void ScrollToBottom() {
this.ScrollBar.CurrentValue = this.ScrollBar.MaxValue;
}

/// <summary>
/// Returns whether the given <paramref name="element"/> is currently visible within this panel if it scrolls overflow.
/// This method will return <see langword="true"/> on any elements whose <see cref="Element.Area"/> intersects this panel's render target area, regardless of whether it is a child or grandchild of this panel.
/// </summary>
/// <param name="element">The element to query for visibility.</param>
/// <returns>Whether the element is in this panel's visible area.</returns>
public bool IsVisible(Element element) {
return element.Area.Intersects(this.GetRenderTargetArea());
}

/// <inheritdoc />
protected override void InitStyle(UiStyle style) {
base.InitStyle(style);
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 84bf3fa

Please sign in to comment.