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

Hover #898

Merged
merged 4 commits into from
Dec 9, 2024
Merged

Hover #898

merged 4 commits into from
Dec 9, 2024

Conversation

jaredkhan
Copy link
Collaborator

@jaredkhan jaredkhan commented Nov 13, 2024

Kinda relates to the remaining task on #155 i.e. fixes slow hovering but also adds a cursor:pointer during hover states.

Before:
https://github.com/user-attachments/assets/4dd9ca85-9338-455d-83a6-96de79a3bf70

After:
https://github.com/user-attachments/assets/b1974ae3-5d59-445d-a54c-081d93f40c14

Fixes #155

@@ -73,6 +76,27 @@ function refresh(root) {
}
}

function update_cursor() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This could feasibly live in the controller too, happy to go with whatever was more in line with the intention.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It does feel like it needs a better home, but I'm not sure there is one that isn't just needless indirection.

However, is there a reason to check for each global_button_action.action explicitly? Wouldn't this be equivalent?

canvas.style.cursor = tree_state.mouse_hold ? "move" : global_button_action.action ? "pointer" : "default"

I can't see anything in live_area_config.js that hasn't been listed.

If we do want a live area with a different cursor, which seems unlikely, then I think adding that to a tree_state.cursor inside the register_button_event() functions would be the way to go.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Haha, yeah I think to start with I'd tried 'zoom-in' cursor for 'tap2zoom' etc. but decided it looked silly so the switch statement is spare now. Have simplified and also added in a little check to make sure we don't steamroll over the mouse interactor's 'zoom-in'/'zoom-out' cursor setting.

if (tree_state.button_x != last_button_x || tree_state.button_y != last_button_y) {
last_button_x = tree_state.button_x;
last_button_y = tree_state.button_y;
return true;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In principle I expected that we'd be able to call get_shapes in here rather than returning true, since that's (as far as I understand) the thing that is actually updating global button action and then the next line would return true if necessary, which would be obviously better, but I couldn't get that to work at first glance, it just got stuck not rendering at all.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd assume there's something seeing the second call to get_shapes() with an identical tree and deciding rendering doesn't need to happen, but what that is I dunno.

Anyway, how about not bothering with last_button_x, and moving the get_shapes() call outside of if (need_refresh())?

if (need_refresh()) {
controller.projection.get_shapes(root, shapes);

This is more wasteful admittedly, as we're then running get_shapes() on every refresh rather than every refresh with a moving mouse cursor. But it's just get_shapes() not refresh_by_redraw(), and if there's no activity the whole refresh loop will fall idle & stop anyway.

We could make it 2 stage maybe, a need_shapes() & need_refresh(), but a quick profile shows that get_shapes() suggests that get_shapes isn't that expensive in comparison to the actual render (which is mostly slowed down by text measuring).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm. Trying that, I'm finding I get a fiar bit of garbage collection cruft and stuttering when running at 120Hz. I'm not being very scientific about it though.
I've pushed a commit to pull the get_shapes outside of the need_refresh only when the cursor has moved which seems to work okay. See what you think of that.

@jaredkhan jaredkhan marked this pull request as ready for review November 13, 2024 23:05
@jaredkhan
Copy link
Collaborator Author

Thanks very much for the comments Jamie, appreciate it.

@hyanwong
Copy link
Member

Thanks for looking at this @lentinj . I'm not familiar with this bit of the code, so am probably not best placed to test it out. Once you and Jared are happy with it, I'm fine to merge it, however. As with the other PRs, we can sync up the main branch with the extinct tree app first, then pull it to beta, and finally move it all over to the production branch, so we can test drive it a bit first.

@davidebbo
Copy link
Collaborator

I just tried this, and it seems like a nice improvement.

Copy link
Collaborator

@lentinj lentinj left a comment

Choose a reason for hiding this comment

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

@hyanwong this is all fine by me, given the shuffling you need to do for the extinct tree is it easier for me to let you merge it?

@hyanwong
Copy link
Member

hyanwong commented Dec 9, 2024

Happy for you to merge in general @lentinj , but I mighty as well do this one since I'm here.

@hyanwong hyanwong merged commit 35d92a7 into OneZoom:main Dec 9, 2024
1 check passed
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.

Touch pan/click disambiguation
4 participants