-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Conversation
Preview available at https://egui-pr-preview.github.io/pr/5420-show-cursor-on-click |
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()), | ||
) | ||
}; |
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.
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.
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.
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?
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.
Makes sense - thanks!
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()), | ||
) | ||
}; |
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.
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
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.
Comment added!
679ee93
to
1c4f222
Compare
I just noticed that another one of my PRs (#3660) got merged earlier today and was missing some backticks which was causing |
please merge in |
@emilk merged |
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