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

Make text cursor always appear on click #5420

Merged
merged 6 commits into from
Dec 4, 2024

Conversation

juancampa
Copy link
Contributor

@juancampa juancampa commented Nov 30, 2024

  • I have followed the instructions in the PR template

Problem

When clicking on a TextEdit sometimes the cursor doesn't appear immediately which makes it feel like the click was not registered for a second. This is because the start time for the blinking animation is only reset on keyboard input, but not on mouse interaction.

It's hard to tell on the video but the cursor doesn't show immediately after clicking if the blink timer happens to be off.

Screenshot.2024-11-30.at.12.58.56.mp4

Solution

Reset the click timer every time a TextEdit is clicked.

Additionally, the cursor is now correctly painted on the pixel boundary. IMO we should default to 1px cursor (instead of 2px) but that's not included in this PR. Happy to make that change too.

Screenshot.2024-11-30.at.12.58.24.mp4

Copy link

Preview available at https://egui-pr-preview.github.io/pr/5420-show-cursor-on-click
Note that it might take a couple seconds for the update to show up after the preview_build workflow has completed.

@juancampa juancampa marked this pull request as ready for review November 30, 2024 18:06
Comment on lines +99 to +111
let (top, bottom) = if (stroke.width as usize) % 2 == 0 {
(
painter.round_pos_to_pixels(cursor_rect.center_top()),
painter.round_pos_to_pixels(cursor_rect.center_bottom()),
)
} else {
(
painter.round_pos_to_pixel_center(cursor_rect.center_top()),
painter.round_pos_to_pixel_center(cursor_rect.center_bottom()),
)
};
Copy link
Contributor Author

@juancampa juancampa Nov 30, 2024

Choose a reason for hiding this comment

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

I would think it's safe to assume that everyone will be using either 1px or 2px cursor thickness. This should make it pixel-perfect for all whole-number thickness values.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Will this work when the scale is 150%?

Also it'd be nice to have a screenshot test that shows the cursor, maybe you can add one?

Copy link
Owner

@emilk emilk left a comment

Choose a reason for hiding this comment

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

Makes sense - thanks!

Comment on lines +99 to +111
let (top, bottom) = if (stroke.width as usize) % 2 == 0 {
(
painter.round_pos_to_pixels(cursor_rect.center_top()),
painter.round_pos_to_pixels(cursor_rect.center_bottom()),
)
} else {
(
painter.round_pos_to_pixel_center(cursor_rect.center_top()),
painter.round_pos_to_pixel_center(cursor_rect.center_bottom()),
)
};
Copy link
Owner

Choose a reason for hiding this comment

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

This could use a comment explaining what is going on, and ideally with a link to #5164 so we can remember to update this code if we move the rounding to epaint

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment added!

@juancampa juancampa force-pushed the show-cursor-on-click branch from 679ee93 to 1c4f222 Compare December 3, 2024 01:39
@juancampa
Copy link
Contributor Author

I just noticed that another one of my PRs (#3660) got merged earlier today and was missing some backticks which was causing check.sh to fail. I just fixed that as well so this should be good to go now.

@emilk emilk added bug Something is broken egui labels Dec 3, 2024
@emilk
Copy link
Owner

emilk commented Dec 3, 2024

please merge in master to fix CI

@juancampa
Copy link
Contributor Author

@emilk merged

@emilk emilk merged commit cd0f585 into emilk:master Dec 4, 2024
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken egui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants