-
Notifications
You must be signed in to change notification settings - Fork 569
ZStack fix #2291
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
ZStack fix #2291
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| use crate::{ | ||
| BoxConstraints, Data, Env, Event, EventCtx, LayoutCtx, LifeCycle, LifeCycleCtx, PaintCtx, | ||
| Point, Rect, Size, UnitPoint, UpdateCtx, Vec2, Widget, WidgetExt, WidgetPod, | ||
| BoxConstraints, Data, Env, Event, EventCtx, InternalEvent, LayoutCtx, LifeCycle, LifeCycleCtx, | ||
| PaintCtx, Point, Rect, Size, UnitPoint, UpdateCtx, Vec2, Widget, WidgetExt, WidgetPod, | ||
| }; | ||
|
|
||
| /// A container that stacks its children on top of each other. | ||
|
|
@@ -94,17 +94,22 @@ impl<T: Data> ZStack<T> { | |
|
|
||
| impl<T: Data> Widget<T> for ZStack<T> { | ||
| fn event(&mut self, ctx: &mut EventCtx, event: &Event, data: &mut T, env: &Env) { | ||
| let is_pointer_event = matches!( | ||
| event, | ||
| Event::MouseDown(_) | Event::MouseMove(_) | Event::MouseUp(_) | Event::Wheel(_) | ||
| ); | ||
|
|
||
| let mut previous_hot = false; | ||
| for layer in self.layers.iter_mut() { | ||
| layer.child.event(ctx, event, data, env); | ||
|
|
||
| if is_pointer_event && layer.child.is_hot() { | ||
| ctx.set_handled(); | ||
| if event.is_pointer_event() && previous_hot { | ||
| if layer.child.is_active() { | ||
| ctx.set_handled(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we still need this
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean replace it with the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a good chance I'm missing something, but I was thinking just remove it. Does that work? I'm expecting that this child is active but not hot, and it will know how to correctly handle mouse events based on that, even if they aren't marked as handled.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The child only knows that it is not hot because it received a follow up event (Mouse event while active is set) which was marked as ´handled´. In any case we either need
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't the child do
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is about the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ups my mistake. I meant
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I aggree. The only thing which is still brocken is scrolling while pressing a mousebutton. That is not the most impprtant usecase. I think we can merge this PR as it is. |
||
| layer.child.event(ctx, event, data, env); | ||
| } else { | ||
| layer | ||
| .child | ||
| .event(ctx, &Event::Internal(InternalEvent::MouseLeave), data, env); | ||
| } | ||
| } else { | ||
| layer.child.event(ctx, event, data, env); | ||
| } | ||
|
|
||
| previous_hot |= layer.child.is_hot(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.