-
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
text cursor blink in TextEdit #4121
Conversation
It's changes were completed. |
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 is feeling much better now!
crates/egui/src/style.rs
Outdated
/// show where the text cursor would be if you clicked | ||
pub text_cursor_preview: bool, | ||
|
||
/// set the text cursor to blink | ||
pub text_cursor_blink: bool, | ||
|
||
/// set the text cursor on duration | ||
pub text_cursor_on_duration: f64, | ||
|
||
/// set the text cursor off duration | ||
pub text_cursor_off_duration: f64, |
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 it's time to group all these in a struct TextCursorStyle
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.
…but I can do that in a later PR
crates/egui/src/style.rs
Outdated
@@ -1846,6 +1862,15 @@ impl Visuals { | |||
ui.checkbox(text_cursor_preview, "Preview text cursor on hover"); | |||
ui.add(Slider::new(clip_rect_margin, 0.0..=20.0).text("clip_rect_margin")); | |||
|
|||
ui.add(Slider::new(resize_corner_size, 0.0..=20.0).text("resize_corner_size")); |
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.
ui.add(Slider::new(resize_corner_size, 0.0..=20.0).text("resize_corner_size")); |
.request_repaint_after(std::time::Duration::from_millis( | ||
(on_duration * 1000.0) as u64, | ||
)); | ||
} | ||
if !is_cursor_visible { | ||
ui.ctx() | ||
.request_repaint_after(std::time::Duration::from_millis( | ||
(off_duration * 1000.0) as u64, | ||
)); |
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.
.request_repaint_after(std::time::Duration::from_millis( | |
(on_duration * 1000.0) as u64, | |
)); | |
} | |
if !is_cursor_visible { | |
ui.ctx() | |
.request_repaint_after(std::time::Duration::from_millis( | |
(off_duration * 1000.0) as u64, | |
)); | |
.request_repaint_after(std::time::Duration::from_secs_f32( | |
on_duration | |
)); | |
} | |
if !is_cursor_visible { | |
ui.ctx() | |
.request_repaint_after(std::time::Duration::from_secs_f32( | |
off_duration | |
)); |
/// Paint text cursor. | ||
pub fn paint_text_cursor( |
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.
fn paint_text_cursor
and fn paint_cursor
have very similar names, but one does blinking, and one does not. We should document that. fn paint_cursor
should probably be made non-pub
too
primary_cursor_rect: Rect, | ||
is_stay_cursor: bool, | ||
) { | ||
let i_time = ui.input(|i| i.time); |
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.
Currently the cursor still blinks while typing, which is quite annoying. If we instead reset a timer each time the user presses a key, it won't blink until text_cursor_on_duration
after the user last stopped typing.
So, I think you were right to put this timer in TextEditState
. We could put a last_edit_time: Option<f64>
there fed by ui.input(|i| i.time)
, and then paint_text_cursor
is fed with time_since_last_edit
which will be used as the basis for the animation
I'll fix the rest of the things in this PR |
Yes, Thank you emilk. |
On by default. Can be set with `style.text_cursor.blink`. * Closes emilk#4121
text cursor blink in TextEdit