Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new descendants api as well as deeper element queries to ElementHandle #5433

Merged
merged 5 commits into from
Jul 15, 2024

Conversation

tronical
Copy link
Member

No description provided.

@tronical tronical requested a review from ogoffart June 19, 2024 12:51
Copy link
Member

@ogoffart ogoffart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should visit_element be removed. It is a bit redundent since you can do HasElementHandle::root_element(component).visit_descendants

(the only difference is that it visits the root)

@@ -312,21 +313,30 @@ impl ItemRc {
r.upgrade()?.parent_item()
}

// FIXME: This should be nicer/done elsewhere?
/// Returns true if this item is visible from the root of the item tree. Note that this will return
/// false for `Clip` elements, even if they are "visible".
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it? All Clip elements? Why is that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm missing something (I tried to cover that also in the test I added in search_api.rs), but the old code did this:

    pub fn is_visible(&self) -> bool {
        let item = self.borrow();
        let is_clipping = crate::item_rendering::is_clipping_item(item);
        let geometry = self.geometry();
        if is_clipping && (geometry.width() <= 0.01 as _ || geometry.height() <= 0.01 as _) {
            return false;
        }
        if let Some(parent) = self.parent_item() {
            parent.is_visible()
        } else {
            true
        }
    }

That suggests to me that is_clipping_item() returns true for Clip elements that are enabled for clipping (clip true) and the visible pass gives them the null width/height. So I think that'll return false.

The new code should return an empty clip rectangle from the call to absolute_clip_rect_and_geometry because of this:

      if crate::item_rendering::is_clipping_item(item) {
            clip = geometry.intersection(&clip).unwrap_or_default();
        }

And then the intersection of itself should be empty.

Should I add a direct unit test in here perhaps?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test for that would be nice.

So if you have a

outer := Rectangle { 
   clip: true;  
   inner := Rectangle { x: parent.width; background: blue; } 
}

Then the Clip item for that outer rectangle would still be considered visible.
But the inner Rectangle would not;

I think either behavior is fine. It's just that the documention is a bit strange.
I think what you mean is that if an item has a size of 0x0 it will not be considered visible (because the intersection is empty)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then the Clip item for that outer rectangle would still be considered visible.
But the inner Rectangle would not;

The Clip item would not be considered visible (the function returns false). AFAICS the old code did that as per this condition:

        if is_clipping && (geometry.width() <= 0.01 as _ || geometry.height() <= 0.01 as _) {  
            return false;  
        }  

and the new code should do the same by intersection.

internal/backends/testing/search_api.rs Outdated Show resolved Hide resolved
@tronical
Copy link
Member Author

Should visit_element be removed. It is a bit redundent since you can do HasElementHandle::root_element(component).visit_descendants

(the only difference is that it visits the root)

Yes, I'm in favor of that - if you're okay with the rest of this API. I'd make that a separate change though.

@tronical tronical marked this pull request as draft July 10, 2024 15:19
@tronical
Copy link
Member Author

Going back into draft mode. I'm removing the children bits for now and want to proceed with the matching API that includes descendants but also the other criteria.

@tronical tronical changed the title Add a new children/descendants api as well as deeper element queries to ElementHandle Add a new descendants api as well as deeper element queries to ElementHandle Jul 11, 2024
@tronical tronical marked this pull request as ready for review July 11, 2024 09:11

/// Visit the children of this element and call the visitor to each of them, until the visitor returns [`ControlFlow::Break`].
/// When the visitor breaks, the function returns the value. If it doesn't break, the function returns None.
fn visit_descendants_internal<R>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming: We often use the _impl prefix for this kind of helper function, instead of _internal

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you meant suffix. Changed :)

@@ -312,21 +313,30 @@ impl ItemRc {
r.upgrade()?.parent_item()
}

// FIXME: This should be nicer/done elsewhere?
/// Returns true if this item is visible from the root of the item tree. Note that this will return
/// false for `Clip` elements, even if they are "visible".
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test for that would be nice.

So if you have a

outer := Rectangle { 
   clip: true;  
   inner := Rectangle { x: parent.width; background: blue; } 
}

Then the Clip item for that outer rectangle would still be considered visible.
But the inner Rectangle would not;

I think either behavior is fine. It's just that the documention is a bit strange.
I think what you mean is that if an item has a size of 0x0 it will not be considered visible (because the intersection is empty)

internal/compiler/passes.rs Show resolved Hide resolved
assert_eq!(root.match_descendants().match_inherits("Base").find_all().len(), 1);
}

/*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this commented out?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a test that assumes the availability of children traversal, which I removed again. I can remove the commented out test, but I want to bring it back when adding children support.

@tronical tronical merged commit 52f8249 into master Jul 15, 2024
6 checks passed
@tronical tronical deleted the simon/elementhandle-search branch July 15, 2024 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants