PointerState `last_move_time` calculation
- Dominant language
- Rust
- Stars
- 30.6k
- Forks
- 2.1k
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 72
Description
After migrating to Bevy 0.16 we found that the tooltips generated by `on_hover_text` are not showing up anymore, and with some debugging it seems to stem from the way `PointerState::velocity` is calculated [here](https://github.com/emilk/egui/blob/main/crates/egui/src/input_state/mod.rs#L1139-L1146). As more and more plugins are added to our project, the number of entries into `PointerState::pos_history` seem to decrease, but still maintaining a minimum of 2 entries. As an example here's a printout of `pos_history` when a majority of our app's plugins are commented out:
```
History { min_len: 2, max_len: 1000, max_age: 0.1, total_count: 981, values: [
(7.826662598, [790.0 38.0]),
(7.843553347, [790.0 38.0]),
(7.859664615, [790.0 38.0]),
(7.876596344, [790.0 38.0]),
(7.893348302, [790.0 38.0]),
(7.909604081, [790.0 38.0]),
(7.926358579, [790.0 38.0])] }
```
and here's the printout of pos_history with all our plugins added:
```
History { min_len: 2, max_len: 1000, max_age: 0.1, total_count: 645, values: [(35.043602506, [1515.0 148.0]), (35.093911766, [1574.0 94.0])] }
```
However, this caused `velocity` and consequently `last_move_time` to be _not_ updated, since the requirement for these variables to be updated was for `pos_history.len() >= 3`. More often than not the tooltips would not appear as [should_show_hover_ui](https://github.com/emilk/egui/blob/0.31.1/crates/egui/src/response.rs#L553) returns false due to the widget being [clicked more recently than moved](https://github.com/emilk/egui/blob/0.31.1/crates/egui/src/response.rs#L696).
As an experiment I changed the requirement for minimum length of `pos_history` [here](https://github.com/emilk/egui/blob/main/crates/egui/src/input_state/mod.rs#L1143) from 3 to 2, and the tooltips started showing up again for our app.
I'd like to ask and clarify:
- Is there a reason `pos_history` should have a minimum of 3 entries, instead of 2?
- Are there any other factors to why PointerState might accumulate less entries when more non-egui related plugins are being added to the app? This might help us figure out what else might be causing our tooltips issue.
FYI we're using `egui v0.31.1`.
Contributor guide
Research direction
Start in crates/egui/src/input_state/mod.rs at PointerState::velocity and the last_move_time calculation, then inspect should_show_hover_ui in crates/egui/src/response.rs. Reproduce the tooltip behavior with different plugin sets and compare pos_history lengths with minimum thresholds of 3 and 2. Done means the cause of the missing tooltip behavior and the intended minimum history length are established, with the relevant behavior corrected if needed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100