-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Implement overlay
for Component
#1154
Conversation
Yes! I originally tried to implement another self-referential #[self_referencing]
struct Overlay<'a, 'b, Message, Renderer, Event> {
state: &'b mut Option<State<'a, Message, Renderer, Event>>,
#[borrows(mut state)]
#[covariant]
overlay: Option<overlay::Element<'this, Event, Renderer>>,
message: PhantomData<Message>,
} So we can implement fn overlay(
&mut self,
layout: Layout<'_>,
) -> Option<overlay::Element<'_, Message, Renderer>> {
let overlay = OverlayBuilder {
state: &mut self.state,
overlay_builder: |state| {
state
.as_mut()
.unwrap()
.with_element_mut(|element| element.overlay(layout))
},
message: PhantomData,
}
.build();
if overlay.borrow_overlay().is_some() {
Some(overlay::Element::new(layout.position(), Box::new(overlay)))
} else {
None
}
} But unfortunately, I don't think I did not think about relying on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed some of the duplication in 48b2264 by creating a couple of helper methods.
Hopefully I didn't break anything! Let me know what you think.
I really like the There is an edge case though where if I made an attempt to fix this by deferring the processing of the overlay's events by |
I'm not sure it will work properly. There is no guarantee that I think the best approach for now is to wrap the |
…the original element" This reverts commit aa09bd4.
That's a good point. It implicitly depends on the order in which methods are being called from
Yeah this is what I tried to do originally, but I was a bit concerned that returning an empty layout node from |
It shouldn't be a problem. The layout nodes of each widget are opaque to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this!
It's great to be able to make it work even when the current overlay implementation hinders composability!
Let's ship! 🎉
I saw the note about this method in
Component
so figure perhaps something like this has already been considered (or there are other plans foroverlay
), but here is something I came up with that seems to work in the limited tests I've performed.The idea is to use a second self-referential struct to cache the cached element's overlay content, then return an overlay element that accesses the cache for each operation similar to how it's being done for the original element.
There's a couple potential problems with doing this:
into_heads
to access the element. I don't know what the performance implications of this are.