-
Notifications
You must be signed in to change notification settings - Fork 25
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
Add cursor timer reset on input #20
Conversation
Yeah, I'd love to not involve any bespoke macros here. I actually think this might be relatively simple to accomplish by adding a |
This sounds a lot simpler, I'll revert my changes and try to implement it this way instead. |
This reverts commit e237536.
Just a heads up: I merged #21 in the mean time which might cause some confusion. |
I've attempted the suggested implementation. I don't love that |
I am a bit on the fence about
I think I have a slight preference for the third option. |
src/lib.rs
Outdated
@@ -150,6 +162,8 @@ fn keyboard( | |||
|
|||
for event in events.read() { | |||
if !event.state.is_pressed() { | |||
// Resume blinking the cursor when the user releases a key. | |||
cursor_timer.should_reset = false; |
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 think I'd rather take the hit of dealing with this in every match arm rather than potentially resetting the cursor when users press e.g. shift
or other keys that don't affect the cursor position.
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.
So something like this for handling when the key is up?
if !event.state.is_pressed() {
match event.key_code {
KeyCode::ArrowLeft
| KeyCode::ArrowRight
| KeyCode::Backspace
| KeyCode::Delete
| KeyCode::Space => {
cursor_timer.should_reset = false;
}
_ => {}
}
if let Key::Character(_) = event.logical_key {
cursor_timer.should_reset = false;
}
continue;
};
Then having the following in each match arm (besides KeyCode::Enter
):
cursor_timer.should_reset = true;
continue;
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.
Yes on the second part, but I think we can just reset cursor_timer.should_reset
to false right after doing the reset in the other system.
The only issue I have with the third option is that the cursor could be stuck in an invisible state if the user types whilst it is invisible. If you desire this behavior then I'd be happy to just do that. If not, any ideas on how this could be solved? |
Definitely don't want that behavior. I think I just made a mistake in the diff above though. if !finished && !cursor_timer.should_reset { |
This makes a lot more sense, thanks! As an alternative, this solution also works and avoids the unnecessary query to InnerText, but I'll just commit whichever you prefer. // ...
if cursor_timer.is_changed() && cursor_timer.should_reset {
cursor_timer.timer.reset();
cursor_timer.should_reset = false;
if let Some(mut text) = inner_text.get_mut(entity) {
text.sections[1].style.color = style.0.color;
}
continue;
}
if !cursor_timer.timer.tick(time.delta()).just_finished() {
continue;
} |
Your solution looks nice. |
Perfect, I'll commit these changes now. |
Thanks for working with me through that! Can't promise I won't change my mind and refactor into a separate system at some point, but this looks good to me. |
Resets the cursor's timer on inputs (other than
KeyCode::Enter
), solving #10I'm not sure if this solution is ideal and aligns with the project's goals. Please let me know what you think.