-
Notifications
You must be signed in to change notification settings - Fork 567
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
Associate timers with widget ids #831
Conversation
2) Aggressive traversal is achieved by storing a map of TimerToken -> WidgetId in each window. 3) On Timer event, we check the map from step 2 and recurse only if child MIGHT contain the WidgetId.
I haven't looked at the code closely yet, but can't we do this association without I'll have more time to look into this tomorrow hopefully, but just wanted to get that thought out there. |
druid/src/contexts.rs
Outdated
timer_token | ||
} | ||
|
||
pub fn remove_timer(&mut self, timer_token: &TimerToken) { |
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.
After widgets are done processing timer events, should we all ask them to remove map entry?
This is not used anywhere in examples.
I think framework needs to remove it rather than forcing widgets to remove it themselves.
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.
After merging up, Im clearing the map of BaseState. So remove is not needed when event is handled.
That was my first attempt.
The objective of this was to do aggressive traversing of |
Yeah druid-shell shouldn't be modified, but we could probably store the As for agressive traversing, you can still do that if you just know the |
Whatever you said is what this PR does. |
…ot needed when event is handled.
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.
It seems that the HashMap
in window is nevered cleaned up. We should remove the TimerToken
entry from the window HashMap
at the end of the window's event generation function.
You are right. I cleaned up |
To remove timers from window, I check Is that acceptable? |
I think it's fine to set if *widget_id != child_ctx.base_state.id {
recurse = child_ctx.base_state.children.may_contain(widget_id);
} else {
child_ctx.is_handled = true;
} That can be useful for preventing further propagation, however this is not how the removal should happen in the window, because the widget who requested the timer may not exist anymore. I think the window |
Sounds good. With that in mind, this should work at the end of
|
I spoke too early. With the change I suggested, the |
|
…rToken � Conflicts: � druid/src/core.rs � druid/src/window.rs
You are absolutely right. Looks like tokens are reused only on Windows. Linux/Mac seem to work as token aren't reused there. |
Okay this looks functional now. There is some more work opportunity here though. Instead of the window sending Let me know if this is something you wish to continue working on. It's completely fine if you want to just get this merged and be done for now. 👍 |
I prefer doing this the right way rather than just merging and creating a technical debt. Besides hopefully I'll learn something more. |
sorry i've been distracted, will try and take a look at this shortly! |
This approach is pretty good, but It isn't quite what i had in mind; as mentioned by @xStrom, I think it would be even cleaner if we used an internal |
I agree. Im working on the approach you and @xStrom are talking about. But isn't
already working? I ask because that was THE goal I was working towards and I thought I implemented it. 🤔 |
not if a widget has children; we will recurse into a container widget with the |
…rToken � Conflicts: � druid/src/core.rs � druid/src/window.rs
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.
Looking better! Just some minor changes needed.
@@ -147,6 +147,7 @@ pub enum InternalEvent { | |||
MouseLeave, | |||
/// A command still in the process of being dispatched. | |||
TargetedCommand(Target, Command), | |||
RouteTimer(TimerToken, WidgetId), |
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.
Add a comment here describing this variant. Something simple like Used to route timer events. would work.
druid/src/core.rs
Outdated
recurse = child_ctx.base_state.request_timer; | ||
Event::Timer(*id) | ||
} | ||
Event::Timer(token) => Event::Timer(*token), |
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.
Add recurse = false;
here because if we get this then we're already a descendant of the targeted widget.
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.
Good catch. Missed this important change. :(
Thanks.
druid/src/window.rs
Outdated
//In some platforms, timer tokens are reused. So it is necessary to remove token from | ||
//window's timer before adding base state's timers to it. |
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.
In On some platforms, timer tokens are reused. So it is necessary to remove the token from the window's timer map before adding base state's timers new tokens to it.
druid/src/window.rs
Outdated
self.timers.remove(&token); | ||
} | ||
|
||
//If at least one widget requested timer, collect those timers from widgets and add to window's timers map. |
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.
If at least one widget requested a timer, collect those timers from widgets and add all the requested timers to window's timers map.
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.
Looks good now. Thanks for doing this!
Closes #494