-
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
Changes from all commits
b553092
11e31ea
8dd93b4
e56ad08
c6a0fca
61362e5
53991c4
ae48093
f534359
86e0910
f748437
443e68b
5a55d0b
790609c
183500b
8d21de6
6b76c1c
e20c05f
ff68bd2
7ce3353
35704f7
ee4a20b
691308b
bc1e54a
ea247ec
ded8e31
c813943
3c8bc78
8cbe04b
037c4ac
ce54c56
0b3c88e
043ac3f
782fd9d
01675d1
d5fcd5c
55a7c5e
ea89cf6
79eb765
8faf0f5
894fc2f
6ca5eeb
f231579
14ef3f4
f62a193
0ba726e
79dddbf
08daf51
875114f
eb64586
c293e19
956b853
135b88d
9505776
9ee6ca6
ec0f56a
55467b3
a1a3d11
0681300
de4fa6e
0b4ea7f
1600d32
fbabc24
a2eee07
82d3814
24e86d1
d098a8f
27098a1
e50f80d
7dd8226
94f8424
f101c92
837c277
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,3 +73,46 @@ pub fn paint_cursor(painter: &Painter, visuals: &Visuals, cursor_rect: Rect) { | |
); | ||
} | ||
} | ||
|
||
/// Paint text cursor. | ||
pub fn paint_text_cursor( | ||
ui: &mut Ui, | ||
painter: &Painter, | ||
primary_cursor_rect: Rect, | ||
blink_pause: bool, | ||
) { | ||
let i_time = ui.input(|i| i.time); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 So, I think you were right to put this timer in |
||
let blink_mode = ui.visuals().text_cursor_style.blink; | ||
let is_blink_mode = blink_mode && !blink_pause; | ||
|
||
let on_duration = ui.visuals().text_cursor_style.on_duration; | ||
let off_duration = ui.visuals().text_cursor_style.off_duration; | ||
let total_duration = on_duration + off_duration; | ||
|
||
let mut is_cursor_visible = true; | ||
|
||
if is_blink_mode { | ||
// Check if the text cursor is on/off based on the time | ||
is_cursor_visible = (i_time % total_duration) < on_duration; | ||
} | ||
|
||
// Keep the text cursor visible for some time. | ||
if i_time < ui.visuals().text_cursor_style.last_edit_time + 3.0 { | ||
is_cursor_visible = true; | ||
} | ||
|
||
if is_cursor_visible { | ||
paint_cursor(painter, ui.visuals(), primary_cursor_rect); | ||
} | ||
|
||
if blink_mode { | ||
if is_cursor_visible { | ||
ui.ctx() | ||
.request_repaint_after(std::time::Duration::from_secs_f64(on_duration)); | ||
} | ||
if !is_cursor_visible { | ||
ui.ctx() | ||
.request_repaint_after(std::time::Duration::from_secs_f64(off_duration)); | ||
} | ||
} | ||
} |
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
andfn 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