1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-25 05:58:35 +01:00

Added Panel.IsVisible method to check if a child element is visible

This commit is contained in:
Ell 2024-09-19 20:21:06 +02:00
parent 3340a5024b
commit 84bf3fa0a3
2 changed files with 15 additions and 3 deletions

View file

@ -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

View file

@ -255,6 +255,16 @@ namespace MLEM.Ui.Elements {
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);
@ -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;
}